Forwarding a HTTP header

199 Views Asked by At

I have a http header: X-Seq-ApiKey send as part of the request going to the otel collector.
I need to forward this through the otelhttp exporter.

I have found this extension, that i believe should be able to solve my problem. However I am having a LOT of trouble understanding how to use this extension correctly.

receivers:
  otlp:
    protocols:
      grpc:
        include_metadata: true
        
exporters:
  debug:
    #verbosity: detailed
  otlphttp/seq:
    endpoint: http://seq:5341/ingest/otlp
  otlp/jaeger:
    endpoint: http://jaeger:4317
    tls:
      insecure: true
    
extensions:
  health_check:
  pprof:
  zpages:
    endpoint: ":55679"
  headers_setter:
    headers:
      - action: upsert
        key: X-Seq-ApiKey
        from_context: X-Seq-ApiKey
        
service:
  extensions: [zpages, headers_setter]
  pipelines:
    traces:
      receivers: [otlp]
      processors: []
      exporters: [otlp/jaeger]
    metrics:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    logs:
      receivers: [otlp]
      processors: []
      exporters: [otlphttp/seq]

I have tried using both value and from_context - with no luck.
Since the documentation is lacking an example of the incoming http request header, it is a bit tricky to figure out what the correct values are here. I have tried all the combinations i can think of, so i must be doing something else wrong. Any input?

1

There are 1 best solutions below

1
Snehasish Konger On

Here's what you can do:

  1. Ensure the incoming request contains the X-Seq-ApiKey header.
  2. Modify the service section to include the headers_setter extension in the logs pipeline:
service:
  extensions: [zpages, headers_setter]
  pipelines:
    logs:
      receivers: [otlp]
      processors: []
      exporters: [otlphttp/seq]
      # Make sure to add the extension here
      extensions: [headers_setter]
  1. In your headers_setter configuration, you should set the header with a static value for testing. If it works, then switch to from_context:
extensions:
  headers_setter:
    headers:
      - action: upsert
        key: X-Seq-ApiKey
        value: "static_value_for_testing"
        # If static value works, replace the above line with the one below
        # from_context: X-Seq-ApiKey

After making these changes, restart the OpenTelemetry Collector and observe if the header is being forwarded correctly. If it's not, the issue might not be with your configuration but with how the header is being handled by the collector or the exporter.