|
1 | 1 | # OpenTelemetry Baggage Span Processor |
2 | 2 |
|
3 | | -The BaggageSpanProcessor reads entries stored in Baggage from the parent context |
4 | | -and adds the baggage keys and values to the `Span` as attributes on start. |
| 3 | +The `BaggageSpanProcessor` and `BaggageLogRecordPRocessor` read entries stored in Baggage from the |
| 4 | +parent context and adds the baggage keys and values to the `Span`, respectively `LogRecord`, as |
| 5 | +attributes on start, respectively emit. |
5 | 6 |
|
6 | | -Add this span processor to a tracer provider. |
| 7 | +Add these span and log processors to the tracer and logger providers. |
7 | 8 |
|
8 | 9 | Warning! |
9 | 10 |
|
10 | 11 | To repeat: a consequence of adding data to Baggage is that the keys and values |
11 | | -will appear in all outgoing trace context headers from the application. |
| 12 | +will appear in all outgoing trace and log context headers from the application. |
12 | 13 |
|
13 | 14 | Do not put sensitive information in Baggage. |
14 | 15 |
|
15 | 16 | ## Usage |
16 | 17 |
|
17 | | -Add the span processor when configuring the tracer provider. |
| 18 | +Add the span and log processor when configuring the tracer and logger providers. |
18 | 19 |
|
19 | | -To configure the span processor to copy all baggage entries during configuration: |
| 20 | +To configure the span and log processors to copy all baggage entries during configuration: |
20 | 21 |
|
21 | 22 | ```java |
22 | 23 | import io.opentelemetry.contrib.baggage.processor; |
23 | 24 | // ... |
24 | 25 |
|
25 | | -Tracer tracer = SdkTracerProvider.builder() |
26 | | - .addSpanProcessor(new BaggageSpanProcessor(BaggageSpanProcessor.allowAllBaggageKeys)) |
27 | | - .build() |
| 26 | +TracerProvider tracerProvider = SdkTracerProvider.builder() |
| 27 | + .addSpanProcessor(BaggageSpanProcessor.allowAllBaggageKeys()) |
| 28 | + .build(); |
| 29 | + |
| 30 | +LoggerProvider loggerProvider = SdkLoggerProvider.builder() |
| 31 | + .addLogRecordProcessor(BaggageLogRecordProcessor.allowAllBaggageKeys()) |
| 32 | + .build(); |
28 | 33 | ``` |
29 | 34 |
|
30 | 35 | Alternatively, you can provide a custom baggage key predicate to select which baggage keys you want to copy. |
31 | 36 |
|
32 | 37 | For example, to only copy baggage entries that start with `my-key`: |
33 | 38 |
|
34 | 39 | ```java |
35 | | -new BaggageSpanProcessor(baggageKey -> baggageKey.startsWith("my-key")) |
| 40 | +new BaggageSpanProcessor(baggageKey -> baggageKey.startsWith("my-key")); |
| 41 | +new BaggageLogRecordProcessor(baggageKey -> baggageKey.startsWith("my-key")); |
36 | 42 | ``` |
37 | 43 |
|
38 | 44 | For example, to only copy baggage entries that match the regex `^key.+`: |
39 | 45 |
|
40 | 46 | ```java |
41 | 47 | Pattern pattern = Pattern.compile("^key.+"); |
42 | | -new BaggageSpanProcessor(baggageKey -> pattern.matcher(baggageKey).matches()) |
| 48 | +new BaggageSpanProcessor(baggageKey -> pattern.matcher(baggageKey).matches()); |
| 49 | +new BaggageLogRecordProcessor(baggageKey -> pattern.matcher(baggageKey).matches()); |
43 | 50 | ``` |
44 | 51 |
|
45 | 52 | ## Usage with SDK auto-configuration |
46 | 53 |
|
47 | | -If you are using the OpenTelemetry SDK auto-configuration, you can add the span processor this |
48 | | -library to configure the span processor. |
| 54 | +If you are using the OpenTelemetry SDK auto-configuration, you can add the span and log baggage |
| 55 | +processors through configuration. |
49 | 56 |
|
50 | | -| Property | Description | |
51 | | -|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| |
52 | | -| otel.java.experimental.span-attributes.copy-from-baggage.include | Add baggage entries as span attributes, e.g. `key1,key2` or `*` to add all baggage items as keys. | |
| 57 | +| Property | Description | |
| 58 | +|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| |
| 59 | +| `otel.java.experimental.span-attributes.copy-from-baggage.include` | Add baggage entries as span attributes, e.g. `key1,key2` or `*` to add all baggage items as keys. | |
| 60 | +| `otel.java.experimental.log-attributes.copy-from-baggage.include` | Add baggage entries as log attributes, e.g. `key1,key2` or `*` to add all baggage items as keys. | |
53 | 61 |
|
54 | 62 | ## Component owners |
55 | 63 |
|
|
0 commit comments