aboutsummaryrefslogtreecommitdiff
path: root/buildscripts
diff options
context:
space:
mode:
authorsebright <sebright@google.com>2018-08-27 09:49:05 -0700
committerGitHub <noreply@github.com>2018-08-27 09:49:05 -0700
commit0bbfec84cbf898ae7327880c43f9b5c60c49d4cd (patch)
treebfa669feb6c2d26d4eb644d38e4d1272fc13af92 /buildscripts
parentb8e6dcc312c9655a1d5709c15a2e408903314cbe (diff)
downloadopencensus-java-0bbfec84cbf898ae7327880c43f9b5c60c49d4cd.tar.gz
Start adding log correlation for Log4j. (#1371)
This commit takes the approach of implementing Log4j's ContextDataInjector. It inserts three keys into each log event: "`openCensusTraceId`", "`openCensusSpanId`", and "`openCensusTraceSampled`". The tracing data can be accessed with LogEvent.getContextData() or included in a layout. See https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/ContextDataInjector.html. Here is an example of a pattern layout that includes all three tracing fields and a log entry that could be produced by the layout: Pattern layout: "`%d{HH:mm:ss.SSS} [%t] traceId=%X{openCensusTraceId} spanId=%X{openCensusSpanId} sampled=%X{openCensusTraceSampled} %-5level %logger{36} - %msg%n`" Log entry: "`20:45:52.929 [main] traceId=0af7a7bef890695f1c5e85a8e7290164 spanId=d3f07c467ec2fbb2 sampled=true WARN io.opencensus.contrib.logcorrelation.log4j.demo.OpenCensusLog4jLogCorrelationDemo - my log message`" The ContextDataInjector implementation must be specified with a system property, i.e., "`-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j.OpenCensusTraceContextDataInjector`". The system property "`io.opencensus.contrib.logcorrelation.log4j.OpenCensusTraceContextDataInjector.spanSelection`" controls whether tracing data is added to all spans, no spans, or only sampled spans.
Diffstat (limited to 'buildscripts')
-rw-r--r--buildscripts/import-control.xml4
1 files changed, 4 insertions, 0 deletions
diff --git a/buildscripts/import-control.xml b/buildscripts/import-control.xml
index f0574df7..7375eb5f 100644
--- a/buildscripts/import-control.xml
+++ b/buildscripts/import-control.xml
@@ -97,6 +97,10 @@ General guidelines on imports:
<allow pkg="io.opencensus.tags"/>
<allow pkg="io.opencensus.trace"/>
</subpackage>
+ <subpackage name="logcorrelation.log4j">
+ <allow pkg="io.opencensus.trace"/>
+ <allow pkg="org.apache.logging.log4j"/>
+ </subpackage>
<subpackage name="logcorrelation.stackdriver">
<allow pkg="com.google.cloud"/>
<allow pkg="io.opencensus.trace"/>