Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject TraceID in to log messages #196

Closed
bruceharrison1984 opened this issue Apr 27, 2021 · 6 comments
Closed

Inject TraceID in to log messages #196

bruceharrison1984 opened this issue Apr 27, 2021 · 6 comments
Assignees
Labels

Comments

@bruceharrison1984
Copy link

bruceharrison1984 commented Apr 27, 2021

The Java SDK exposes AWS-XRAY-TRACE-ID in the MDC to allow for easily adding TraceID to log messages, which allows ServiceLens to marry up X-Ray segments and log messages. It would be great to have this same behavior within the C# library, or at least an easy to access value for adding traceId to log messages in a similar fashion.

From the Java X-Ray SDK:
To expose the current fully qualified trace ID to your log statements, you can inject the ID into the mapped diagnostic context (MDC). Using the SegmentListener interface, methods are called from the X-Ray recorder during segment lifecycle events. When a segment or subsegment begins, the qualified trace ID is injected into the MDC with the key AWS-XRAY-TRACE-ID. When that segment ends, the key is removed from the MDC. This exposes the trace ID to the logging library in use. When a subsegment ends, its parent ID is injected into the MDC.

https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-configuration.html#xray-sdk-java-configuration-logging

@srprash srprash added the feature label May 4, 2021
@srprash srprash self-assigned this May 4, 2021
@srprash
Copy link
Collaborator

srprash commented May 7, 2021

Hi @bruceharrison1984
Thanks for opening this feature request. We have added this item in a backlog. However, due to all our efforts currently directed towards developing X-Ray support for OpenTelemetry .Net, it may not be prioritized soon.
If you'd like to contribute the implementation for this feature, I'll be happy to review. :)

Thanks!

@DanielLaberge
Copy link

DanielLaberge commented Jul 21, 2021

@srprash In the meantime, is there any other way to get application logs to show up in XRay Traces?

@bruceharrison1984
Copy link
Author

@DanielLaberge I'm curious to know this as well.

@srprash
Is the current TraceId available in a statically accessible location so it can be added to log messages? And if so, what format does it need to appear in the logs for ServiceLens to take advantage of it?

@srprash
Copy link
Collaborator

srprash commented Jul 29, 2021

@DanielLaberge @bruceharrison1984
The trace id to log correlation involves 2 pieces to work:

  1. A resource plugin (EC2 or ECS) on the X-Ray SDK to record the log-group id on the trace data. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/deploy_servicelens_CloudWatch_agent_logintegration.html
  2. Trace-id and segment-id injection to CloudWatch logs in a specific format. https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-configuration.html#xray-sdk-java-configuration-logging

For the X-Ray .Net SDK, I believe it is still possible to do the 2nd part by fetching the trace-id and segment-id of the current segment and passing it into logger. However, the current resource plugins are missing the logic to get the CW log group ARN to enable ServiceLens to do the actual correlation.

@bruceharrison1984
Copy link
Author

@srprash I appreciate you closing the loop on this 👍

@bruceharrison1984 bruceharrison1984 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
@luizfds
Copy link
Contributor

luizfds commented Oct 6, 2023

I know it's an old thread, but I will comment anyway, as it can help others.

After seeing this GitHub issue and comment in the aws-xray-sdk-python I decided to try the same on .NET SDK and got the same result.

Here is what I did using Serilog.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants