CXone Studio DBConnector: Context propagation fails when chaining with HTTP action

Trying to inject OpenTelemetry trace context into a CXone Studio script that hits our internal database via the DBConnector action. The goal is to correlate the DB lookup latency with the upstream Genesys Cloud interaction span.

We’ve got the DBConnector configured to call a stored procedure that accepts a trace_id parameter. I’m passing the trace ID from the incoming webhook context. The DB call works fine in isolation. The issue pops up when I chain it with an HTTP action to push the result to our OTel collector.

Here’s the snippet logic in the script:

{
 "action": "DBConnector",
 "params": {
 "connectionString": "conn_str_var",
 "commandText": "sp_get_customer_data",
 "parameters": [
 { "name": "@trace_id", "value": "{context.traceId}" }
 ]
 }
}

The DB returns the data. Then I try to send a JSON payload to our collector:

{
 "action": "HTTP",
 "method": "POST",
 "url": "{env.otel_collector_url}/api/v2/traces",
 "body": {
 "traceId": "{context.traceId}",
 "spanId": "{new_uuid()}",
 "parentSpanId": "{context.parentTraceId}",
 "db_latency_ms": "{db_connector.result.elapsed_time}"
 }
}

The HTTP action returns a 502 Bad Gateway. The payload looks valid. Checked the collector logs, it’s not receiving the request. Suspect the context.traceId variable is getting cleared or malformed after the DB action completes.

Is there a specific way to preserve custom context variables across DBConnector actions? Or does the DB action reset the context scope?

Also noticed the elapsed_time property isn’t documented in the standard DBConnector response schema. Just guessing at the field name based on similar actions. Might be why the JSON is malformed.

The DBConnector action in Studio doesn’t automatically pull headers from the previous HTTP action context. You have to manually map the trace ID.

Check your data flow. If the HTTP action returns the trace ID in the response body, you need to set a variable first.

{
 "actionType": "setVariable",
 "variableName": "otelTraceId",
 "value": "{{httpResponse.body.traceId}}"
}

Then pass that variable to the DBConnector parameter. Don’t try to chain the HTTP response directly into the DB input. It breaks the context scope.

I’ve seen this cause 500 errors when the DB expects a string but gets an object reference. Also, make sure your stored procedure isn’t truncating the trace ID. Genesys uses 32-character hex strings. If your DB column is VARCHAR(16), it’ll fail silently or corrupt the span.

Check the DB schema length. That’s usually the culprit when the connection works but the data doesn’t propagate correctly.