Skip to content
Latest (currently 2026.10.2) has the newest features, bug fixes, and CVE patches of Solo Enterprise for agentgateway.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Distributed tracing headers

Page as Markdown

Inject dynamically generated UUIDs and random sampling values into request headers using CEL expressions.

Use the uuid() and random() CEL functions to inject dynamically generated values into request headers. uuid() generates a unique UUIDv4 string on each request, useful for correlation IDs in distributed tracing. random() returns a float between 0.0 and 1.0, useful for probabilistic sampling decisions.

Before you begin

  1. Set up an agentgateway proxy.
  2. Install the httpbin sample app.

Generate request tracing headers

Tracing every request can be expensive at high traffic volumes. A common pattern is to inject a unique ID for correlation and a random value that a downstream tracing backend uses to decide whether to record a full trace, keeping only a percentage of all requests.

In this example, two headers are injected on every incoming request before it is forwarded upstream:

  • x-request-id: A unique UUIDv4 generated by uuid(), used to correlate the request across services.
  • x-sampling-decision: A random float from the random() function. For example, you might have a tracing backend that is configured to sample requests only if the x-sampling-decision header is set to 0.1 or less.
  1. Create an EnterpriseAgentgatewayPolicy resource with your transformation rules.

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: transformation
      namespace: httpbin
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: httpbin
      traffic:
        transformation:
          request:
            set:
            - name: x-request-id
              value: 'uuid()'
            - name: x-sampling-decision
              value: 'string(random())'
    EOF

    The expression breaks down as follows:

    • uuid(): Generates a new UUIDv4 string for each request, such as f47ac10b-58cc-4372-a567-0e02b2c3d479.
    • random(): Generates a random float between 0.0 and 1.0, such as 0.4731. Wrap the transformation in string() so the value can be set as a header string.
  2. Send a request and verify that both headers are present in the forwarded request.

    curl -vi http://$INGRESS_GW_ADDRESS:80/get \
     -H "host: www.example.com:80"
    curl -vi localhost:8080/get \
    -H "host: www.example.com"

    Example output:

    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    ...
    {
      "headers": {
        "X-Request-Id": [
           "81895ac3-0b2b-45cb-901d-068b517c7262"
        ],
        "X-Sampling-Decision": [
           "0.32929987260956217"
        ]
        ...
      },
      ...
    }
    

    Each request produces a different X-Request-Id value. The X-Sampling-Decision value varies between 0.0 and 1.0 on each request.

Cleanup

You can remove the resources that you created in this guide.
kubectl delete EnterpriseAgentgatewayPolicy transformation -n httpbin