Skip to content

Conversation

@agocs
Copy link
Contributor

@agocs agocs commented Nov 9, 2020

What does this PR do?

This adds the capability to inject trace IDs into your logs so that you can correlate your logs with your traces.

In the case of XRay tracing, this calculates a DD Trace ID from the last 63 bits of the XRay trace ID. It exposes a method from within DDLambda that lets you get your trace ID. It also adds the trace ID to the slf4j MDC so that the trace ID can be accessed by Log4J or other logging frameworks.

Testing Guidelines

Done: Unit tests that instantiate a new DDLambda (w/XRay tracing) and attempt to log some things using Log4J, verifying that the trace ID was added to the logs. Created a test lambda using log4j and verified it worked as expected.

Additional Notes

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Checklist

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • [xc] This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@agocs agocs requested a review from a team as a code owner November 9, 2020 22:03
@@ -1,5 +1,6 @@
package com.datadoghq.datadog_lambda_java;

import org.slf4j.MDC;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a standard logging solution? Or are we forcing people to add it as a dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slf4j is a standard logging facade that unifies the most common java logging frameworks (log4j, java.util.logging, logback, etc). Our users aren't forced to use it; they can get the trace ID as a raw string and incorporate it however they want.


@Test
public void getAPMTraceID() {
XRayTraceContext xrt = new XRayTraceContext();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look good. They are the same tests we have in the other languages right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I ported these from Go directly

@agocs
Copy link
Contributor Author

agocs commented Nov 12, 2020

@DarcyRaynerDD , to confirm, the span ID is the parent ID, correct?

Copy link

@DarcyRaynerDD DarcyRaynerDD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Left a nit on the docs

README.md Outdated
#### Plain text logs

If you are using plain text logs, then you must create a new [Parser](https://docs.datadoghq.com/logs/processing/parsing/?tab=matcher)
that can extract the trace context from the correct position in the logs. Use the helper `_trace_context` to

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that this helper is only available if you are modifying our Lambda pipeline, with our existing grok rules.

@agocs agocs merged commit 5f6067f into master Nov 16, 2020
@agocs agocs deleted the chris.agocs/add_trace_log_correlation branch November 16, 2020 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants