Stuck on injecting OTel context into Genesys Notification WebSocket subscriptions

Stuck on injecting OTel context into Genesys Notification WebSocket subscriptions.

I am using the Python websockets library to connect to wss://api.mypurecloud.com/api/v2/analytics/conversations/events. I need to propagate the current trace context (traceparent) from my upstream Data Action trigger to the WebSocket handshake so I can correlate inbound events back to the originating span in Jaeger. The standard SDK does not support custom headers on the WebSocket upgrade. Here is my current setup:

import websockets
import asyncio

headers = {
 "Authorization": f"Bearer {access_token}",
 "Traceparent": trace_context_header # e.g., "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
}

async def subscribe():
 uri = f"wss://api.mypurecloud.com/api/v2/analytics/conversations/events?ids={conversation_id}"
 async with websockets.connect(uri, extra_headers=headers) as websocket:
 async for message in websocket:
 process_event(message)

The connection fails with a 401 Unauthorized immediately after the handshake attempt, despite the token being valid for REST calls. Does the Notification API WebSocket endpoint reject custom headers during the HTTP Upgrade phase, or is there a specific query parameter mechanism I am missing to attach correlation IDs without breaking authentication?

Check your handshake payload structure. The WebSocket endpoint ignores custom headers on the upgrade request, so you have to embed the traceparent in the initial subscription JSON.

{
 "subscriptions": [
 {
 "type": "conversation",
 "traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
 }
 ]
}

How I usually solve this is by injecting the traceparent into the subscription payload body, exactly as mentioned. the handshake headers are stripped by the gateway anyway. make sure your data action output schema maps the trace context to that nested object before sending. here is a quick jsonpath transform snippet to help.

{
 "subscriptions": [
 {
 "type": "conversation",
 "traceparent": "$.context.traceparent"
 }
 ]
}