The bundle provides two complementary log features: log-trace correlation, which injects the activeDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tracewayapp/opentelemetry-symfony-bundle/llms.txt
Use this file to discover all available pages before exploring further.
trace_id and span_id into every Monolog record so you can jump from a log line to its matching trace, and OTel log export, which forwards Monolog records to any OpenTelemetry-compatible log backend via the OTel Logs API. Both features work independently and can be enabled or disabled without affecting the other.
Log-Trace Correlation
Log-trace correlation is enabled by default. TheTraceContextProcessor reads the active OTel span from the current context and appends trace_id and span_id to the extra array of every Monolog record. If there is no active span (e.g. a log emitted outside a request), the record is passed through unchanged.
| Field | Example value |
|---|---|
extra.trace_id | 4bf92f3577b34da6a3ce929d0e0e4736 |
extra.span_id | 00f067aa0ba902b7 |
Correlation is injected by
TraceContextProcessor, a standard Monolog ProcessorInterface. It is wired automatically when logs.correlation.enabled: true. If you use Monolog’s IntrospectionProcessor, add it before the trace context processor so the call site is resolved first.OTel Log Export
OTel log export is opt-in and requiressymfony/monolog-bundle. When enabled, the OtelLogHandler is registered as a Monolog handler and exports records to any backend configured via OTEL_LOGS_EXPORTER.
Enabling Export
Configuration Options
| Key | Default | Description |
|---|---|---|
level | debug | Minimum Monolog level forwarded to OTel. Records below this level are dropped before reaching the handler. |
capture_code_attributes | false | When true and Monolog’s IntrospectionProcessor is not active, the handler walks debug_backtrace() to find the application call site and populate code.* attributes. |
unprefixed_attributes | true | See below. |
unprefixed_attributes (Default: true)
When unprefixed_attributes: true, log context and extra fields are emitted as flat OTel attributes — for example, a context key user_id becomes the attribute user_id. This matches the convention used by the official OpenTelemetry SDKs for Java, Python, .NET, and JavaScript, making cross-language log correlation dashboards easier to build.
When unprefixed_attributes: false, context fields are prefixed as monolog.context.* and extra fields as monolog.extra.*. Use this only if you need to distinguish Monolog-originated attributes from other OTel attributes in a shared schema.
Instrumentation Scope per Channel
Each Monolog channel becomes its own OTel instrumentation scope. A log from thesecurity channel is exported under the scope name security, and a log from app appears under app. This matches the behavior of the official opentelemetry-logger-monolog contrib handler and allows backends to filter or route logs by channel without introducing a separate attribute.
The Monolog channel name is the instrumentation scope name, not a log attribute. It will not appear as
monolog.channel in the exported record — look for it in the scope metadata of your backend’s log viewer.code.* Attributes
OtelLogHandler emits the following OTel semantic-convention code attributes (Stable):
| Attribute | Source |
|---|---|
code.file.path | Absolute path to the source file containing the log call |
code.line.number | Line number within that file |
code.function.name | Fully qualified function name, e.g. App\Service\OrderService::process |
Source 1 — IntrospectionProcessor (Free)
If Monolog’sIntrospectionProcessor is registered, it writes file, line, class, and function into $record->extra. The handler promotes these to code.* attributes automatically and drops the raw keys from the extra namespace to avoid duplication — no additional configuration required.
Source 2 — capture_code_attributes: true (Opt-in)
When capture_code_attributes: true and the IntrospectionProcessor extras are absent, the handler calls debug_backtrace(), walking past Monolog internals, Symfony Bridge frames, and bundle handler frames to find the first application frame. This adds a small overhead per log record and is disabled by default.
Re-entrance Guard
OtelLogHandler includes a re-entrance guard ($emitting flag). If the OTel export path itself emits a Monolog record (e.g. the OTLP HTTP exporter logs a failed send), the guard prevents infinite recursion. The nested log record is silently dropped rather than causing a loop.
Combining Correlation and Export
Both features can be active simultaneously. When they are, the OTel SDK setstrace_id and span_id natively on the exported LogRecord from the active span context. The handler skips extra.trace_id and extra.span_id values that TraceContextProcessor wrote — they are duplicates at that point — so your exported records will not carry redundant trace fields.
For the full list of
logs.* configuration keys and the OTEL_LOGS_EXPORTER environment variable reference, see the Configuration Reference.