Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 598cbb8

Browse files
authored
Add specification of log correlation for tracing (issue #123). (#181)
The specification only covers aspects of log correlation that are likely to be shared by log correlation implementations for multiple languages and logging frameworks. It is based on the experimental log correlation libraries in opencensus-java: https://github.com/census-instrumentation/opencensus-java/tree/master/contrib/log_correlation/stackdriver https://github.com/census-instrumentation/opencensus-java/tree/master/contrib/log_correlation/log4j2
1 parent 4173983 commit 598cbb8

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

trace/LogCorrelation.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Log Correlation (draft)
2+
3+
This specification is not done until the key names below are finalized (issue
4+
[#195](https://github.com/census-instrumentation/opencensus-specs/issues/195)).
5+
6+
Log correlation is a feature that inserts information about the current span into log entries
7+
created by existing logging frameworks. The feature can be used to add more context to log entries,
8+
filter log entries by trace ID, or find log entries associated with a specific trace or span.
9+
10+
The design of a log correlation implementation depends heavily on the details of the particular
11+
logging framework that it supports. Therefore, this document only covers the aspects of log
12+
correlation that could be shared across log correlation implementations for multiple languages and
13+
logging frameworks. It doesn't cover how to hook into the logging framework.
14+
15+
## Identifying the span to associate with a log entry
16+
17+
A log correlation implementation should look up tracing data from the span that is current at the
18+
point of the log statement. See
19+
[Span.md#how-span-interacts-with-context](Span.md#how-span-interacts-with-context) for the
20+
definition of the current span.
21+
22+
## Tracing data to include in log entries
23+
24+
A log correlation implementation should make the following pieces of tracing data from the current
25+
span context available in each log entry:
26+
27+
### Trace ID
28+
29+
The trace ID of the current span. See [Span.md#traceid](Span.md#traceid).
30+
31+
### Span ID
32+
33+
The span ID of the current span. See [Span.md#spanid](Span.md#spanid).
34+
35+
### Sampling Decision
36+
37+
The sampling bit of the current span, as a boolean. See
38+
[Span.md#supported-bits](Span.md#supported-bits).
39+
40+
TODO(sebright): Include "samplingScore" once that field is added to the SpanContext.
41+
42+
TODO(sebright): Add a section on fields from the Tracestate. Users should be able to add
43+
vendor-specific fields from the Tracestate to logs, using a callback mechanism.
44+
45+
TODO(sebright): Consider adding parent span ID, to allow recreating the trace structure from logs.
46+
47+
## String format for tracing data
48+
49+
The logging framework may require the pieces of tracing data to be converted to strings. In that
50+
case, the log correlation implementation should format the trace ID and span ID as lowercase base 16
51+
and format the sampling decision as "true" or "false".
52+
53+
## Key names for tracing data
54+
55+
Some logging frameworks allow the insertion of arbitrary key-value pairs into log entries. When
56+
a log correlation implementation inserts tracing data by that method, the key names should be
57+
"opencensusTraceId", "opencensusSpanId", and "opencensusTraceSampled" by default. The log
58+
correlation implementation may allow the user to override the tracing data key names.

trace/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ describes the key types and the overall behavior.
1010
* [gRPC integration](gRPC.md): document about how to instrument gRPC framework.
1111
* [HTTP integration](HTTP.md): document about how to instrument http frameworks.
1212
* [Sampling logic](Sampling.md): document about how sampling works.
13+
* [Log correlation](LogCorrelation.md): specification for a feature for inserting tracing data into log entries.

0 commit comments

Comments
 (0)