Skip to content

Commit

Permalink
[headerssetter] Update docs to clarify how to use "from_context" (ope…
Browse files Browse the repository at this point in the history
…n-telemetry#31283)

This clarifies potential confusion about how to access metadata using
the `from_context` configuration argument.

A few months ago I submitted open-telemetry#27465 to remove an obsolete warning, but
then a user
[asked](open-telemetry@d50e094#commitcomment-131957576)
about why their `from_context` isn't working properly with a batch
processor. I agree that it's not obvious, so I hope this PR clarifies it
enough.

I did not try running the update example, so I hope it works :) 

cc @jpkrohling
  • Loading branch information
ptodev committed Feb 19, 2024
1 parent 0d1f562 commit 090a18f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions extension/headerssetterextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ The following settings are required:

The `value` and `from_context` properties are mutually exclusive.

In order for `from_context` to work, other components in the pipeline also need to be configured appropriately:
* If a [batch processor][batch-processor] is present in the pipeline, it must be configured to [preserve client metadata][batch-processor-preserve-metadata].
Add the value which `from_context` needs to the `metadata_keys` of the batch processor.
* Receivers must be configured with `include_metadata: true` so that metadata keys are available to the pipeline.

#### Configuration Example

```yaml
Expand All @@ -67,7 +72,10 @@ receivers:
include_metadata: true

processors:
nop:
batch:
# Preserve the tenant-id metadata.
metadata_keys:
- tenant_id

exporters:
loki:
Expand All @@ -84,10 +92,13 @@ service:
pipelines:
traces:
receivers: [ otlp ]
processors: [ nop ]
processors: [ batch ]
exporters: [ loki ]
```

[batch-processor]: https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor/batchprocessor/README.md
[batch-processor-preserve-metadata]: https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor/batchprocessor/README.md#batching-and-client-metadata

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[Mimir]: https://grafana.com/oss/mimir/
Expand Down

0 comments on commit 090a18f

Please sign in to comment.