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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentelemetry_instrumentation_sanic-0.1.0.tar.gz.
File metadata
- Download URL: opentelemetry_instrumentation_sanic-0.1.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf14e9be2b38aaacdb7361f25d5ecb0dadb747e4e64fe52fa1d7f13b6768deff
|
|
| MD5 |
252c3b06b911b54ed80f6f46a15e0e51
|
|
| BLAKE2b-256 |
bcf7303ba6e475f9748b6a0b0c170a2321c1225e5f70cbfb71d24ff8fc4b8afc
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_sanic-0.1.0.tar.gz:
Publisher:
publish.yml on daipham3213/opentelemetry-instrumentation-sanic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_sanic-0.1.0.tar.gz -
Subject digest:
cf14e9be2b38aaacdb7361f25d5ecb0dadb747e4e64fe52fa1d7f13b6768deff - Sigstore transparency entry: 2034001928
- Sigstore integration time:
-
Permalink:
daipham3213/opentelemetry-instrumentation-sanic@57aed21ee0bc351ce0fb581889fc1eccb094c92d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/daipham3213
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57aed21ee0bc351ce0fb581889fc1eccb094c92d -
Trigger Event:
push
-
Statement type:
File details
Details for the file opentelemetry_instrumentation_sanic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opentelemetry_instrumentation_sanic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b17f5ff6ba673cb782df1efa0ca73b07903c8c7a1491cd2a6088ac1e6a25f152
|
|
| MD5 |
c926b0a28d87b994b179fa39b9f99b76
|
|
| BLAKE2b-256 |
76a5890c5e11bd7b81513149b40d6970157cd41e083b8cd3cb06788d4b151593
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_sanic-0.1.0-py3-none-any.whl -
Subject digest:
b17f5ff6ba673cb782df1efa0ca73b07903c8c7a1491cd2a6088ac1e6a25f152 - Sigstore transparency entry: 2034002296
- Sigstore integration time:
-
Permalink:
daipham3213/opentelemetry-instrumentation-sanic@57aed21ee0bc351ce0fb581889fc1eccb094c92d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/daipham3213
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57aed21ee0bc351ce0fb581889fc1eccb094c92d -
Trigger Event:
push
-
Statement type: