Skip to main content

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.
Upstash Workflow Trace Visualization
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.0

Quick 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.CLIENT

instrumentWorkflowServe

Wraps the serve function to trace execution and all workflow steps with SpanKind.SERVER

Workflow Handler Instrumentation

The instrumentWorkflowServe 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

The instrumentWorkflowClient 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:
Separate client-side triggers create independent traces:

Span Attributes

Workflow Handler Spans (instrumentWorkflowServe)

Client Trigger Spans (instrumentWorkflowClient)

Step Spans (context.run)

Sleep Spans (context.sleep, context.sleepFor, context.sleepUntil)

Call Spans (context.call)

Event Spans (context.waitForEvent)

Step Data Attributes (Optional)

When captureStepData is enabled:
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

Use descriptive step names to make traces easier to understand:
Name sleep operations to understand workflow timing:
Only enable step data capture in development or when data doesn’t contain sensitive information:
Implement proper error handling within workflow steps:

Troubleshooting

Ensure OpenTelemetry is initialized before using workflows:
Make sure required environment variables are set:
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!

License

MIT