hawkapi-otel
OpenTelemetry integration for HawkAPI — a plugin that initialises the OTel SDK on startup and a middleware that creates a server span per request, with full W3C trace-context propagation.
Works out of the box with a local OTLP collector. One-liner configs for Honeycomb, Grafana Cloud, Datadog, and Jaeger are listed below.
Quickstart
pip install hawkapi-otel
from hawkapi import HawkAPI
from hawkapi_otel import OTelPlugin, OTelMiddleware
app = HawkAPI()
app.add_plugin(
OTelPlugin(
service_name="my-app",
service_version="1.0.0",
endpoint="http://localhost:4317",
protocol="grpc",
insecure=True,
)
)
app.add_middleware(OTelMiddleware)
Every request gets a server span with HTTP semantic-convention attributes. Unhandled exceptions are recorded on the current span.
OTelPlugin parameter reference
| Parameter | Type | Default | Description |
|---|---|---|---|
service_name |
str |
"unknown_service" |
service.name resource attribute. |
service_version |
str | None |
None |
service.version resource attribute. |
endpoint |
str |
"http://localhost:4317" |
OTLP collector endpoint. |
protocol |
str |
"grpc" |
"grpc" or "http/protobuf". |
insecure |
bool |
True |
Disable TLS (useful for local collectors). |
headers |
dict[str, str] | None |
None |
Extra headers — API keys for Honeycomb, Grafana Cloud, etc. |
resource_attributes |
dict[str, str] | None |
None |
Arbitrary extra resource attributes. |
traces_sampler |
str |
"parentbased_always_on" |
Sampler name. See sampler reference below. |
traces_sampler_arg |
float | None |
None |
Ratio for traceidratio / parentbased_traceidratio. |
enable_metrics |
bool |
True |
Build a MeterProvider with OTLP metric export. |
enable_logs |
bool |
False |
Attach LoggingHandler to root logger + OTLP log export. |
console_exporter |
bool |
False |
Also add a ConsoleSpanExporter (debug). |
record_exceptions |
bool |
True |
Call span.record_exception() in on_exception. |
Sampler reference
traces_sampler value |
Behaviour |
|---|---|
"always_on" |
Sample every trace. |
"always_off" |
Sample nothing. |
"traceidratio" |
Sample traces_sampler_arg fraction (e.g. 0.1 = 10%). |
"parentbased_always_on" |
Respect parent; default to always-on. (default) |
"parentbased_always_off" |
Respect parent; default to always-off. |
"parentbased_traceidratio" |
Respect parent; default to ratio sampling. |
Vendor recipes
Honeycomb
OTelPlugin(
service_name="my-app",
endpoint="https://api.honeycomb.io",
protocol="http/protobuf",
insecure=False,
headers={"x-honeycomb-team": "YOUR_API_KEY"},
)
Grafana Cloud
OTelPlugin(
service_name="my-app",
endpoint="https://otlp-gateway-prod-eu-west-0.grafana.net/otlp",
protocol="http/protobuf",
insecure=False,
headers={"authorization": "Basic BASE64_ENCODED_INSTANCE_ID:TOKEN"},
)
Datadog (OTLP intake)
OTelPlugin(
service_name="my-app",
endpoint="https://api.datadoghq.com",
protocol="http/protobuf",
insecure=False,
headers={"dd-api-key": "YOUR_DD_API_KEY"},
)
Jaeger (local)
OTelPlugin(
service_name="my-app",
endpoint="http://localhost:4317",
protocol="grpc",
insecure=True,
)
Development
# Clone and install in editable mode with dev extras
git clone https://github.com/Hawk-API/hawkapi-otel.git
cd hawkapi-otel
uv sync --extra dev
# Run tests
uv run pytest tests/ -q
# Lint
uv run ruff check .
uv run ruff format .
# Type-check
uv run pyright src/
License
MIT — Copyright (c) 2026 HawkAPI Contributors.
Metadata
Release files for hawkapi-otel 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| hawkapi_otel-0.2.1.tar.gz | 40.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hawkapi_otel-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.2 kB
Release files / hawkapi_otel-0.2.1.tar.gz
| Download URL | hawkapi_otel-0.2.1.tar.gz |
|---|---|
| Size | 40.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0acf09448b7ecadb4768a0ddde71e1032a865c8fbb709f627af1e054dd20ca78
|
|
BLAKE2b-256 checksum How to use checksums |
edeaf5996c1e934186939e05fbd85380a61d24d2224e8ccbaae7659b7f81429e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 10, 2026.
Transparency logRelease files / hawkapi_otel-0.2.1-py3-none-any.whl
| Download URL | hawkapi_otel-0.2.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2af310610ad130edf0032eb2ae0565b49c2e3443e9b9e714569c19d1a56ceca
|
|
BLAKE2b-256 checksum How to use checksums |
3014f6d9b6ec6d7204ee12b1236e04547a95eae4ea70c2200b77c9985b100931
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 10, 2026.
Transparency logSecurity for hawkapi-otel 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for hawkapi_otel-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.