We’re building a custom chat UI to bypass the default widget and get full control over the UI state for our tracing pipeline. The goal is to inject an OpenTelemetry trace ID into every message sent via the WebSocket connection so we can correlate the chat session with backend Data Action spans.
I’m connecting to wss://webchat.genesyscloud.com/v1/{organizationId}/guest/{guestId}/connect and successfully sending a send-message command. However, the customAttributes field in the payload seems to be ignored or stripped when the message arrives at the platform side. Here’s the JSON I’m pushing:
The WebSocket handshake works fine, but I don’t see these attributes in the interaction metadata later. Is there a specific header or payload structure required for the Guest API to accept custom metadata? Or do I need to attach this data via a different mechanism before the connection is established?
You’re probably hitting a wall because the send-message command doesn’t natively accept arbitrary headers or trace contexts in its payload. The WebSocket spec for Genesys is pretty strict on what it accepts.
If you want that OpenTelemetry trace ID to stick with the interaction for backend correlation, you shouldn’t try to shove it into the message body itself. It’s better to attach it to the conversation context when the session initializes. You can use the set-attributes command right after the connect handshake. This puts the trace ID into the conversation’s custom attributes, which then flows through to Architect Data Actions and the Analytics API.
Once that’s set, any Data Action you trigger later in the flow can grab conversation.attributes.otel_trace_id. It’s a bit more work than just adding a header, but it actually persists. If you need it on every single message for some reason, you’d have to maintain that state on your client side and resend those attributes with every send-message, but that feels like overkill and might hit rate limits or payload size caps.
Just watch out for the character limit on attributes. Genesys caps them, so if your trace context gets huge, you might get truncated. Usually the trace ID and span ID are short enough, though.