Skip to content

Latest commit

 

History

History

headerssetterextension

Headers Setter extension

Status
Stability alpha
Distributions contrib

The headers_setter extension implements ClientAuthenticator and is used to set requests headers in gRPC / HTTP exporters with values provided via extension configurations or requests metadata (context).

Use cases include but are not limited to enabling multi-tenancy for observability backends such as Tempo, Mimir, Loki and others by setting the X-Scope-OrgID header to the value extracted from the context.

Configuration

The following settings are required:

  • headers: a list of header configuration objects that specify headers and their value sources. Each configuration object has the following properties:
    • key: The header name.
    • action (default: upsert): An action to perform on the header. Supported actions are:
      • insert: Inserts the new header if it does not exist.
      • update: Updates the header value if it exists.
      • upsert: Inserts a header if it does not exist and updates the header if it exists.
      • delete: Deletes the header.
    • value: The header value is looked up from the value property of the extension configuration.
    • from_context: The header value is looked up from the request metadata, such as HTTP headers, using the property value as the key (likely a header name).

The value and from_context properties are mutually exclusive.

Configuration Example

extensions:
  headers_setter:
    headers:
      - action: insert
        key: X-Scope-OrgID
        from_context: tenant_id
      - action: upsert
        key: User-ID
        value: user_id
      - action: update
        key: User-ID
        value: user_id
      - action: delete
        key: Some-Header

receivers:
  otlp:
    protocols:
      http:
        include_metadata: true

processors:
  nop:

exporters:
  loki:
    labels:
      resource:
        container_id: ""
        container_name: ""
    endpoint: https://localhost:<port>/loki/api/v1/push
    auth:
      authenticator: headers_setter

service:
  extensions: [ headers_setter ]
  pipelines:
    traces:
      receivers: [ otlp ]
      processors: [ nop ]
      exporters: [ loki ]

Limitations

At the moment, it is not possible to use the from_context option to ge the header value if Collector's pipeline contains the batch processor. See #4544.