question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatically inject correlation identifiers into log messages

See original GitHub issue

I am trying to enable automatic correlation identifier injection using the package version 2.10.0. However, the logged properties (dd_trace_id, dd_version, dd_service, dd_env) are not being logged anymore.

I am using the SerilogExample as project to do the tests and I didn`t change anything, only the version of DataDog.Trace package. And the results are:

Datadog.Trace  Version 1.31.2
-------------------------------
{"Timestamp":"2022-06-20T23:47:18.8214709-03:00","Level":"Information","MessageTemplate":"Message before a trace.","Properties":{"order-number":1024,"serviceName":"SerilogExample","applicationVersion":"1.0.0.0"}}
{"Timestamp":"2022-06-20T23:47:19.1242922-03:00","Level":"Information","MessageTemplate":"Message during a trace.","Properties":{"dd_service":"SerilogExample","dd_version":"1.0.0","dd_env":"dev","dd_trace_id":"8448889662018737848","dd_span_id":"6686629885022921939","order-number":1024,"serviceName":"SerilogExample","applicationVersion":"1.0.0.0"}}
{"Timestamp":"2022-06-20T23:47:19.1355577-03:00","Level":"Information","MessageTemplate":"Message after a trace.","Properties":{"order-number":1024,"serviceName":"SerilogExample","applicationVersion":"1.0.0.0"}}


Datadog.Trace  Version 2.10.0
-------------------------------
{"Timestamp":"2022-06-20T23:48:18.8324620-03:00","Level":"Information","MessageTemplate":"Message before a trace.","Properties":{"order-number":1024,"serviceName":"SerilogExample","applicationVersion":"1.0.0.0"}}
{"Timestamp":"2022-06-20T23:48:19.1069486-03:00","Level":"Information","MessageTemplate":"Message during a trace.","Properties":{"order-number":1024,"serviceName":"SerilogExample","applicationVersion":"1.0.0.0"}}
{"Timestamp":"2022-06-20T23:48:19.1106834-03:00","Level":"Information","MessageTemplate":"Message after a trace.","Properties":{"order-number":1024,"serviceName":"SerilogExample","applicationVersion":"1.0.0.0"}}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
pierotiboucommented, Jun 22, 2022

First, you seem to have properly handled context propagation in your code.

Then, regarding the tracer setup (the document linked is mainly linked to the agent), you could follow this inapp docs filtered on your setup where you setup the tracer in the container itself, setting the right environment variables:

Basically, it could look like something like this if you run on linux:

# Please select the corresponding download for your Linux containers https://github.com/DataDog/dd-trace-dotnet/releases/latest

# Download and install the Tracer
RUN mkdir -p /opt/datadog \
    && mkdir -p /var/log/datadog \
    && TRACER_VERSION=$(curl -s https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c2-) \
    && curl -LO https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb \
    && dpkg -i ./datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb \
    && rm ./datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb

# Enable the tracer
ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
ENV DD_DOTNET_TRACER_HOME=/opt/datadog
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json

Then you would need to run docker by setting -e DD_LOGS_INJECTION=true as well.

Here are some more examples if need be: https://www.datadoghq.com/blog/asp-dotnet-core-monitoring/ And our public documentation for complete details: https://docs.datadoghq.com/tracing/setup_overview/setup/dotnet-core?tab=windows

1reaction
parraclaudiocommented, Jul 6, 2022

Thank you so much for your time @pierotibou

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correlation Ids — Log4net Enrichment | by Jon Glass | Medium
Because the correlation id is injected manually into the messages, including correlation ids with all our page requests in the website would be...
Read more >
How to correlate messages across services
Correlation ID can be set on log messages logged through log4net in multiple ways. You can include it directly on the LoggingEvent :...
Read more >
A consistent approach to track correlation IDs through ...
The correlation ID can then be used to quickly find all the relevant log messages for this request (very easy to do in...
Read more >
Adding Correlation IDs to Easily Track Down Errors
In this post, we'll look at how we can use Spring Cloud Sleuth to add trace IDs to our application to track down...
Read more >
Correlation IDs - Code With Engineering Playbook
Log correlation is the ability to track disparate events through different parts of the application. Having a Correlation ID provides more ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found