Otel
OpenTelemetry for Python services in this project — SDK setup, auto-instrumentation, custom spans/metrics/logs, semantic conventions, and the Collector pipeline that consumes the data. Use when instrumenting a Python service with traces/metrics/logs, picking attribute names, debugging missing telemetry, or deciding what belongs in the SDK vs the Collector.From its SKILL.md
npx -y skills add AI-Riksarkivet/ra-skills --skill otelAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.6 KB, as published. Nobody here has run it
OpenTelemetry (Python-first)
The single reference for OTel in this project. Replaces the four upstream dash0 skills. Vendor-neutral — no backend-specific guidance.
Layered above python-infrastructure → references/observability.md, which pins the project-specific conventions (resource attributes, log severity, golden signals, NATS context propagation). Read that first if you're applying this in code; come here for the deep reference.
Scope routing
| If you need to… | Read |
|---|---|
| Install the Python SDK, auto-instrument, set env vars, custom spans, structured logs, graceful shutdown, troubleshooting | references/python-sdk.md |
| Name spans, pick span kind, set status, choose metric instrument types, structure log records, manage cardinality | references/signals.md |
| Look up the right attribute name, decide resource vs span placement, find a semconv namespace | references/attributes.md |
| Run a Collector pipeline, order processors, send to a backend over OTLP | references/collector.md |
Key principles
- Auto-instrument first, manual for business operations.
opentelemetry-bootstrap -a installcovers FastAPI, httpx, asyncpg, redis, requests, SQLAlchemy and most libs we use. Add manual spans only for domain logic the framework can't see (process_order,validate_invoice). - Three signals, one SDK. Traces, metrics, and logs all go out via OTLP. Don't add
structlogor a Prometheus client — the OTel Python SDK's stdlib-logginghandler and metrics API cover both. - Sample in the Collector, not the SDK. Use the default
AlwaysOnsampler in the SDK. Tail/head sampling lives in the Collector where the outcome of a request is known. - Cardinality is the cost driver. Metric attribute values must be bounded.
http.routenoturl.path;user.tiernotuser.id. Per-request identifiers go on spans and logs, not metrics. - Semconv names first, custom names last. Search the Attribute Registry before inventing. Custom attributes use a reverse-DNS namespace (
com.rask.order.priority). - Set status
ERRORonly on final failure. Retried-then-succeeded operations stayUNSET. EveryERRORcarries a status message with the error class. - Resource attributes identify the producer.
service.name,service.version,deployment.environment.name. Set via env (OTEL_SERVICE_NAME,OTEL_RESOURCE_ATTRIBUTES), never per-span.
Quick start (Python)
uv add opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
export OTEL_SERVICE_NAME="rask-api"
export OTEL_RESOURCE_ATTRIBUTES="service.version=1.2.3,deployment.environment.name=production"
export OTEL_EXPORTER_OTLP_ENDPOINT="http://otel-collector:4317"
export OTEL_METRICS_EXPORTER="otlp" # traces & logs default to otlp; metrics doesn't
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
opentelemetry-instrument python -m rask.api
For development without a Collector, swap exporters to the console:
export OTEL_TRACES_EXPORTER=console OTEL_METRICS_EXPORTER=console OTEL_LOGS_EXPORTER=console
Full details in references/python-sdk.md.
Top gotchas
- Sync code inside an async handler blocks the loop. Auto-instrumentation can't fix a
requests.get(...)inside an async route — usehttpx.AsyncClient. See siblingpython-infrastructure. - Trace context is lost across queues. Publishing to NATS JetStream drops the span unless you
propagate.inject(carrier)into message headers andpropagate.extracton the consumer. Seepython-infrastructure/references/observability.md. opentelemetry-instrumentis required. Just installing the packages does nothing — the SDK isn't activated until the launcher runs. Missing instrumentations? Re-runopentelemetry-bootstrap -a installin the same venv.- No metrics by default.
OTEL_METRICS_EXPORTERdefaults tononein Python (unlike traces/logs). Set it explicitly tootlp. - Span events for exceptions are deprecated. Don't call
span.record_exception(e)for new code. Emit a log record withexception.type/exception.message/exception.stacktraceinside the active span context — it'll carrytrace_id/span_idautomatically. opentelemetry-instrumentregisters anatexitshutdown hook automatically. Noatexit.register(provider.shutdown)needed unless you set up the SDK programmatically.
References
- OpenTelemetry Python docs
- Attribute Registry
- Semantic Conventions spec
- OTel Collector docs
- Instrumentation Score spec — vendor-neutral quality score