Skip to main content

Zero-code OpenTelemetry instrumentation for the Sanic web framework

Project description

opentelemetry-instrumentation-sanic

Zero-code OpenTelemetry instrumentation for the Sanic web framework (including ASGI deployments).

Every inbound HTTP request handled by Sanic is turned into a server span with HTTP semantic-convention attributes, W3C context propagation, and correct error status mapping — with no changes to your application code.

Install

pip install opentelemetry-instrumentation-sanic

Zero-code usage

opentelemetry-instrument --traces_exporter console python my_sanic_app.py

The opentelemetry-instrument launcher discovers this package through its opentelemetry_instrumentor entry point and activates it before your app is created.

Programmatic usage

Call instrument() before constructing your Sanic app:

from opentelemetry.instrumentation.sanic import SanicInstrumentor

SanicInstrumentor().instrument(excluded_urls="/health,/metrics")

from sanic import Sanic
app = Sanic("my-app")

See examples/manual_app.py for a runnable example.

Configuration

SanicInstrumentor().instrument() accepts:

Keyword Type Description
tracer_provider TracerProvider Provider to use; defaults to the global provider.
excluded_urls str / iterable[str] Regex patterns whose matching URLs are not traced.

Development

pip install -e ".[test]"
pytest

Design notes

The instrumentor swaps sanic.Sanic for a subclass that registers request/response middleware on construction. Middleware signatures are stable across Sanic releases, so the integration stays decoupled from Sanic internals. Responsibilities are split across small modules: URL filtering (_url_filter), attribute extraction (_attributes), span lifecycle (_middleware), and activation (__init__).

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

opentelemetry_instrumentation_sanic-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_sanic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf14e9be2b38aaacdb7361f25d5ecb0dadb747e4e64fe52fa1d7f13b6768deff
MD5 252c3b06b911b54ed80f6f46a15e0e51
BLAKE2b-256 bcf7303ba6e475f9748b6a0b0c170a2321c1225e5f70cbfb71d24ff8fc4b8afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_sanic-0.1.0.tar.gz:

Publisher: publish.yml on daipham3213/opentelemetry-instrumentation-sanic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_sanic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b17f5ff6ba673cb782df1efa0ca73b07903c8c7a1491cd2a6088ac1e6a25f152
MD5 c926b0a28d87b994b179fa39b9f99b76
BLAKE2b-256 76a5890c5e11bd7b81513149b40d6970157cd41e083b8cd3cb06788d4b151593

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_sanic-0.1.0-py3-none-any.whl:

Publisher: publish.yml on daipham3213/opentelemetry-instrumentation-sanic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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