@@ -70,9 +70,12 @@ Exactly one of `value` or `from_context` must be provided for each `header`
70
70
block.
71
71
72
72
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.
73
74
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.
76
79
77
80
## Exported fields
78
81
@@ -96,10 +99,29 @@ configuration.
96
99
This example configures [ otelcol.exporter.otlp] [ ] to use custom headers:
97
100
98
101
``` 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]
103
125
}
104
126
}
105
127
@@ -114,6 +136,13 @@ otelcol.auth.headers "creds" {
114
136
value = "user_id"
115
137
}
116
138
}
139
+
140
+ otelcol.exporter.otlp "production" {
141
+ client {
142
+ endpoint = env("OTLP_SERVER_ENDPOINT")
143
+ auth = otelcol.auth.headers.creds.handler
144
+ }
145
+ }
117
146
```
118
147
119
148
[ otelcol.exporter.otlp] : {{< relref "./otelcol.exporter.otlp.md" >}}
0 commit comments