Can Apigee emit a W3C traceparent derived from x-b3-traceid?

Hi all,

Trying to bridge B3 → W3C Trace Context so downstream services can correlate Apigee logs with traces in Dynatrace.

Flow: Client → Apigee → Cloud Run (Java + OTel) → Apigee → Cloud Run (Java + OTel)

  • Apigee propagates B3 only (x-b3-traceid).
  • Cloud Run auto-injects its own W3C traceparent with a different trace ID when none is present, breaking correlation.
  • Per Google’s docs, Cloud Run preserves an inbound traceparent if one exists. So if Apigee emitted traceparent carrying the same ID as x-b3-traceid, both headers would align end-to-end.

Questions:

  1. Does Apigee have any native W3C Trace Context support or workarounds we could try?
  2. If not, what’s the recommended way to build a traceparent (00-<32-hex-trace>-<16-hex-span>-01) from x-b3-traceid / x-b3-spanid?
  3. Where should the policy live — ProxyEndpoint request flow?
  4. Does anyone have a sample policy for this (or a similar header-derivation pattern)?

Thanks :folded_hands:

Apigee does not natively auto-generate W3C traceparent headers, but you can bridge B3 and W3C by using an AssignMessage policy to construct the header manually.

To build a valid traceparent string (\(00-\langle trace\_id \rangle-\langle span\_id \rangle-01\)), insert the following policy in the ProxyEndpoint PreFlow Request.

Extract B3 VariablesUse an ExtractVariables policy first if you need to parse the incoming headers, though Apigee automatically exposes standard B3 headers as flow variables (e.g., request.header.x-b3-traceid and request.header.x-b3-spanid)

Construct the Traceparent HeaderUse the AssignMessage policy to format the W3C trace ID. The W3C trace ID requires exactly 32 hex characters. Since B3 uses 16 or 32 characters depending on the client, you should pad it if necessary (though most OTel environments accept the standard payload).

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Assign W3C traceparent 00-{request.header.x-b3-traceid}-{request.header.x-b3-spanid}-01 true

Trace ID Length NoteIf your clients emit 16-character B3 trace IDs, the W3C spec strictly requires 32 hex digits. In that scenario, you would need to prepend zeros. You can use a JavaScript policy to execute custom string padding and logic before injecting the header

var traceId = context.getVariable("request.header.x-b3-traceid");                        var spanId = context.getVariable("request.header.x-b3-spanid");                                                                                             W3C Trace IDs must be 32 hex characters, pad if necessary         while                      (traceId.length < 32) { traceId = "0" + traceId;                            while (spanId.length < 16) {spanId = "0" + spanId;