Skip to main content

Overview

@kubiks/otel-upstash-queues provides comprehensive OpenTelemetry instrumentation for Upstash QStash. Capture spans for both message publishing and consumption with detailed operation metadata and delivery tracking.
Upstash QStash Trace Visualization
Visualize your message queue operations with detailed span information including message publishing, callbacks, and delivery tracking—from producer to consumer.

Installation

Peer Dependencies: @opentelemetry/api >= 1.9.0, @upstash/qstash >= 2.0.0

Quick Start

Publishing Messages

instrumentUpstash wraps the QStash client instance you already use—no configuration changes needed. Every SDK call creates a client span with useful attributes.

Consuming Messages

instrumentConsumer wraps your message handler to trace message consumption, creating a SERVER span for each message received and processed.

What Gets Traced

This instrumentation provides two main functions:

instrumentUpstash

Wraps the QStash client to trace message publishing with SpanKind.CLIENT

instrumentConsumer

Wraps your message handler to trace message consumption with SpanKind.SERVER

Configuration

With Body Capture

Optionally capture request/response bodies for debugging:
Body capture is disabled by default to protect sensitive data. Only enable in secure, development environments.

Span Attributes

Publisher Spans (instrumentUpstash)

Consumer Spans (instrumentConsumer)

Body/Payload Attributes (Optional)

When captureBody is enabled:

Usage Examples

Basic Message Publishing

Delayed Message Publishing

Message with Callbacks

Retries and Deduplication

Message Consumer

Complete Integration Example

Here’s a complete example of QStash with OpenTelemetry in a Next.js application:

Setup

lib/qstash.ts

Publishing Messages

app/actions/tasks.ts

Consuming Messages

app/api/process/image/route.ts
app/api/process/report/route.ts

Callback Handlers

app/api/callbacks/report-success/route.ts
app/api/callbacks/report-failure/route.ts

Best Practices

Always verify QStash signatures to ensure messages are authentic:
Use deduplication IDs to prevent duplicate processing:
Set retry counts based on operation criticality:
Implement callbacks to track message processing:
Always handle errors in consumer handlers:

Advanced Patterns

Troubleshooting

Ensure OpenTelemetry is initialized before using QStash:
Make sure environment variables are set correctly:
Check that your endpoint is:
  • Publicly accessible
  • Returns 2xx status codes
  • Responds within timeout (default: 2 minutes)
  • Has signature verification enabled
Ensure instrumentConsumer is called before verifySignatureAppRouter:

Resources

QStash Documentation

Learn more about Upstash QStash

GitHub Repository

View source code and examples

npm Package

View package on npm

Report Issues

Found a bug? Let us know!

License

MIT