Trace Exporter
What is Trace Exporter
With the Trace Exporter feature, you can take full control of how to handle trace data collected by the Coralogix RUM Browser SDK. By configuring a tracesExporter callback, you can intercept batches of trace data, inspect or modify them, and decide if and where to forward them. This supports advanced use cases such as server-side filtering, enrichment, and tail-based sampling, where decisions are made after traces are collected rather than at capture time.
Why it matters
- Control trace volume by filtering or sampling traces before ingestion.
- Enrich trace data with business or environment context in your own backend.
- Implement tail-based sampling based on trace outcomes, such as errors or latency.
- Integrate with existing OpenTelemetry-compatible collectors running in your infrastructure.
How it works
When you configure tracesExporter, the SDK stops automatically exporting traces to Coralogix. Instead, it invokes your callback with a batch of trace data the SDK has collected since the previous callback invocation. Your callback becomes the single export pipeline and is responsible for forwarding any traces you want to keep.
Trace data is provided in OTLP/JSON format, which mirrors the official OpenTelemetry Protobuf schema for traces and is commonly used when OTLP is sent over HTTP.
What you need
- Coralogix RUM Browser SDK with tracing enabled
- An endpoint capable of receiving OTLP/JSON trace payloads (for example, your own backend or the Coralogix OTLP ingestion endpoint)
Configuration
Define the tracesExporter callback as a top-level property in CoralogixRum.init.
CoralogixRum.init({
tracesExporter:(data) => {
// Forward trace data to your backend or OTLP-compatible endpoint
}
});
Forwarding traces to Coralogix
After you include tracesExporter in your configuration, the SDK stops forwarding traces automatically. To send traces to Coralogix, manually forward the payload from within the callback.
If you forward the entire payload unchanged, all collected traces are sent as-is. You can also add conditional logic to filter, enrich, or reroute specific traces before forwarding.
Pass-through and selective handling
If you only want to intervene on a subset of traces, use a pass-through approach:
- Forward all trace batches to Coralogix by default
- Apply custom logic for specific traces or batches, such as dropping low-value traces or enriching error traces
This ensures you retain full trace visibility while still applying targeted processing.
Payload format
The callback receives a TraceExporterData object that follows the OpenTelemetry Collector trace format. At a high level, the payload includes resources, scopes, and spans grouped into batches.
{
"resource_spans": [
{
"resource": {
"attributes": [
{ "key": "service.name", "value": { "string_value": "my-service" } }
]
},
"scope_spans": [
{
"scope": { "name": "rum-sdk" },
"spans": [
{
"trace_id": "7f3a2c1e9b4d4f0a8c7d6e5f4a3b2c1d",
"span_id": "1a2b3c4d5e6f7081",
"name": "fetch-data",
"start_time_unix_nano": "1665753217736722000",
"end_time_unix_nano": "1665753217737156416"
}
]
}
]
}
]
}
User responsibility and limitations
When using tracesExporter, you assume responsibility for:
- Forwarding traces to Coralogix or another destination
- Error handling and retries for failed exports
- Performance considerations, ensuring the callback does not block the main thread
- Data loss prevention, as the SDK does not retry exports on your behalf
Important
Defining tracesExporter fully replaces the SDK’s default trace exporter. The SDK does not continue exporting traces automatically in parallel.