@observe-decorated function and can export them to any OTLP-compatible backend — Grafana Tempo, Jaeger, Dash0, Datadog, Honeycomb, and others.
How It Works
In Cognee core, the@observe decorator maps only to OpenTelemetry. When tracing is enabled, it wraps each decorated function in an OTEL span; when tracing is disabled it is a no-op that passes the call straight through. There is no built-in Sentry or Langfuse backend to configure.
| Feature | OTEL |
|---|---|
| Enabled by | COGNEE_TRACING_ENABLED=true |
| Data destination | Any OTLP backend (or in-memory) |
| Span type | OTEL span |
Installation
OTEL support requires OpenTelemetry dependencies. Install them with thetracing extra:
opentelemetry-sdk plus the OTLP gRPC and HTTP exporters. No additional packages are needed for the in-memory buffer.
Quick Start
1. Enable tracing via environment variable
2. Export to an OTLP backend (optional)
Point cognee at an OTLP-compatible collector:Grafana Tempo / Grafana Cloud
Grafana Tempo / Grafana Cloud
Jaeger (local)
Jaeger (local)
4317) exposed.Dash0
Dash0
3. Using an auto-instrumentation agent
If you launch your application withopentelemetry-instrument or an APM agent (Datadog, Dash0, Elastic), it configures its own TracerProvider before your code runs. Cognee detects this and attaches its in-memory exporter to the existing provider instead of creating a new one — so cognee spans appear inside your existing trace alongside other spans from your application.
get_last_trace() and related helpers still work.
Programmatic API
You can also control tracing from Python:CogneeTrace API
| Method | Returns | Description |
|---|---|---|
spans() | list[dict] | Flat list of span dicts sorted by start time |
summary() | dict | Root operation, total duration, per-span breakdown, errors |
tree() | dict | Hierarchical span tree as nested dicts |
name, trace_id, span_id, parent_span_id, start_time_ns, end_time_ns, duration_ms, status, attributes.
Span Attributes
Cognee sets the following semantic attributes on spans:| Attribute | Description |
|---|---|
cognee.span.category | Value of as_type= passed to @observe |
cognee.llm.model | LLM model name |
cognee.llm.provider | LLM provider |
cognee.pipeline.stage | Pipeline stage that issued the LLM call — extraction, summarization, or query; present on LLM spans made within a stage boundary regardless of whether per-stage routing overrides are set |
cognee.search.type | Search type enum value used by retrieval |
cognee.search.query | Search query text used by retrieval |
cognee.pipeline.task_name | Pipeline task name |
cognee.vector.collection | Vector collection name |
cognee.db.system | Database backend identifier |
Environment Variables Reference
| Variable | Default | Description |
|---|---|---|
COGNEE_TRACING_ENABLED | false | Set to true to enable OTEL tracing |
OTEL_SERVICE_NAME | cognee | Service name attached to all spans |
OTEL_EXPORTER_OTLP_ENDPOINT | (none) | OTLP collector endpoint. Cognee currently prefers the OTLP gRPC exporter when both gRPC and HTTP exporters are installed. |
OTEL_EXPORTER_OTLP_HEADERS | (none) | Auth headers (e.g. Authorization=Bearer <token>) |
OTEL_RESOURCE_ATTRIBUTES | (none) | Comma-separated extra resource attributes attached to the tracer provider resource (e.g. service.namespace=my-team,service.version=1.0,deployment.environment.name=prod). Read by the OpenTelemetry SDK itself. |
Cognee reads
OTEL_EXPORTER_OTLP_ENDPOINT directly and passes it to the OTLP exporter. Other standard OTEL_EXPORTER_OTLP_* settings such as headers are honored by the underlying exporter library. OTEL_RESOURCE_ATTRIBUTES is read by the OpenTelemetry SDK and merged into the provider resource. When Cognee creates its own TracerProvider, that includes service.name, service.version, and deployment.environment; in auto-instrumented setups, the external provider’s resource configuration applies instead.Cognee currently tries the OTLP gRPC exporter first and only falls back to the OTLP HTTP exporter if the gRPC exporter package is unavailable. Because the shipped extras install both exporters, the practical default is gRPC. Use a gRPC-compatible OTLP endpoint unless you intentionally run with only the HTTP exporter installed.