Skip to content

Commit e7b95cf

Browse files
In otelcol.auth.headers, clarify usage of from_context (#6373)
* Clarify usage of from_context * Apply suggestions from code review Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> --------- Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
1 parent c57cb77 commit e7b95cf

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

docs/sources/flow/reference/components/otelcol.auth.headers.md

+35-6
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ Exactly one of `value` or `from_context` must be provided for each `header`
7070
block.
7171

7272
The `value` attribute sets the value of the header directly.
73+
Alternatively, `from_context` can be used to dynamically retrieve the header value from request metadata.
7374

74-
Alternatively, `from_context` can be used to dynamically retrieve the header
75-
value from request metadata.
75+
For `from_context` to work, other components in the pipeline also need to be configured appropriately:
76+
* If an `otelcol.processor.batch` is present in the pipeline, it must be configured to preserve client metadata.
77+
Do this by adding the value that `from_context` needs to the `metadata_keys` of the batch processor.
78+
* `otelcol` receivers must be configured with `include_metadata` set to `true` so that metadata keys are available to the pipeline.
7679

7780
## Exported fields
7881

@@ -96,10 +99,29 @@ configuration.
9699
This example configures [otelcol.exporter.otlp][] to use custom headers:
97100

98101
```river
99-
otelcol.exporter.otlp "example" {
100-
client {
101-
endpoint = "my-otlp-grpc-server:4317"
102-
auth = otelcol.auth.headers.creds.handler
102+
otelcol.receiver.otlp "default" {
103+
http {
104+
include_metadata = true
105+
}
106+
grpc {
107+
include_metadata = true
108+
}
109+
110+
output {
111+
metrics = [otelcol.processor.batch.default.input]
112+
logs = [otelcol.processor.batch.default.input]
113+
traces = [otelcol.processor.batch.default.input]
114+
}
115+
}
116+
117+
otelcol.processor.batch "default" {
118+
// Preserve the tenant_id metadata.
119+
metadata_keys = ["tenant_id"]
120+
121+
output {
122+
metrics = [otelcol.exporter.otlp.production.input]
123+
logs = [otelcol.exporter.otlp.production.input]
124+
traces = [otelcol.exporter.otlp.production.input]
103125
}
104126
}
105127
@@ -114,6 +136,13 @@ otelcol.auth.headers "creds" {
114136
value = "user_id"
115137
}
116138
}
139+
140+
otelcol.exporter.otlp "production" {
141+
client {
142+
endpoint = env("OTLP_SERVER_ENDPOINT")
143+
auth = otelcol.auth.headers.creds.handler
144+
}
145+
}
117146
```
118147

119148
[otelcol.exporter.otlp]: {{< relref "./otelcol.exporter.otlp.md" >}}

0 commit comments

Comments
 (0)