I can’t seem to figure out why my OpenTelemetry span context is being dropped when I attempt to inject it into a CXone Studio Snippet using standard ASSIGN and IF logic.
I am building a distributed tracing pipeline for Data Action calls originating from CXone. My goal is to propagate the traceparent and tracestate headers from an incoming webhook into subsequent internal REST calls. I have successfully generated the context in my Node.js service and am passing it to the CXone Studio Snippet via a Data Action input variable named otel_context.
The issue arises when I try to parse this JSON string and assign the individual header values to flow variables for use in a GetRESTProxy call. Studio Snippets do not support native JSON parsing functions, so I am attempting to use string manipulation within ASSIGN actions. However, the logic seems to break when the payload contains special characters or when I try to conditionally branch based on the presence of the trace ID using an IF action.
Here is my current snippet logic structure:
ASSIGN traceData = $input.otel_context
IF traceData != "null"
ASSIGN traceParent = SUBSTR(traceData, 0, 55) // This is a hacky workaround
ASSIGN headers = {"traceparent": traceParent}
ELSE
ASSIGN headers = {}
END IF
// Later in the flow
ASSIGN response = GetRESTProxy("POST", "https://internal-api/ingest", headers, body)
The SUBSTR approach is unreliable because the JSON structure varies slightly between spans. I need a robust way to extract the traceparent value from the JSON string using only Studio Snippet actions. Is there a way to use a Data Action to parse the JSON before assigning it, or am I missing a native function that handles this in the GetRESTProxy context? The current implementation results in malformed headers, causing 400 Bad Request errors on the receiving end.