Loading...
Loading...
Ossido has built-in OpenTelemetry support. The server
exports traces and logs over OTLP (http/protobuf) to any collector - Jaeger,
Grafana, Honeycomb, otel-tui, and so on. There's no Ossido config for it: it's
switched on at runtime with the standard OTEL_* environment variables. With none
set, nothing is exported and nothing changes.
Point the server at an OTLP-HTTP endpoint:
The same variable works for a production server binary - set it wherever you set the rest of the server's environment (see Building & deploying).
For a quick local collector, otel-tui shows traces and logs right in the terminal:
With an endpoint set, every request is traced without any code changes:
GET /api/pokemons/{name}), with the HTTP semantic conventions. An incoming W3C
traceparent header is continued, so Ossido joins traces started upstream.#[api] routes, and
#[action]s.ssr.queue_wait (time spent
waiting for a render pool
worker), ssr.render_job, ssr.v8_compile, and ssr.render.logger call (and,
in development, forwarded browser logs) is exported and correlated with the
request's trace. Console output is unchanged: logs still print exactly as
before.Ossido re-exports the tracing crate as
ossido::tracing. Spans you create there become children of the request's
server and handler spans.
The span macros work with no extra dependency:
The #[tracing::instrument] attribute expands to ::tracing paths, so it needs a
direct tracing dependency in your Cargo.toml:
[dependencies]
tracing = "0.1"
When OpenTelemetry isn't enabled, these spans cost next to nothing.
Configuration comes entirely from the standard OpenTelemetry environment variables:
| Variable | Purpose |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | The collector endpoint. Setting it turns export on. |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT / OTEL_EXPORTER_OTLP_LOGS_ENDPOINT | Per-signal endpoints. |
OTEL_EXPORTER_OTLP_HEADERS | Extra headers, for example an API key for a hosted backend. |
OTEL_EXPORTER_OTLP_TIMEOUT | Export timeout. |
OTEL_SERVICE_NAME | The service name. Defaults to ossido. |
OTEL_RESOURCE_ATTRIBUTES | Extra resource attributes, such as deployment.environment=prod. |
OTEL_TRACES_SAMPLER / OTEL_TRACES_SAMPLER_ARG | Trace sampling. |
OTEL_BSP_* / OTEL_BLRP_* | Batch span and log processor settings. |
OTEL_SDK_DISABLED | Set to true to turn export off even when an endpoint is set. |
Only the http/protobuf transport is supported. Any other
OTEL_EXPORTER_OTLP_PROTOCOL value is ignored with a warning.
If your app defines an
Environment struct, its .env files are
loaded before telemetry starts, so the OTEL_* variables can live there too (the
kitchen-sink example does this). Telemetry reads them once at startup, so
changing one needs a server restart - the
.env hot reload
doesn't apply to them.
telemetry featureOpenTelemetry is compiled in behind the ossido crate's telemetry Cargo feature,
which is on by default. If you never export telemetry and want to drop the
dependency weight (and some compile time), turn default features off:
[dependencies]
ossido = { version = "0.1.9", default-features = false }
Without the feature, the OTEL_* variables are ignored, and ossido::tracing is
still available for your own instrumentation.
The with-opentelemetry
example shows all of the above, and the kitchen-sink example uses it alongside a
real database. Start a project from either:
Next: Building & deploying · Back to Tooling & developer experience