-
Notifications
You must be signed in to change notification settings - Fork 14
Add trace log correlation #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f20c750
adjust version code and add version tag to readme
1d918e1
Merge branch 'master' of github.com:DataDog/datadog-lambda-java into …
efd6591
Add trace/log correlation info
cf3380d
Add instructions for how to add trace ids to your logs
bb32c93
Made some decisions about some log levels
b3f0022
Add span ID, add more detail in the README
0eadd7a
Update README and version number
16fdf5e
Explicitly mention cloning the lambda pipeline
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/com/datadoghq/datadog_lambda_java/TraceLogCorrelationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.datadoghq.datadog_lambda_java; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.PrintStream; | ||
| import java.util.Map; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.apache.log4j.Logger; | ||
| import org.apache.log4j.ConsoleAppender; | ||
| import org.apache.log4j.WriterAppender; | ||
| import org.apache.log4j.PatternLayout; | ||
|
|
||
|
|
||
| public class TraceLogCorrelationTest { | ||
| private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
| private final PrintStream originalErr = System.err; | ||
|
|
||
| @Test | ||
| public void TestWithLog4J(){ | ||
| Logger logger = Logger.getLogger(TraceLogCorrelationTest.class.getName()); | ||
| PatternLayout layout = new PatternLayout("%d{ISO8601} %X{dd.trace_context} [%t] %-5p %c %x - %m%n"); | ||
| logger.addAppender(new ConsoleAppender((layout))); | ||
|
|
||
| logger.info("Test log message"); | ||
|
|
||
| EnhancedMetricTest.MockContext mc = new EnhancedMetricTest.MockContext(); | ||
|
|
||
| //try to grab the contents of StdErr | ||
| logger.addAppender(new WriterAppender(layout, outContent)); | ||
| DDLambda ddl = new DDLambda(mc, "Root=1-5fa98677-5dda00b12ec8b1c31f61aa82;Parent=b481b4a6ef3a296c;Sampled=1"); | ||
| outContent.reset(); | ||
| logger.info("Test log message 2"); | ||
| logger.removeAllAppenders(); | ||
|
|
||
| String logOutput = outContent.toString(); | ||
| String[] logFields = logOutput.split(" "); | ||
| Assert.assertEquals("[dd.trace_id=3371139772690049666", logFields[2]); | ||
| Assert.assertEquals("dd.span_id=13006875827893840236]", logFields[3]); | ||
| } | ||
|
|
||
| @Test | ||
| public void TestGetTraceLogCorrelationId(){ | ||
| EnhancedMetricTest.MockContext mc = new EnhancedMetricTest.MockContext(); | ||
| DDLambda ddl = new DDLambda(mc, "Root=1-5fa98677-5dda00b12ec8b1c31f61aa82;Parent=b481b4a6ef3a296c;Sampled=1"); | ||
|
|
||
| Map<String,String> traceInfo = ddl.getTraceContext(); | ||
| Assert.assertEquals("3371139772690049666", traceInfo.get("dd.trace_id")); | ||
| Assert.assertEquals("13006875827893840236", traceInfo.get("dd.span_id")); | ||
| } | ||
|
|
||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.