@saga-bus/middleware-tracing 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Dean Foran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @saga-bus/middleware-tracing
2
+
3
+ OpenTelemetry distributed tracing middleware for saga-bus.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @saga-bus/middleware-tracing @opentelemetry/api
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { createTracingMiddleware } from "@saga-bus/middleware-tracing";
15
+ import { createBus } from "@saga-bus/core";
16
+ import { trace } from "@opentelemetry/api";
17
+
18
+ const tracingMiddleware = createTracingMiddleware({
19
+ tracer: trace.getTracer("my-service"),
20
+ });
21
+
22
+ const bus = createBus({
23
+ middleware: [tracingMiddleware],
24
+ sagas: [...],
25
+ transport,
26
+ });
27
+ ```
28
+
29
+ ## Features
30
+
31
+ - Automatic span creation for message processing
32
+ - W3C Trace Context propagation (traceparent/tracestate headers)
33
+ - Span attributes for message type, saga ID, correlation ID
34
+ - Error recording on handler failures
35
+ - Optional payload recording
36
+
37
+ ## Trace Context Propagation
38
+
39
+ The middleware automatically propagates trace context across service boundaries:
40
+
41
+ ```typescript
42
+ import { createPublishTracer } from "@saga-bus/middleware-tracing";
43
+
44
+ const publishWithTracing = createPublishTracer(bus, {
45
+ tracer: trace.getTracer("my-service"),
46
+ });
47
+
48
+ // Automatically injects traceparent/tracestate headers
49
+ await publishWithTracing({
50
+ type: "OrderCreated",
51
+ payload: { orderId: "123" },
52
+ });
53
+ ```
54
+
55
+ ## Span Attributes
56
+
57
+ Each message processing span includes:
58
+
59
+ | Attribute | Description |
60
+ |-----------|-------------|
61
+ | `messaging.system` | `"saga-bus"` |
62
+ | `messaging.operation` | `"process"` |
63
+ | `messaging.message.type` | Message type |
64
+ | `saga.name` | Saga name |
65
+ | `saga.id` | Saga instance ID |
66
+ | `messaging.message.correlation_id` | Correlation ID |
67
+
68
+ ## Configuration
69
+
70
+ | Option | Type | Default | Description |
71
+ |--------|------|---------|-------------|
72
+ | `tracer` | `Tracer` | global | OpenTelemetry tracer |
73
+ | `tracerName` | `string` | `"@saga-bus/middleware-tracing"` | Tracer name |
74
+ | `recordPayload` | `boolean` | `false` | Record payload as attribute |
75
+ | `maxPayloadSize` | `number` | `1024` | Max payload size to record |
76
+ | `attributeExtractor` | `function` | - | Custom attribute extractor |
77
+
78
+ ## Custom Attributes
79
+
80
+ ```typescript
81
+ createTracingMiddleware({
82
+ attributeExtractor: (envelope) => ({
83
+ "custom.order_id": envelope.payload?.orderId,
84
+ "custom.priority": envelope.payload?.priority,
85
+ }),
86
+ });
87
+ ```
88
+
89
+ ## License
90
+
91
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createPublishTracer: () => createPublishTracer,
24
+ createTracingMiddleware: () => createTracingMiddleware
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/TracingMiddleware.ts
29
+ var import_api = require("@opentelemetry/api");
30
+ var TRACER_NAME = "@saga-bus/middleware-tracing";
31
+ function createTracingMiddleware(options = {}) {
32
+ const tracer = options.tracer ?? import_api.trace.getTracer(options.tracerName ?? TRACER_NAME);
33
+ const recordPayload = options.recordPayload ?? false;
34
+ const maxPayloadSize = options.maxPayloadSize ?? 1024;
35
+ const attributeExtractor = options.attributeExtractor;
36
+ return async (ctx, next) => {
37
+ const { envelope } = ctx;
38
+ let parentContext = import_api.context.active();
39
+ const existingState = ctx.existingState;
40
+ if (existingState?.metadata?.traceParent) {
41
+ const carrier = {
42
+ traceparent: existingState.metadata.traceParent,
43
+ tracestate: existingState.metadata.traceState ?? void 0
44
+ };
45
+ parentContext = import_api.propagation.extract(import_api.context.active(), carrier);
46
+ } else if (envelope.headers?.traceparent) {
47
+ parentContext = extractContext(envelope);
48
+ }
49
+ const spanName = `saga-bus.handle ${envelope.type}`;
50
+ const span = tracer.startSpan(
51
+ spanName,
52
+ {
53
+ kind: import_api.SpanKind.CONSUMER,
54
+ attributes: buildAttributes(envelope, recordPayload, maxPayloadSize)
55
+ },
56
+ parentContext
57
+ );
58
+ if (attributeExtractor) {
59
+ try {
60
+ const customAttrs = attributeExtractor(envelope);
61
+ span.setAttributes(customAttrs);
62
+ } catch {
63
+ }
64
+ }
65
+ span.setAttribute("saga.name", ctx.sagaName);
66
+ if (ctx.sagaId) {
67
+ span.setAttribute("saga.id", ctx.sagaId);
68
+ }
69
+ span.setAttribute("saga.correlation_id", ctx.correlationId);
70
+ span.setAttribute("saga.is_new", !existingState);
71
+ if (!existingState || !existingState.metadata?.traceParent) {
72
+ const carrier = {};
73
+ import_api.propagation.inject(import_api.trace.setSpan(import_api.context.active(), span), carrier);
74
+ if (carrier.traceparent) {
75
+ ctx.setTraceContext(carrier.traceparent, carrier.tracestate ?? null);
76
+ }
77
+ }
78
+ try {
79
+ await import_api.context.with(import_api.trace.setSpan(import_api.context.active(), span), async () => {
80
+ await next();
81
+ });
82
+ span.setStatus({ code: import_api.SpanStatusCode.OK });
83
+ } catch (error) {
84
+ span.setStatus({
85
+ code: import_api.SpanStatusCode.ERROR,
86
+ message: error instanceof Error ? error.message : String(error)
87
+ });
88
+ span.recordException(error);
89
+ throw error;
90
+ } finally {
91
+ span.end();
92
+ }
93
+ };
94
+ }
95
+ function createPublishTracer(options = {}) {
96
+ const tracer = options.tracer ?? import_api.trace.getTracer(options.tracerName ?? TRACER_NAME);
97
+ return (envelope) => {
98
+ const span = tracer.startSpan(`saga-bus.publish ${envelope.type}`, {
99
+ kind: import_api.SpanKind.PRODUCER,
100
+ attributes: {
101
+ "messaging.system": "saga-bus",
102
+ "messaging.operation": "publish",
103
+ "messaging.message.id": envelope.id,
104
+ "messaging.message.type": envelope.type
105
+ }
106
+ });
107
+ const traceHeaders = {};
108
+ import_api.propagation.inject(import_api.trace.setSpan(import_api.context.active(), span), traceHeaders);
109
+ span.end();
110
+ return {
111
+ ...envelope,
112
+ headers: {
113
+ ...envelope.headers,
114
+ ...traceHeaders.traceparent && { traceparent: traceHeaders.traceparent },
115
+ ...traceHeaders.tracestate && { tracestate: traceHeaders.tracestate }
116
+ }
117
+ };
118
+ };
119
+ }
120
+ function extractContext(envelope) {
121
+ const headers = envelope.headers;
122
+ if (!headers.traceparent) {
123
+ return import_api.context.active();
124
+ }
125
+ return import_api.propagation.extract(import_api.context.active(), headers);
126
+ }
127
+ function buildAttributes(envelope, recordPayload, maxPayloadSize) {
128
+ const attrs = {
129
+ "messaging.system": "saga-bus",
130
+ "messaging.operation": "process",
131
+ "messaging.message.id": envelope.id,
132
+ "messaging.message.type": envelope.type
133
+ };
134
+ if (envelope.partitionKey) {
135
+ attrs["messaging.message.partition_key"] = envelope.partitionKey;
136
+ }
137
+ if (recordPayload && envelope.payload !== void 0) {
138
+ const payloadStr = JSON.stringify(envelope.payload);
139
+ if (payloadStr.length <= maxPayloadSize) {
140
+ attrs["messaging.message.payload"] = payloadStr;
141
+ } else {
142
+ attrs["messaging.message.payload"] = payloadStr.slice(0, maxPayloadSize) + "...";
143
+ attrs["messaging.message.payload_truncated"] = true;
144
+ }
145
+ }
146
+ return attrs;
147
+ }
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ createPublishTracer,
151
+ createTracingMiddleware
152
+ });
153
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/TracingMiddleware.ts"],"sourcesContent":["export {\n createTracingMiddleware,\n createPublishTracer,\n} from \"./TracingMiddleware.js\";\nexport type {\n TracingMiddlewareOptions,\n TraceContextHeaders,\n} from \"./types.js\";\n","import {\n trace,\n context,\n SpanKind,\n SpanStatusCode,\n propagation,\n type Context,\n type Attributes,\n} from \"@opentelemetry/api\";\nimport type {\n SagaMiddleware,\n SagaPipelineContext,\n MessageEnvelope,\n} from \"@saga-bus/core\";\nimport type { TracingMiddlewareOptions, TraceContextHeaders } from \"./types.js\";\n\nconst TRACER_NAME = \"@saga-bus/middleware-tracing\";\n\n/**\n * OpenTelemetry tracing middleware for saga-bus.\n *\n * Creates spans for message handling with proper context propagation\n * for distributed tracing across services. Supports saga-correlated tracing\n * where all messages for the same saga instance share the same trace.\n *\n * @example\n * ```typescript\n * import { trace } from \"@opentelemetry/api\";\n * import { createTracingMiddleware } from \"@saga-bus/middleware-tracing\";\n *\n * const middleware = createTracingMiddleware({\n * tracer: trace.getTracer(\"my-service\"),\n * });\n *\n * const bus = createMessageBus({\n * middleware: [middleware],\n * });\n * ```\n */\nexport function createTracingMiddleware(\n options: TracingMiddlewareOptions = {}\n): SagaMiddleware {\n const tracer =\n options.tracer ?? trace.getTracer(options.tracerName ?? TRACER_NAME);\n const recordPayload = options.recordPayload ?? false;\n const maxPayloadSize = options.maxPayloadSize ?? 1024;\n const attributeExtractor = options.attributeExtractor;\n\n return async (ctx: SagaPipelineContext, next: () => Promise<void>) => {\n const { envelope } = ctx;\n\n // Determine parent context:\n // 1. First check if saga state has stored trace context (for saga correlation)\n // 2. Fall back to message headers (for standard distributed tracing)\n // 3. Fall back to active context\n let parentContext = context.active();\n\n // Check existing saga state for stored trace context\n const existingState = ctx.existingState;\n if (existingState?.metadata?.traceParent) {\n // Use saga's stored trace context for correlation\n const carrier: TraceContextHeaders = {\n traceparent: existingState.metadata.traceParent,\n tracestate: existingState.metadata.traceState ?? undefined,\n };\n parentContext = propagation.extract(context.active(), carrier);\n } else if (envelope.headers?.traceparent) {\n // Use message header trace context\n parentContext = extractContext(envelope);\n }\n\n // Start span with parent context\n const spanName = `saga-bus.handle ${envelope.type}`;\n const span = tracer.startSpan(\n spanName,\n {\n kind: SpanKind.CONSUMER,\n attributes: buildAttributes(envelope, recordPayload, maxPayloadSize),\n },\n parentContext\n );\n\n // Add custom attributes\n if (attributeExtractor) {\n try {\n const customAttrs = attributeExtractor(envelope);\n span.setAttributes(customAttrs);\n } catch {\n // Ignore extractor errors\n }\n }\n\n // Add saga attributes\n span.setAttribute(\"saga.name\", ctx.sagaName);\n if (ctx.sagaId) {\n span.setAttribute(\"saga.id\", ctx.sagaId);\n }\n span.setAttribute(\"saga.correlation_id\", ctx.correlationId);\n span.setAttribute(\"saga.is_new\", !existingState);\n\n // If this is a new saga or saga has no trace context, store the current trace context\n // so subsequent messages can be correlated\n if (!existingState || !existingState.metadata?.traceParent) {\n const carrier: TraceContextHeaders = {};\n propagation.inject(trace.setSpan(context.active(), span), carrier);\n if (carrier.traceparent) {\n // Store trace context in pipeline context for orchestrator to persist\n ctx.setTraceContext(carrier.traceparent, carrier.tracestate ?? null);\n }\n }\n\n try {\n // Run next middleware within span context\n await context.with(trace.setSpan(context.active(), span), async () => {\n await next();\n });\n\n span.setStatus({ code: SpanStatusCode.OK });\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error instanceof Error ? error.message : String(error),\n });\n span.recordException(error as Error);\n throw error;\n } finally {\n span.end();\n }\n };\n}\n\n/**\n * Create a publish interceptor that adds tracing to outbound messages.\n *\n * @example\n * ```typescript\n * const tracer = createPublishTracer({\n * tracer: trace.getTracer(\"my-service\"),\n * });\n *\n * // Before publishing, wrap the envelope\n * const tracedEnvelope = tracer(envelope);\n * await transport.publish(tracedEnvelope.payload, options);\n * ```\n */\nexport function createPublishTracer(\n options: TracingMiddlewareOptions = {}\n): (envelope: MessageEnvelope) => MessageEnvelope {\n const tracer =\n options.tracer ?? trace.getTracer(options.tracerName ?? TRACER_NAME);\n\n return (envelope: MessageEnvelope): MessageEnvelope => {\n const span = tracer.startSpan(`saga-bus.publish ${envelope.type}`, {\n kind: SpanKind.PRODUCER,\n attributes: {\n \"messaging.system\": \"saga-bus\",\n \"messaging.operation\": \"publish\",\n \"messaging.message.id\": envelope.id,\n \"messaging.message.type\": envelope.type,\n },\n });\n\n // Inject trace context into message headers\n const traceHeaders: TraceContextHeaders = {};\n propagation.inject(trace.setSpan(context.active(), span), traceHeaders);\n\n span.end();\n\n // Return envelope with trace headers merged into existing headers\n return {\n ...envelope,\n headers: {\n ...envelope.headers,\n ...(traceHeaders.traceparent && { traceparent: traceHeaders.traceparent }),\n ...(traceHeaders.tracestate && { tracestate: traceHeaders.tracestate }),\n },\n };\n };\n}\n\n/**\n * Extract trace context from message headers.\n */\nfunction extractContext(envelope: MessageEnvelope): Context {\n const headers = envelope.headers;\n\n if (!headers.traceparent) {\n return context.active();\n }\n\n return propagation.extract(context.active(), headers);\n}\n\n/**\n * Build standard span attributes from message envelope.\n */\nfunction buildAttributes(\n envelope: MessageEnvelope,\n recordPayload: boolean,\n maxPayloadSize: number\n): Attributes {\n const attrs: Attributes = {\n \"messaging.system\": \"saga-bus\",\n \"messaging.operation\": \"process\",\n \"messaging.message.id\": envelope.id,\n \"messaging.message.type\": envelope.type,\n };\n\n if (envelope.partitionKey) {\n attrs[\"messaging.message.partition_key\"] = envelope.partitionKey;\n }\n\n if (recordPayload && envelope.payload !== undefined) {\n const payloadStr = JSON.stringify(envelope.payload);\n if (payloadStr.length <= maxPayloadSize) {\n attrs[\"messaging.message.payload\"] = payloadStr;\n } else {\n attrs[\"messaging.message.payload\"] =\n payloadStr.slice(0, maxPayloadSize) + \"...\";\n attrs[\"messaging.message.payload_truncated\"] = true;\n }\n }\n\n return attrs;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAQO;AAQP,IAAM,cAAc;AAuBb,SAAS,wBACd,UAAoC,CAAC,GACrB;AAChB,QAAM,SACJ,QAAQ,UAAU,iBAAM,UAAU,QAAQ,cAAc,WAAW;AACrE,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,iBAAiB,QAAQ,kBAAkB;AACjD,QAAM,qBAAqB,QAAQ;AAEnC,SAAO,OAAO,KAA0B,SAA8B;AACpE,UAAM,EAAE,SAAS,IAAI;AAMrB,QAAI,gBAAgB,mBAAQ,O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AAS;AAAA,EACrC;AAEA,MAAI,SAAS,cAAc;AACzB,UAAM,iCAAiC,IAAI,SAAS;AAAA,EACtD;AAEA,MAAI,iBAAiB,SAAS,YAAY,QAAW;AACnD,UAAM,aAAa,KAAK,UAAU,SAAS,OAAO;AAClD,QAAI,WAAW,UAAU,gBAAgB;AACvC,YAAM,2BAA2B,IAAI;AAAA,IACvC,OAAO;AACL,YAAM,2BAA2B,IAC/B,WAAW,MAAM,GAAG,cAAc,IAAI;AACxC,YAAM,qCAAqC,IAAI;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,81 @@
1
+ import { MessageEnvelope, SagaMiddleware } from '@saga-bus/core';
2
+ import { Tracer, Attributes } from '@opentelemetry/api';
3
+
4
+ /**
5
+ * Tracing middleware configuration options.
6
+ */
7
+ interface TracingMiddlewareOptions {
8
+ /**
9
+ * OpenTelemetry tracer instance.
10
+ * If not provided, uses the global tracer.
11
+ */
12
+ tracer?: Tracer;
13
+ /**
14
+ * Tracer name when creating from global provider.
15
+ * @default "@saga-bus/middleware-tracing"
16
+ */
17
+ tracerName?: string;
18
+ /**
19
+ * Whether to record message payloads as span attributes.
20
+ * May expose sensitive data - use with caution.
21
+ * @default false
22
+ */
23
+ recordPayload?: boolean;
24
+ /**
25
+ * Maximum payload size to record (bytes).
26
+ * @default 1024
27
+ */
28
+ maxPayloadSize?: number;
29
+ /**
30
+ * Custom attribute extractor.
31
+ * Called for each message to add custom attributes.
32
+ */
33
+ attributeExtractor?: (envelope: MessageEnvelope) => Attributes;
34
+ }
35
+ /**
36
+ * Trace context propagation headers.
37
+ */
38
+ interface TraceContextHeaders {
39
+ traceparent?: string;
40
+ tracestate?: string;
41
+ }
42
+
43
+ /**
44
+ * OpenTelemetry tracing middleware for saga-bus.
45
+ *
46
+ * Creates spans for message handling with proper context propagation
47
+ * for distributed tracing across services. Supports saga-correlated tracing
48
+ * where all messages for the same saga instance share the same trace.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { trace } from "@opentelemetry/api";
53
+ * import { createTracingMiddleware } from "@saga-bus/middleware-tracing";
54
+ *
55
+ * const middleware = createTracingMiddleware({
56
+ * tracer: trace.getTracer("my-service"),
57
+ * });
58
+ *
59
+ * const bus = createMessageBus({
60
+ * middleware: [middleware],
61
+ * });
62
+ * ```
63
+ */
64
+ declare function createTracingMiddleware(options?: TracingMiddlewareOptions): SagaMiddleware;
65
+ /**
66
+ * Create a publish interceptor that adds tracing to outbound messages.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const tracer = createPublishTracer({
71
+ * tracer: trace.getTracer("my-service"),
72
+ * });
73
+ *
74
+ * // Before publishing, wrap the envelope
75
+ * const tracedEnvelope = tracer(envelope);
76
+ * await transport.publish(tracedEnvelope.payload, options);
77
+ * ```
78
+ */
79
+ declare function createPublishTracer(options?: TracingMiddlewareOptions): (envelope: MessageEnvelope) => MessageEnvelope;
80
+
81
+ export { type TraceContextHeaders, type TracingMiddlewareOptions, createPublishTracer, createTracingMiddleware };
@@ -0,0 +1,81 @@
1
+ import { MessageEnvelope, SagaMiddleware } from '@saga-bus/core';
2
+ import { Tracer, Attributes } from '@opentelemetry/api';
3
+
4
+ /**
5
+ * Tracing middleware configuration options.
6
+ */
7
+ interface TracingMiddlewareOptions {
8
+ /**
9
+ * OpenTelemetry tracer instance.
10
+ * If not provided, uses the global tracer.
11
+ */
12
+ tracer?: Tracer;
13
+ /**
14
+ * Tracer name when creating from global provider.
15
+ * @default "@saga-bus/middleware-tracing"
16
+ */
17
+ tracerName?: string;
18
+ /**
19
+ * Whether to record message payloads as span attributes.
20
+ * May expose sensitive data - use with caution.
21
+ * @default false
22
+ */
23
+ recordPayload?: boolean;
24
+ /**
25
+ * Maximum payload size to record (bytes).
26
+ * @default 1024
27
+ */
28
+ maxPayloadSize?: number;
29
+ /**
30
+ * Custom attribute extractor.
31
+ * Called for each message to add custom attributes.
32
+ */
33
+ attributeExtractor?: (envelope: MessageEnvelope) => Attributes;
34
+ }
35
+ /**
36
+ * Trace context propagation headers.
37
+ */
38
+ interface TraceContextHeaders {
39
+ traceparent?: string;
40
+ tracestate?: string;
41
+ }
42
+
43
+ /**
44
+ * OpenTelemetry tracing middleware for saga-bus.
45
+ *
46
+ * Creates spans for message handling with proper context propagation
47
+ * for distributed tracing across services. Supports saga-correlated tracing
48
+ * where all messages for the same saga instance share the same trace.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { trace } from "@opentelemetry/api";
53
+ * import { createTracingMiddleware } from "@saga-bus/middleware-tracing";
54
+ *
55
+ * const middleware = createTracingMiddleware({
56
+ * tracer: trace.getTracer("my-service"),
57
+ * });
58
+ *
59
+ * const bus = createMessageBus({
60
+ * middleware: [middleware],
61
+ * });
62
+ * ```
63
+ */
64
+ declare function createTracingMiddleware(options?: TracingMiddlewareOptions): SagaMiddleware;
65
+ /**
66
+ * Create a publish interceptor that adds tracing to outbound messages.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const tracer = createPublishTracer({
71
+ * tracer: trace.getTracer("my-service"),
72
+ * });
73
+ *
74
+ * // Before publishing, wrap the envelope
75
+ * const tracedEnvelope = tracer(envelope);
76
+ * await transport.publish(tracedEnvelope.payload, options);
77
+ * ```
78
+ */
79
+ declare function createPublishTracer(options?: TracingMiddlewareOptions): (envelope: MessageEnvelope) => MessageEnvelope;
80
+
81
+ export { type TraceContextHeaders, type TracingMiddlewareOptions, createPublishTracer, createTracingMiddleware };
package/dist/index.js ADDED
@@ -0,0 +1,131 @@
1
+ // src/TracingMiddleware.ts
2
+ import {
3
+ trace,
4
+ context,
5
+ SpanKind,
6
+ SpanStatusCode,
7
+ propagation
8
+ } from "@opentelemetry/api";
9
+ var TRACER_NAME = "@saga-bus/middleware-tracing";
10
+ function createTracingMiddleware(options = {}) {
11
+ const tracer = options.tracer ?? trace.getTracer(options.tracerName ?? TRACER_NAME);
12
+ const recordPayload = options.recordPayload ?? false;
13
+ const maxPayloadSize = options.maxPayloadSize ?? 1024;
14
+ const attributeExtractor = options.attributeExtractor;
15
+ return async (ctx, next) => {
16
+ const { envelope } = ctx;
17
+ let parentContext = context.active();
18
+ const existingState = ctx.existingState;
19
+ if (existingState?.metadata?.traceParent) {
20
+ const carrier = {
21
+ traceparent: existingState.metadata.traceParent,
22
+ tracestate: existingState.metadata.traceState ?? void 0
23
+ };
24
+ parentContext = propagation.extract(context.active(), carrier);
25
+ } else if (envelope.headers?.traceparent) {
26
+ parentContext = extractContext(envelope);
27
+ }
28
+ const spanName = `saga-bus.handle ${envelope.type}`;
29
+ const span = tracer.startSpan(
30
+ spanName,
31
+ {
32
+ kind: SpanKind.CONSUMER,
33
+ attributes: buildAttributes(envelope, recordPayload, maxPayloadSize)
34
+ },
35
+ parentContext
36
+ );
37
+ if (attributeExtractor) {
38
+ try {
39
+ const customAttrs = attributeExtractor(envelope);
40
+ span.setAttributes(customAttrs);
41
+ } catch {
42
+ }
43
+ }
44
+ span.setAttribute("saga.name", ctx.sagaName);
45
+ if (ctx.sagaId) {
46
+ span.setAttribute("saga.id", ctx.sagaId);
47
+ }
48
+ span.setAttribute("saga.correlation_id", ctx.correlationId);
49
+ span.setAttribute("saga.is_new", !existingState);
50
+ if (!existingState || !existingState.metadata?.traceParent) {
51
+ const carrier = {};
52
+ propagation.inject(trace.setSpan(context.active(), span), carrier);
53
+ if (carrier.traceparent) {
54
+ ctx.setTraceContext(carrier.traceparent, carrier.tracestate ?? null);
55
+ }
56
+ }
57
+ try {
58
+ await context.with(trace.setSpan(context.active(), span), async () => {
59
+ await next();
60
+ });
61
+ span.setStatus({ code: SpanStatusCode.OK });
62
+ } catch (error) {
63
+ span.setStatus({
64
+ code: SpanStatusCode.ERROR,
65
+ message: error instanceof Error ? error.message : String(error)
66
+ });
67
+ span.recordException(error);
68
+ throw error;
69
+ } finally {
70
+ span.end();
71
+ }
72
+ };
73
+ }
74
+ function createPublishTracer(options = {}) {
75
+ const tracer = options.tracer ?? trace.getTracer(options.tracerName ?? TRACER_NAME);
76
+ return (envelope) => {
77
+ const span = tracer.startSpan(`saga-bus.publish ${envelope.type}`, {
78
+ kind: SpanKind.PRODUCER,
79
+ attributes: {
80
+ "messaging.system": "saga-bus",
81
+ "messaging.operation": "publish",
82
+ "messaging.message.id": envelope.id,
83
+ "messaging.message.type": envelope.type
84
+ }
85
+ });
86
+ const traceHeaders = {};
87
+ propagation.inject(trace.setSpan(context.active(), span), traceHeaders);
88
+ span.end();
89
+ return {
90
+ ...envelope,
91
+ headers: {
92
+ ...envelope.headers,
93
+ ...traceHeaders.traceparent && { traceparent: traceHeaders.traceparent },
94
+ ...traceHeaders.tracestate && { tracestate: traceHeaders.tracestate }
95
+ }
96
+ };
97
+ };
98
+ }
99
+ function extractContext(envelope) {
100
+ const headers = envelope.headers;
101
+ if (!headers.traceparent) {
102
+ return context.active();
103
+ }
104
+ return propagation.extract(context.active(), headers);
105
+ }
106
+ function buildAttributes(envelope, recordPayload, maxPayloadSize) {
107
+ const attrs = {
108
+ "messaging.system": "saga-bus",
109
+ "messaging.operation": "process",
110
+ "messaging.message.id": envelope.id,
111
+ "messaging.message.type": envelope.type
112
+ };
113
+ if (envelope.partitionKey) {
114
+ attrs["messaging.message.partition_key"] = envelope.partitionKey;
115
+ }
116
+ if (recordPayload && envelope.payload !== void 0) {
117
+ const payloadStr = JSON.stringify(envelope.payload);
118
+ if (payloadStr.length <= maxPayloadSize) {
119
+ attrs["messaging.message.payload"] = payloadStr;
120
+ } else {
121
+ attrs["messaging.message.payload"] = payloadStr.slice(0, maxPayloadSize) + "...";
122
+ attrs["messaging.message.payload_truncated"] = true;
123
+ }
124
+ }
125
+ return attrs;
126
+ }
127
+ export {
128
+ createPublishTracer,
129
+ createTracingMiddleware
130
+ };
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/TracingMiddleware.ts"],"sourcesContent":["import {\n trace,\n context,\n SpanKind,\n SpanStatusCode,\n propagation,\n type Context,\n type Attributes,\n} from \"@opentelemetry/api\";\nimport type {\n SagaMiddleware,\n SagaPipelineContext,\n MessageEnvelope,\n} from \"@saga-bus/core\";\nimport type { TracingMiddlewareOptions, TraceContextHeaders } from \"./types.js\";\n\nconst TRACER_NAME = \"@saga-bus/middleware-tracing\";\n\n/**\n * OpenTelemetry tracing middleware for saga-bus.\n *\n * Creates spans for message handling with proper context propagation\n * for distributed tracing across services. Supports saga-correlated tracing\n * where all messages for the same saga instance share the same trace.\n *\n * @example\n * ```typescript\n * import { trace } from \"@opentelemetry/api\";\n * import { createTracingMiddleware } from \"@saga-bus/middleware-tracing\";\n *\n * const middleware = createTracingMiddleware({\n * tracer: trace.getTracer(\"my-service\"),\n * });\n *\n * const bus = createMessageBus({\n * middleware: [middleware],\n * });\n * ```\n */\nexport function createTracingMiddleware(\n options: TracingMiddlewareOptions = {}\n): SagaMiddleware {\n const tracer =\n options.tracer ?? trace.getTracer(options.tracerName ?? TRACER_NAME);\n const recordPayload = options.recordPayload ?? false;\n const maxPayloadSize = options.maxPayloadSize ?? 1024;\n const attributeExtractor = options.attributeExtractor;\n\n return async (ctx: SagaPipelineContext, next: () => Promise<void>) => {\n const { envelope } = ctx;\n\n // Determine parent context:\n // 1. First check if saga state has stored trace context (for saga correlation)\n // 2. Fall back to message headers (for standard distributed tracing)\n // 3. Fall back to active context\n let parentContext = context.active();\n\n // Check existing saga state for stored trace context\n const existingState = ctx.existingState;\n if (existingState?.metadata?.traceParent) {\n // Use saga's stored trace context for correlation\n const carrier: TraceContextHeaders = {\n traceparent: existingState.metadata.traceParent,\n tracestate: existingState.metadata.traceState ?? undefined,\n };\n parentContext = propagation.extract(context.active(), carrier);\n } else if (envelope.headers?.traceparent) {\n // Use message header trace context\n parentContext = extractContext(envelope);\n }\n\n // Start span with parent context\n const spanName = `saga-bus.handle ${envelope.type}`;\n const span = tracer.startSpan(\n spanName,\n {\n kind: SpanKind.CONSUMER,\n attributes: buildAttributes(envelope, recordPayload, maxPayloadSize),\n },\n parentContext\n );\n\n // Add custom attributes\n if (attributeExtractor) {\n try {\n const customAttrs = attributeExtractor(envelope);\n span.setAttributes(customAttrs);\n } catch {\n // Ignore extractor errors\n }\n }\n\n // Add saga attributes\n span.setAttribute(\"saga.name\", ctx.sagaName);\n if (ctx.sagaId) {\n span.setAttribute(\"saga.id\", ctx.sagaId);\n }\n span.setAttribute(\"saga.correlation_id\", ctx.correlationId);\n span.setAttribute(\"saga.is_new\", !existingState);\n\n // If this is a new saga or saga has no trace context, store the current trace context\n // so subsequent messages can be correlated\n if (!existingState || !existingState.metadata?.traceParent) {\n const carrier: TraceContextHeaders = {};\n propagation.inject(trace.setSpan(context.active(), span), carrier);\n if (carrier.traceparent) {\n // Store trace context in pipeline context for orchestrator to persist\n ctx.setTraceContext(carrier.traceparent, carrier.tracestate ?? null);\n }\n }\n\n try {\n // Run next middleware within span context\n await context.with(trace.setSpan(context.active(), span), async () => {\n await next();\n });\n\n span.setStatus({ code: SpanStatusCode.OK });\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error instanceof Error ? error.message : String(error),\n });\n span.recordException(error as Error);\n throw error;\n } finally {\n span.end();\n }\n };\n}\n\n/**\n * Create a publish interceptor that adds tracing to outbound messages.\n *\n * @example\n * ```typescript\n * const tracer = createPublishTracer({\n * tracer: trace.getTracer(\"my-service\"),\n * });\n *\n * // Before publishing, wrap the envelope\n * const tracedEnvelope = tracer(envelope);\n * await transport.publish(tracedEnvelope.payload, options);\n * ```\n */\nexport function createPublishTracer(\n options: TracingMiddlewareOptions = {}\n): (envelope: MessageEnvelope) => MessageEnvelope {\n const tracer =\n options.tracer ?? trace.getTracer(options.tracerName ?? TRACER_NAME);\n\n return (envelope: MessageEnvelope): MessageEnvelope => {\n const span = tracer.startSpan(`saga-bus.publish ${envelope.type}`, {\n kind: SpanKind.PRODUCER,\n attributes: {\n \"messaging.system\": \"saga-bus\",\n \"messaging.operation\": \"publish\",\n \"messaging.message.id\": envelope.id,\n \"messaging.message.type\": envelope.type,\n },\n });\n\n // Inject trace context into message headers\n const traceHeaders: TraceContextHeaders = {};\n propagation.inject(trace.setSpan(context.active(), span), traceHeaders);\n\n span.end();\n\n // Return envelope with trace headers merged into existing headers\n return {\n ...envelope,\n headers: {\n ...envelope.headers,\n ...(traceHeaders.traceparent && { traceparent: traceHeaders.traceparent }),\n ...(traceHeaders.tracestate && { tracestate: traceHeaders.tracestate }),\n },\n };\n };\n}\n\n/**\n * Extract trace context from message headers.\n */\nfunction extractContext(envelope: MessageEnvelope): Context {\n const headers = envelope.headers;\n\n if (!headers.traceparent) {\n return context.active();\n }\n\n return propagation.extract(context.active(), headers);\n}\n\n/**\n * Build standard span attributes from message envelope.\n */\nfunction buildAttributes(\n envelope: MessageEnvelope,\n recordPayload: boolean,\n maxPayloadSize: number\n): Attributes {\n const attrs: Attributes = {\n \"messaging.system\": \"saga-bus\",\n \"messaging.operation\": \"process\",\n \"messaging.message.id\": envelope.id,\n \"messaging.message.type\": envelope.type,\n };\n\n if (envelope.partitionKey) {\n attrs[\"messaging.message.partition_key\"] = envelope.partitionKey;\n }\n\n if (recordPayload && envelope.payload !== undefined) {\n const payloadStr = JSON.stringify(envelope.payload);\n if (payloadStr.length <= maxPayloadSize) {\n attrs[\"messaging.message.payload\"] = payloadStr;\n } else {\n attrs[\"messaging.message.payload\"] =\n payloadStr.slice(0, maxPayloadSize) + \"...\";\n attrs[\"messaging.message.payload_truncated\"] = true;\n }\n }\n\n return attrs;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAQP,IAAM,cAAc;AAuBb,SAAS,wBACd,UAAoC,CAAC,GACrB;AAChB,QAAM,SACJ,QAAQ,UAAU,MAAM,UAAU,QAAQ,cAAc,WAAW;AACrE,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,iBAAiB,QAAQ,kBAAkB;AACjD,QAAM,qBAAqB,QAAQ;AAEnC,SAAO,OAAO,K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AuB;AAAA,IACvB,wBAAwB,SAAS;AAAA,IACjC,0BAA0B,SAAS;AAAA,EACrC;AAEA,MAAI,SAAS,cAAc;AACzB,UAAM,iCAAiC,IAAI,SAAS;AAAA,EACtD;AAEA,MAAI,iBAAiB,SAAS,YAAY,QAAW;AACnD,UAAM,aAAa,KAAK,UAAU,SAAS,OAAO;AAClD,QAAI,WAAW,UAAU,gBAAgB;AACvC,YAAM,2BAA2B,IAAI;AAAA,IACvC,OAAO;AACL,YAAM,2BAA2B,IAC/B,WAAW,MAAM,GAAG,cAAc,IAAI;AACxC,YAAM,qCAAqC,IAAI;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@saga-bus/middleware-tracing",
3
+ "version": "0.1.0",
4
+ "description": "OpenTelemetry tracing middleware for saga-bus",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/deanforan/saga-bus.git",
26
+ "directory": "packages/middleware-tracing"
27
+ },
28
+ "keywords": [
29
+ "saga",
30
+ "message-bus",
31
+ "middleware",
32
+ "tracing",
33
+ "opentelemetry",
34
+ "otel"
35
+ ],
36
+ "dependencies": {
37
+ "@saga-bus/core": "0.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "@opentelemetry/api": "^1.9.0",
41
+ "@opentelemetry/sdk-trace-base": "^1.25.0",
42
+ "@types/node": "^20.0.0",
43
+ "tsup": "^8.0.0",
44
+ "typescript": "^5.9.2",
45
+ "vitest": "^3.0.0",
46
+ "@repo/eslint-config": "0.0.0",
47
+ "@repo/typescript-config": "0.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "@opentelemetry/api": ">=1.0.0"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup",
54
+ "dev": "tsup --watch",
55
+ "lint": "eslint src/",
56
+ "check-types": "tsc --noEmit",
57
+ "test": "vitest run",
58
+ "test:watch": "vitest"
59
+ }
60
+ }