Skip to content

Commit 69c6096

Browse files
authored
Logging trace context compatibility document (open-telemetry#3331)
1 parent 3110c2d commit 69c6096

File tree

3 files changed

+75
-60
lines changed

3 files changed

+75
-60
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ release.
2222
([#3332](https://github.com/open-telemetry/opentelemetry-specification/pull/3332))
2323
- Remove log readme document status.
2424
([#3334](https://github.com/open-telemetry/opentelemetry-specification/pull/3334))
25+
- Break out compatibility document on recording trace context in non-OTLP Log Format
26+
([#3331](https://github.com/open-telemetry/opentelemetry-specification/pull/3331))
2527

2628
### Resource
2729

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Trace Context in non-OTLP Log Formats
2+
3+
**Status**: [Experimental](../document-status.md)
4+
5+
<details>
6+
<summary>Table of Contents</summary>
7+
8+
<!-- toc -->
9+
10+
- [Overview](#overview)
11+
* [Syslog RFC5424](#syslog-rfc5424)
12+
* [Plain Text Formats](#plain-text-formats)
13+
* [JSON Formats](#json-formats)
14+
* [Other Structured Formats](#other-structured-formats)
15+
16+
<!-- tocstop -->
17+
18+
</details>
19+
20+
## Overview
21+
22+
OTLP Logs Records have top level fields
23+
representing [trace context](../logs/data-model.md#trace-context-fields). This
24+
document defines how trace context should be recorded in non-OTLP Log Formats.
25+
To summarize, the following field names should be used in legacy formats:
26+
27+
- "trace_id" for [TraceId](../logs/data-model.md#field-traceid), hex-encoded.
28+
- "span_id" for [SpanId](../logs/data-model.md#field-spanid), hex-encoded.
29+
- "trace_flags" for [trace flags](../logs/data-model.md#field-traceflags), formatted
30+
according to W3C traceflags format.
31+
32+
All 3 fields are optional (see the [data model](../logs/data-model.md) for details of
33+
which combination of fields is considered valid).
34+
35+
### Syslog RFC5424
36+
37+
Trace id, span id and traceflags SHOULD be recorded via SD-ID "opentelemetry".
38+
39+
For example:
40+
41+
```
42+
[opentelemetry trace_id="102981ABCD2901" span_id="abcdef1010" trace_flags="01"]
43+
```
44+
45+
### Plain Text Formats
46+
47+
The fields SHOULD be recorded according to the customary approach used for a
48+
particular format (e.g. field:value format for LTSV). For example:
49+
50+
```
51+
host:192.168.0.1<TAB>trace_id:102981ABCD2901<TAB>span_id:abcdef1010<TAB>time:[01/Jan/2010:10:11:23 -0400]<TAB>req:GET /health HTTP/1.0<TAB>status:200
52+
```
53+
54+
### JSON Formats
55+
56+
The fields SHOULD be recorded as top-level fields in the JSON structure. For example:
57+
58+
```json
59+
{
60+
"timestamp":1581385157.14429,
61+
"body":"Incoming request",
62+
"trace_id":"102981ABCD2901",
63+
"span_id":"abcdef1010"
64+
}
65+
```
66+
67+
### Other Structured Formats
68+
69+
The fields SHOULD be recorded as top-level structured attributes of the log
70+
record as it is customary for the particular format.

specification/logs/README.md

+3-60
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ aliases: [/docs/reference/specification/logs/overview]
2525
- [OpenTelemetry Collector](#opentelemetry-collector)
2626
- [Auto-Instrumenting Existing Logging](#auto-instrumenting-existing-logging)
2727
- [Specifications](#specifications)
28-
- [Trace Context in Legacy Formats](#trace-context-in-legacy-formats)
29-
* [Syslog RFC5424](#syslog-rfc5424)
30-
* [Plain Text Formats](#plain-text-formats)
31-
* [JSON Formats](#json-formats)
32-
* [Other Structured Formats](#other-structured-formats)
3328

3429
<!-- tocstop -->
3530

@@ -329,7 +324,8 @@ The benefit of using an intermediary medium is that how logs are produced and
329324
where they are written by the application requires no or minimal changes. The
330325
downside is that it requires the often non-trivial log file reading and parsing
331326
functionality. Parsing may also be not reliable if the output format is not
332-
well-defined.
327+
well-defined. For details on recording and parsing trace context,
328+
see [Trace Context in Non-OTLP Log Formats](../compatibility/logging_trace_context.md).
333329

334330
#### Direct to Collector
335331

@@ -449,57 +445,4 @@ standard output.
449445
* [Logs Data Model](./data-model.md)
450446
* [Event API](./event-api.md)
451447
* [Semantic Conventions](./semantic_conventions/README.md)
452-
453-
## Trace Context in Legacy Formats
454-
455-
Earlier we briefly mentioned that it is possible to modify existing applications
456-
so that they include the Request Context information in the emitted logs.
457-
458-
[OTEP0114](https://github.com/open-telemetry/oteps/pull/114) defines how the
459-
trace context should be recorded in logs. To summarize, the following field
460-
names should be used in legacy formats:
461-
462-
- "trace_id" for [TraceId](data-model.md#field-traceid), hex-encoded.
463-
- "span_id" for [SpanId](data-model.md#field-spanid), hex-encoded.
464-
- "trace_flags" for [trace flags](data-model.md#field-traceflags), formatted
465-
according to W3C traceflags format.
466-
467-
All 3 fields are optional (see the [data model](data-model.md) for details of
468-
which combination of fields is considered valid).
469-
470-
### Syslog RFC5424
471-
472-
Trace id, span id and traceflags SHOULD be recorded via SD-ID "opentelemetry".
473-
474-
For example:
475-
476-
```
477-
[opentelemetry trace_id="102981ABCD2901" span_id="abcdef1010" trace_flags="01"]
478-
```
479-
480-
### Plain Text Formats
481-
482-
The fields should be recorded according to the customary approach used for a
483-
particular format (e.g. field:value format for LTSV). For example:
484-
485-
```
486-
host:192.168.0.1<TAB>trace_id:102981ABCD2901<TAB>span_id:abcdef1010<TAB>time:[01/Jan/2010:10:11:23 -0400]<TAB>req:GET /health HTTP/1.0<TAB>status:200
487-
```
488-
489-
### JSON Formats
490-
491-
The fields should be recorded as top-level fields in the JSON structure. For example:
492-
493-
```json
494-
{
495-
"timestamp":1581385157.14429,
496-
"body":"Incoming request",
497-
"trace_id":"102981ABCD2901",
498-
"span_id":"abcdef1010"
499-
}
500-
```
501-
502-
### Other Structured Formats
503-
504-
The fields should be recorded as top-level structured attributes of the log
505-
record as it is customary for the particular format.
448+
* [Trace Context in non-OTLP Log Formats](../compatibility/logging_trace_context.md)

0 commit comments

Comments
 (0)