headerssetterextension

package module
v0.99.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 7

README

Headers Setter extension

Status
Stability alpha
Distributions contrib
Issues Open issues Closed issues
Code Owners @jpkrohling

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.

In order for from_context to work, other components in the pipeline also need to be configured appropriately:

  • If a batch processor is present in the pipeline, it must be configured to preserve client 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
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:
  batch:
    # Preserve the tenant-id metadata.
    metadata_keys:
    - tenant_id

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: [ batch ]
      exporters: [ loki ]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFactory

func NewFactory() extension.Factory

NewFactory creates a factory for the headers setter extension.

Types

type ActionValue added in v0.82.0

type ActionValue string

ActionValue is the enum to capture the four types of actions to perform on a header

const (
	// INSERT inserts the new header if it does not exist
	INSERT ActionValue = "insert"

	// UPDATE updates the header value if it exists
	UPDATE ActionValue = "update"

	// UPSERT inserts a header if it does not exist and updates the header
	// if it exists
	UPSERT ActionValue = "upsert"

	// DELETE deletes the header
	DELETE ActionValue = "delete"
)

type Config

type Config struct {
	HeadersConfig []HeaderConfig `mapstructure:"headers"`
}

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks if the extension configuration is valid

type Header struct {
	// contains filtered or unexported fields
}

type HeaderConfig

type HeaderConfig struct {
	Action      ActionValue `mapstructure:"action"`
	Key         *string     `mapstructure:"key"`
	Value       *string     `mapstructure:"value"`
	FromContext *string     `mapstructure:"from_context"`
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL