Sinatra - missing trace_id when trying to correlate logs with traces #3652
Labels
bug
Involves a bug
community
Was opened by a community member
integrations
Involves tracing integrations
logging
Log Management product
Current behaviour
I have a sinatra app. By default, Sinatra app is a rack application and rack comes with its Rack::CommonLogger. when I configure logging with Rack::CommonLogger, I get these logs in DD:
I enabled tracing for my app. I want to correlate these logs with traces, as currently they're not correlated at all. As far as I understand, these logs must have span_id and trace_id printed out. At least that's how it works for my other applications, in Rails etc. To do so, I've created my own logger that appends
Datadog::Tracing.log_correlation
to every message Rack::CommonLogger wanted to log. (classMyLogger
inconfig.ru
file)Problem:
When trying to print
Datadog::Tracing.log_correlation
along with the rest of the log, thetrace_id
andspan_id
are always 0(in other words, not set). They are not set even if I pass X_DATADOG_TRACE_ID in headers. What I noticed is that if I turn off tracing, then trace_id is correctly inherited from the headers. That looks like a bug.I can't turn off tracing, because then the app is not traced, so I'm losing a lot of info about my sidekiqs, redises, etc. But with tracing enabled, I can't correlate logs, as trace_id is always 0.
Reproduction steps along with DD setup codes are below.
Expected behaviour
My expectation would be that the trace_id is set and I can correlate logs with traces. If I am doing something wrong here, I'd happy to hear suggestions how to correlate logs with traces correctly.
Steps to reproduce
config.ru
file - basic minimal setupreproduce_script.sh
chmod +x reproduce_script.sh
./reproduce_script.sh
Here is the outcome of the script:
As you can see,
with tracing.enabled = true
dd.trace_ids are zeros, even if I try to set their values by passing headers in the curl command(
curl -X GET 127.0.0.1:9292/ --header "X_DATADOG_TRACE_ID: 999" --header "X_DATADOG_PARENT_ID: 998"
)Environment
Datadog.configure ...
):This error is kinda connected to #2666
The text was updated successfully, but these errors were encountered: