Overview
@kubiks/otel-upstash-workflow provides comprehensive OpenTelemetry instrumentation for the Upstash Workflow SDK. Capture spans for workflow executions, steps, sleep operations, API calls, and event waiting with detailed performance metrics.

Visualize your workflow executions with detailed span information including steps, sleep operations, API calls, and performance metrics.
Pre-release Note: This package instruments the Upstash Workflow SDK, which is currently in pre-release. The API may change as the Workflow SDK evolves.
Installation
Peer Dependencies:
@opentelemetry/api >= 1.9.0, @upstash/workflow >= 0.0.0Quick Start
Instrumenting Workflow Handlers
instrumentWorkflowServe wraps the serve function to trace the entire workflow execution and all steps—no configuration changes needed. Every workflow execution creates a server span with child spans for each step.Instrumenting Workflow Client
instrumentWorkflowClient wraps the workflow client to trace workflow triggers, creating client spans for each trigger operation.Configuration
With Step Data Capture
Optionally capture step inputs and outputs for debugging:Step data capture is disabled by default to protect sensitive data. Only enable in secure, development environments.
What Gets Traced
This instrumentation provides two main functions:instrumentWorkflowClient
Wraps the Workflow Client to trace workflow triggers with
SpanKind.CLIENTinstrumentWorkflowServe
Wraps the serve function to trace execution and all workflow steps with
SpanKind.SERVERWorkflow Handler Instrumentation
TheinstrumentWorkflowServe function wraps the serve function, creating a span with SpanKind.SERVER for the entire workflow execution. All workflow steps (context.run, context.sleep, etc.) automatically create child spans.
Client Instrumentation
TheinstrumentWorkflowClient function wraps the client’s trigger method, creating a span with SpanKind.CLIENT for each workflow trigger operation.
Span Hierarchy
The instrumentation creates the following span hierarchy:Span Attributes
Workflow Handler Spans (instrumentWorkflowServe)
| Attribute | Description | Example |
|---|---|---|
workflow.system | Constant value upstash | upstash |
workflow.operation | Operation type | execute |
workflow.id | Workflow ID from headers | wf_123 |
workflow.run_id | Workflow run ID from headers | run_456 |
workflow.url | Workflow URL from headers | https://example.com/api/workflow |
http.status_code | HTTP response status | 200 |
Client Trigger Spans (instrumentWorkflowClient)
| Attribute | Description | Example |
|---|---|---|
workflow.system | Constant value upstash | upstash |
workflow.operation | Operation type | trigger |
workflow.url | Target workflow URL | https://example.com/api/workflow |
workflow.id | Workflow ID from response | wf_123 |
workflow.run_id | Workflow run ID from response | run_456 |
Step Spans (context.run)
| Attribute | Description | Example |
|---|---|---|
workflow.system | Constant value upstash | upstash |
workflow.operation | Operation type | step |
workflow.step.name | Step name | step-1 |
workflow.step.type | Step type | run |
workflow.step.duration_ms | Step execution time in ms | 150 |
workflow.step.output | Step output (if enabled) | {"result":"success"} |
Sleep Spans (context.sleep, context.sleepFor, context.sleepUntil)
| Attribute | Description | Example |
|---|---|---|
workflow.system | Constant value upstash | upstash |
workflow.operation | Operation type | step |
workflow.step.name | Step name (if named sleep) | wait-5s |
workflow.step.type | Step type | sleep |
workflow.sleep.duration_ms | Sleep duration in ms | 5000 |
workflow.sleep.until_timestamp | Target timestamp (sleepUntil) | 1704067200000 |
Call Spans (context.call)
| Attribute | Description | Example |
|---|---|---|
workflow.system | Constant value upstash | upstash |
workflow.operation | Operation type | step |
workflow.step.name | Step name | api-call |
workflow.step.type | Step type | call |
workflow.call.url | Target URL | https://api.example.com/data |
workflow.call.method | HTTP method | POST |
workflow.call.status_code | Response status code | 200 |
workflow.step.input | Request body (if enabled) | {"userId":"123"} |
workflow.step.output | Response data (if enabled) | {"status":"ok"} |
Event Spans (context.waitForEvent)
| Attribute | Description | Example |
|---|---|---|
workflow.system | Constant value upstash | upstash |
workflow.operation | Operation type | step |
workflow.step.name | Step name | wait-event |
workflow.step.type | Step type | waitForEvent |
workflow.event.id | Event ID | evt_123 |
workflow.event.timeout_ms | Timeout in ms | 60000 |
workflow.step.output | Event data (if enabled) | {"received":true} |
Step Data Attributes (Optional)
WhencaptureStepData is enabled:
| Attribute | Description | Captured By |
|---|---|---|
workflow.step.input | Step input data | Client trigger, context.call |
workflow.step.output | Step output data | All context methods |
The instrumentation captures workflow metadata and step details to help with debugging and monitoring. Step data capture is disabled by default to protect sensitive data.
Usage Examples
Basic Workflow Execution
Workflow with Sleep
Workflow with External API Calls
Workflow with Event Waiting
Client Triggering Workflows
With Step Data Capture
Complete Next.js Integration Example
Workflow Handler
app/api/workflow/route.ts
Triggering Workflows
app/actions.ts
Configuration Options
Best Practices
Name Your Steps Meaningfully
Name Your Steps Meaningfully
Use descriptive step names to make traces easier to understand:
Use Named Sleeps for Clarity
Use Named Sleeps for Clarity
Name sleep operations to understand workflow timing:
Limit Step Data Capture
Limit Step Data Capture
Only enable step data capture in development or when data doesn’t contain sensitive information:
Handle Errors in Steps
Handle Errors in Steps
Implement proper error handling within workflow steps:
Troubleshooting
Spans Not Appearing
Spans Not Appearing
Ensure OpenTelemetry is initialized before using workflows:
Missing Environment Variables
Missing Environment Variables
Make sure required environment variables are set:
Workflow Not Executing
Workflow Not Executing
Check that your endpoint is:
- Publicly accessible
- Returns 2xx status codes
- Properly configured with Upstash Workflow
Resources
Upstash Workflow Documentation
Learn more about Upstash Workflow
GitHub Repository
View source code and examples
npm Package
View package on npm
Report Issues
Found a bug? Let us know!