Create workflow spans
Use workflow spans to capture metrics (errors, page loads, and core web vitals) specific to your organization's use cases, such as understanding drop off rates during a checkout workflow.
Create workflow spans to capture meaningful metrics about customer journeys and user behavior on your site. Workflow spans support filtering by tags and the addition of custom attributes.
How workflow spans add value
Splunk RUM automatically collects metrics about page loads, errors, and core web vitals. Sometimes, you need custom logic to capture a specific workflow that is important to your organization to understand. Workflow spans provide the opportunity for you to see a unique perspective on your data driven by the questions that matter most to you.
For example, if you're an online retailer, you might want to understand behavior around conversion rates. You might also want to understand where users are getting stuck in your application. You can create a workflow span to discover which events precipitate an unsuccessful customer journey. Perhaps users are stopped by an error in your checkout workflow, or are unable to enter a promo code.
When you create a span with a workflow.name attribute, the span is visible on a browser application page's Custom Events tab. You can also perform some analysis on the workflow.
workflow.name attribute. If you didn't set this attribute, the span is still recorded but only appears in the request waterfall view.
The following examples show how to create a workflow span for browser, Android, and iOS applications.
Browser
First declare the tracer and then define the workflow span.
You can declare the tracer through either CDN or NPM. You need to declare the tracer only once. For more information on the difference between CDN and NPM, see Instrument your web application for Splunk RUM.
The following example shows how to initialize the tracer and create a workflow span using NPM:
import {trace} from '@opentelemetry/api'
const tracer = trace.getTracer('appModuleLoader');
const span = tracer.startSpan('test.module.load', {
attributes: {
'workflow.name': 'test.module.load'
}
});
// time passes
span.end();
Android
You can report workflow spans and workflows happening in your Android application using the addRumEvent and startWorkflow APIs.
The following example shows how to report when a user closes a help dialog box:
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = LayoutInflater.from(activity);
View alertView = inflater.inflate(R.layout.sample_mail_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setView(alertView)
.setNegativeButton(R.string.cancel, (dialog, id) ->
// Record a simple "zero duration" span with the provided name and attributes
SplunkRum.getInstance().addRumEvent("User Rejected Help", HELPER_ATTRIBUTES));
return builder.create();
}
The following example shows how to start a workflow for which metrics are recorded by Splunk RUM. To record the workflow you must end the OpenTelemetry span instance:
binding.buttonWork.setOnClickListener(v -> {
Span hardWorker =
SplunkRum.getInstance().startWorkflow("Main thread working hard");
try {
Random random = new Random();
long startTime = System.currentTimeMillis();
while (true) {
random.nextDouble();
if (System.currentTimeMillis() - startTime > 20_000) {
break;
}
}
} finally {
hardWorker.end();
}
});
iOS
The following example shows how to use the OTel Swift API to report on a function you want to time:
func calculateTax() {
let tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: "your-application-name")
let span = tracer.spanBuilder(spanName: "calculateTax").startSpan()
span.setAttribute(key: "numClaims", value: claims.count)
span.setAttribute(key: "workflow.name", value: "your-workflow-name") // This allows the event to appear in the UI
//...
//...
span.end() // You can also use defer for this
}
This example shows how to record an event with no duration:
let dictionary: NSDictionary = [
"attribute1": "hello",
"attribute2": "world!",
"attribute3": 3
]
SplunkRum.reportEvent(name: "testEvent", attributes: dictionary)
Next steps
For examples, dashboards, and metrics related to workflow spans, see the following topics:
Advanced instrumentation
For more information on advanced instrumentation, see the following topics: