Skip to main content

Zero-cost telemetry for Python. No-op when disabled, rich context when enabled.

Project description

Nullscope

PyPI License

Zero-cost telemetry for Python. No-op when disabled, rich context when enabled.

Why Nullscope?

Most telemetry libraries have runtime cost even when you don't need them. Nullscope is different:

  • Disabled: Returns a singleton no-op object. No allocations, no timing calls, no overhead.
  • Enabled: Full-featured timing and metrics with automatic scope hierarchy.

This makes Nullscope ideal for libraries (users can enable telemetry if they want) and applications where you want zero production overhead but rich debugging capability.

from nullscope import TelemetryContext

# When NULLSCOPE_ENABLED != "1", this is literally just returning a cached object
telemetry = TelemetryContext()

with telemetry("database.query"):  # No-op when disabled
    results = db.execute(query)

What Nullscope Is Not

  • A distributed tracing system. No trace propagation, no span IDs, no context injection for cross-service correlation. If you need that, use OpenTelemetry directly. Nullscope can feed OTel, but it doesn't replace it.

  • A metrics aggregation layer. Nullscope reports raw events to reporters. It doesn't compute percentiles, histograms, or roll up data. That's the reporter's job (or the backend's).

  • Auto-instrumentation. Nullscope won't patch your HTTP client or database driver. You instrument what you want, explicitly.

  • A logging framework. Scopes are for timing and metrics, not structured log events. (Though a reporter could emit logs.)

Installation

pip install nullscope

With OpenTelemetry support:

pip install nullscope[otel]

Quick Start

import os
os.environ["NULLSCOPE_ENABLED"] = "1"  # Enable telemetry

from nullscope import TelemetryContext, SimpleReporter

# Create a reporter to see output
reporter = SimpleReporter()
telemetry = TelemetryContext(reporter)

# Time operations with automatic hierarchy
with telemetry("request"):
    with telemetry("auth"):
        validate_token()

    with telemetry("handler"):
        process_data()

# See what was collected
reporter.print_report()

Output:

=== Nullscope Report ===

--- Timings ---
request:
  auth                           | Calls: 1    | Avg: 0.0012s | Total: 0.0012s
  handler                        | Calls: 1    | Avg: 0.0234s | Total: 0.0234s

Configuration

Environment Variable Description
NULLSCOPE_ENABLED=1 Enable telemetry (default: disabled)

Note: environment flags are read at import time. In tests, reload nullscope after changing env vars.

API

TelemetryContext

from nullscope import TelemetryContext

telemetry = TelemetryContext()  # Uses default SimpleReporter when enabled
telemetry = TelemetryContext(my_reporter)  # Custom reporter
telemetry = TelemetryContext(reporter1, reporter2)  # Multiple reporters

Scopes (Timing)

with telemetry("operation"):
    do_work()

# With metadata
with telemetry("http.request", method="GET", path="/api/users"):
    handle_request()

Metrics

telemetry.count("cache.hit")  # Increment counter
telemetry.count("items.processed", 5)  # Increment by N
telemetry.gauge("queue.depth", len(queue))  # Point-in-time value
telemetry.metric("custom", value, metric_type="counter")  # Generic

Check Status

if telemetry.is_enabled:
    # Do expensive debug logging
    pass

OpenTelemetry Adapter

Export to OpenTelemetry backends:

from nullscope import TelemetryContext
from nullscope.adapters.opentelemetry import OTelReporter

# Configure OTel SDK first (providers, exporters, etc.)
# Then use Nullscope with OTel reporter
telemetry = TelemetryContext(OTelReporter(service_name="my-service"))

The adapter emits:

  • Timings → Histogram (seconds) + synthetic Span when wall-clock bounds are present
  • Counters → Counter
  • Gauges → Histogram (sampled values, since Python OTel sync gauge support is limited)

Documentation

  • Design - Architecture and implementation details
  • Examples - Real-world usage patterns
  • Comparison - When to use Nullscope vs alternatives
  • Roadmap - Version milestones and planned features

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nullscope-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nullscope-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file nullscope-0.1.0.tar.gz.

File metadata

  • Download URL: nullscope-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nullscope-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43c5a565f2cf5423ae937ef42830dda1700bf47bb03d8c50c8db442dc095b29a
MD5 e6037c07a9c9e5c6e3bedfa010225cba
BLAKE2b-256 f12449d2f820448ac22ef48b3a50a064bce1cbec7dbdf8cbd641ef92aefa604b

See more details on using hashes here.

File details

Details for the file nullscope-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nullscope-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nullscope-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 516ff698f0603259128de2da12cb155c538c63c4f6d377be852b1d6836b1019f
MD5 ce82c168198da80aeb9e368dd50b3676
BLAKE2b-256 6c6e0e8e60d8b46f7a7796b8658cdb7f2eb4fffb4a485bd267c30d45dbc9e7dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page