Logfire uses the OpenTelemetry standard. This means that you can configure standard OpenTelemetry SDKs
in many languages to export to the Logfire backend. Depending on your SDK, you may need to set only
these environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-api.pydantic.dev for both traces and metrics, or:
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://logfire-api.pydantic.dev/v1/traces for just traces
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://logfire-api.pydantic.dev/v1/metrics for just metrics
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://logfire-api.pydantic.dev/v1/logs for just logs
OTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token' - see Create Write Tokens
to obtain a write token and replace your-write-token with it.
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf to export in Protobuf format over HTTP (not gRPC).
The Logfire backend supports both Protobuf and JSON, but only over HTTP for now. Some SDKs (such as Python) already use this value as the default so setting this isn't required, but other SDKs use grpc as the default.
exportOTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-api.pydantic.dev
exportOTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token'
npminites6-y# creates package.json with type module
npminstall@opentelemetry/sdk-node
nodemain.js
Update the Cargo.toml and main.rs files with the following contents:
Cargo.toml
[package]name="otel-example"version="0.1.0"edition="2021"[dependencies]opentelemetry={version="*",default-features=false,features=["trace"]}# Note: `reqwest-rustls` feature is necessary else you'll have a cryptic failure to export;# see https://github.com/open-telemetry/opentelemetry-rust/issues/2169opentelemetry-otlp={version="*",default-features=false,features=["trace","http-proto","reqwest-blocking-client","reqwest-rustls"]}
src/main.rs
useopentelemetry::{global::ObjectSafeSpan,trace::{Tracer,TracerProvider},};fnmain()->Result<(),Box<dynstd::error::Error+Send+Sync>>{letotlp_exporter=opentelemetry_otlp::new_exporter().http().with_protocol(opentelemetry_otlp::Protocol::HttpBinary)// If you don't want to export environment variables, you can also configure// programmatically like so://// (You'll need to add `use opentelemetry_otlp::WithExportConfig;` to the top of the// file to access the `.with_endpoint` method.)//// .with_endpoint("https://logfire-api.pydantic.dev/v1/traces")// .with_headers({// let mut headers = std::collections::HashMap::new();// headers.insert(// "Authorization".into(),// "your-write-token".into(),// );// headers// });lettracer_provider=opentelemetry_otlp::new_pipeline().tracing().with_exporter(otlp_exporter).install_simple()?;lettracer=tracer_provider.tracer("my_tracer");tracer.span_builder("Hello World").start(&tracer).end();Ok(())}
exportOTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-api.pydantic.dev
exportOTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token'# Optional, but otherwise you will see the service name set to `unknown_service:otel_example`exportOTEL_RESOURCE_ATTRIBUTES="service.name=my_service"
gomodinitotel_example
gomodtidy
gorun.