PHP - Connecting logs with traces
TomKeur opened this issue · comments
Documentation Page
https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/php/
Issue Description
It's not really clear, but when you're using the Monolog v3 version with the Json formatter you can just use the same code with: For monolog v3:
but in the Logging configuration (inside Datadog) you can add extra.dd.trace_id
to Trace ID Option.
My logs and traces are now connected, with the same code :).
Also, the code below: "If your application uses json logs format instead of appending trace_id and span_id to the log message you can add first-level key “dd” containing these ids:"
Is not working Monolog v3, so maybe that should be placed in another place on the page, because I think it creates confusion this way, at least it did for me :).
I've tried contributing this myself, but somehow I was not able to get the local build system (with Docker running).
Hopefully you will benefit from my contribution
We encounter the same issue when using Monolog V3. In Monolog V2, we can add a first-level key "dd" since the LogRecord is an array. However, in Monolog V3, the LogRecord is an object, as mentioned in the changelog, and we are unable to set the "dd" key as the first-level key.
If you can support connecting logs with traces even when we put the "dd" key into the extra key, that would be great.
@yankewei I've fixed it by adding this extra.dd.trace_id
to the "Preprocessing for JSON logs", see screenshot.
I'm ingesting my logs as JSON.
Hi @maycmlee, this seems to describe the way to get it connected :).
Just to let you know, I see saw a new version of the PHP agent adds Auto Log Correlation (0.90.0): DataDog/dd-trace-php#2118 but I think it's good it's still documented somewhere.
Also, keep in mind that not every is able to run the latest version of the Datadog PHP extension, for example I'm not able to run it myself (running Dockerized, but was unable to install it during a new Rust dependency rust
).