|
| 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. |
0 commit comments