autotel-plugins 0.19.25 → 0.19.27
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/dist/bigquery.cjs +393 -309
- package/dist/bigquery.d.cts +56 -44
- package/dist/bigquery.d.ts +56 -44
- package/dist/bigquery.js +389 -308
- package/dist/constants-DKKe2D25.d.cts +94 -47
- package/dist/constants-DKKe2D25.d.ts +94 -47
- package/dist/index.cjs +853 -627
- package/dist/index.d.cts +124 -4
- package/dist/index.d.ts +124 -4
- package/dist/index.js +856 -598
- package/dist/kafka.cjs +330 -226
- package/dist/kafka.d.cts +458 -345
- package/dist/kafka.d.ts +458 -345
- package/dist/kafka.js +326 -210
- package/dist/rabbitmq.cjs +117 -84
- package/dist/rabbitmq.d.cts +218 -151
- package/dist/rabbitmq.d.ts +218 -151
- package/dist/rabbitmq.js +129 -79
- package/package.json +2 -2
package/dist/kafka.d.cts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { SpanLink, Span, Context, SpanContext } from 'autotel';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
C as CORRELATION_ID_HEADER,
|
|
4
|
+
t as SEMATTRS_LINKED_TRACE_ID_COUNT,
|
|
5
|
+
u as SEMATTRS_LINKED_TRACE_ID_HASH,
|
|
6
|
+
v as SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT,
|
|
7
|
+
x as SEMATTRS_MESSAGING_DESTINATION_NAME,
|
|
8
|
+
y as SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET,
|
|
9
|
+
z as SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET,
|
|
10
|
+
A as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED,
|
|
11
|
+
B as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED,
|
|
12
|
+
D as SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS,
|
|
13
|
+
E as SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP,
|
|
14
|
+
F as SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY,
|
|
15
|
+
G as SEMATTRS_MESSAGING_KAFKA_OFFSET,
|
|
16
|
+
H as SEMATTRS_MESSAGING_KAFKA_PARTITION,
|
|
17
|
+
K as SEMATTRS_MESSAGING_OPERATION,
|
|
18
|
+
Q as SEMATTRS_MESSAGING_SYSTEM,
|
|
19
|
+
} from './constants-DKKe2D25.cjs';
|
|
3
20
|
|
|
4
21
|
/**
|
|
5
22
|
* Kafka plugin types - Processing spans, batch lineage, and correlation
|
|
@@ -13,7 +30,10 @@ export { C as CORRELATION_ID_HEADER, t as SEMATTRS_LINKED_TRACE_ID_COUNT, u as S
|
|
|
13
30
|
* Values can be string, Buffer, or undefined.
|
|
14
31
|
* Also accepts Map for compatibility with @platformatic/kafka and other clients.
|
|
15
32
|
*/
|
|
16
|
-
type RawKafkaHeaders =
|
|
33
|
+
type RawKafkaHeaders =
|
|
34
|
+
| Record<string, string | Buffer | undefined>
|
|
35
|
+
| Map<string, string | Buffer | undefined>
|
|
36
|
+
| undefined;
|
|
17
37
|
/**
|
|
18
38
|
* Context mode for processing spans.
|
|
19
39
|
*
|
|
@@ -31,102 +51,102 @@ type ContextMode = 'inherit' | 'link' | 'none';
|
|
|
31
51
|
* Descriptor for creating a processing span.
|
|
32
52
|
*/
|
|
33
53
|
interface ProcessingDescriptor {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Name for the processing span (e.g., "order.process")
|
|
56
|
+
*/
|
|
57
|
+
name: string;
|
|
58
|
+
/**
|
|
59
|
+
* Kafka message headers for context extraction.
|
|
60
|
+
* Use normalizeHeaders() to convert from RawKafkaHeaders.
|
|
61
|
+
*/
|
|
62
|
+
headers: RawKafkaHeaders;
|
|
63
|
+
/**
|
|
64
|
+
* Context mode for relating to extracted remote context.
|
|
65
|
+
* @default 'inherit'
|
|
66
|
+
*/
|
|
67
|
+
contextMode?: ContextMode;
|
|
68
|
+
/**
|
|
69
|
+
* Additional span links to include.
|
|
70
|
+
*/
|
|
71
|
+
links?: SpanLink[];
|
|
72
|
+
/**
|
|
73
|
+
* Kafka topic name. Sets `messaging.destination.name` attribute.
|
|
74
|
+
*/
|
|
75
|
+
topic?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Consumer group name. Sets `messaging.kafka.consumer.group` attribute.
|
|
78
|
+
*/
|
|
79
|
+
consumerGroup?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Kafka partition number. Sets `messaging.kafka.partition` attribute.
|
|
82
|
+
*/
|
|
83
|
+
partition?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Message offset. Sets `messaging.kafka.offset` attribute.
|
|
86
|
+
*/
|
|
87
|
+
offset?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Message key. Sets `messaging.kafka.message.key` attribute.
|
|
90
|
+
*/
|
|
91
|
+
key?: string;
|
|
72
92
|
}
|
|
73
93
|
/**
|
|
74
94
|
* Descriptor for creating a producer span.
|
|
75
95
|
*/
|
|
76
96
|
interface ProducerDescriptor {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Name for the producer span (e.g., "order.publish")
|
|
99
|
+
*/
|
|
100
|
+
name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Kafka topic name. Sets `messaging.destination.name` attribute.
|
|
103
|
+
*/
|
|
104
|
+
topic: string;
|
|
105
|
+
/**
|
|
106
|
+
* Message key. Sets `messaging.kafka.message.key` attribute.
|
|
107
|
+
*/
|
|
108
|
+
messageKey?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Messaging system. Defaults to 'kafka'.
|
|
111
|
+
*/
|
|
112
|
+
system?: string;
|
|
93
113
|
}
|
|
94
114
|
/**
|
|
95
115
|
* Options for batch lineage extraction.
|
|
96
116
|
*/
|
|
97
117
|
interface BatchLineageOptions {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Include raw trace IDs in the result.
|
|
120
|
+
* @default false (privacy consideration)
|
|
121
|
+
*/
|
|
122
|
+
includeTraceIds?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Maximum number of links to include.
|
|
125
|
+
* @default 128
|
|
126
|
+
*/
|
|
127
|
+
maxLinks?: number;
|
|
108
128
|
}
|
|
109
129
|
/**
|
|
110
130
|
* Result of batch lineage extraction.
|
|
111
131
|
*/
|
|
112
132
|
interface BatchLineageResult {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Count of unique, linked trace IDs.
|
|
135
|
+
*/
|
|
136
|
+
linked_trace_id_count: number;
|
|
137
|
+
/**
|
|
138
|
+
* SHA-256 hash of sorted trace IDs (16 hex chars, 64-bit).
|
|
139
|
+
* Useful for comparing batches without exposing individual trace IDs.
|
|
140
|
+
*/
|
|
141
|
+
linked_trace_id_hash: string;
|
|
142
|
+
/**
|
|
143
|
+
* Raw trace IDs, only if includeTraceIds was true.
|
|
144
|
+
*/
|
|
145
|
+
trace_ids?: string[];
|
|
146
|
+
/**
|
|
147
|
+
* Valid SpanLinks from extracted contexts (capped at maxLinks).
|
|
148
|
+
*/
|
|
149
|
+
links: SpanLink[];
|
|
130
150
|
}
|
|
131
151
|
/**
|
|
132
152
|
* Options for injecting trace headers.
|
|
@@ -135,15 +155,15 @@ interface BatchLineageResult {
|
|
|
135
155
|
* If W3CBaggagePropagator is registered, baggage will be injected automatically.
|
|
136
156
|
*/
|
|
137
157
|
interface InjectOptions {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Explicit correlation ID to use. If not provided, derives from current context.
|
|
160
|
+
*/
|
|
161
|
+
correlationId?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Whether to include x-correlation-id header.
|
|
164
|
+
* @default true
|
|
165
|
+
*/
|
|
166
|
+
includeCorrelationIdHeader?: boolean;
|
|
147
167
|
}
|
|
148
168
|
/**
|
|
149
169
|
* Type for the processing span callback function.
|
|
@@ -157,7 +177,7 @@ type ProducerSpanCallback<T> = (span: Span) => Promise<T>;
|
|
|
157
177
|
* Item with optional headers for batch lineage extraction.
|
|
158
178
|
*/
|
|
159
179
|
interface BatchItem {
|
|
160
|
-
|
|
180
|
+
headers?: RawKafkaHeaders;
|
|
161
181
|
}
|
|
162
182
|
|
|
163
183
|
/**
|
|
@@ -201,7 +221,9 @@ interface BatchItem {
|
|
|
201
221
|
* // { traceparent: '00-abc...', 'content-type': 'application/json' }
|
|
202
222
|
* ```
|
|
203
223
|
*/
|
|
204
|
-
declare function normalizeHeaders(
|
|
224
|
+
declare function normalizeHeaders(
|
|
225
|
+
headers?: RawKafkaHeaders,
|
|
226
|
+
): Record<string, string>;
|
|
205
227
|
/**
|
|
206
228
|
* Extract trace context from normalized headers using OTel propagators.
|
|
207
229
|
*
|
|
@@ -280,7 +302,9 @@ declare function deriveCorrelationId(): string;
|
|
|
280
302
|
* }
|
|
281
303
|
* ```
|
|
282
304
|
*/
|
|
283
|
-
declare function extractCorrelationId(
|
|
305
|
+
declare function extractCorrelationId(
|
|
306
|
+
headers: Record<string, string>,
|
|
307
|
+
): string | undefined;
|
|
284
308
|
/**
|
|
285
309
|
* Inject trace headers into outgoing message headers.
|
|
286
310
|
*
|
|
@@ -313,7 +337,10 @@ declare function extractCorrelationId(headers: Record<string, string>): string |
|
|
|
313
337
|
* });
|
|
314
338
|
* ```
|
|
315
339
|
*/
|
|
316
|
-
declare function injectTraceHeaders(
|
|
340
|
+
declare function injectTraceHeaders(
|
|
341
|
+
base?: Record<string, string>,
|
|
342
|
+
options?: InjectOptions,
|
|
343
|
+
): Record<string, string>;
|
|
317
344
|
|
|
318
345
|
/**
|
|
319
346
|
* Processing span wrapper for Kafka message handling.
|
|
@@ -391,7 +418,10 @@ declare function injectTraceHeaders(base?: Record<string, string>, options?: Inj
|
|
|
391
418
|
* });
|
|
392
419
|
* ```
|
|
393
420
|
*/
|
|
394
|
-
declare function withProcessingSpan<T>(
|
|
421
|
+
declare function withProcessingSpan<T>(
|
|
422
|
+
descriptor: ProcessingDescriptor,
|
|
423
|
+
fn: ProcessingSpanCallback<T>,
|
|
424
|
+
): Promise<T>;
|
|
395
425
|
|
|
396
426
|
/**
|
|
397
427
|
* Producer span wrapper for Kafka message publishing.
|
|
@@ -442,7 +472,10 @@ declare function withProcessingSpan<T>(descriptor: ProcessingDescriptor, fn: Pro
|
|
|
442
472
|
* });
|
|
443
473
|
* ```
|
|
444
474
|
*/
|
|
445
|
-
declare function withProducerSpan<T>(
|
|
475
|
+
declare function withProducerSpan<T>(
|
|
476
|
+
descriptor: ProducerDescriptor,
|
|
477
|
+
fn: ProducerSpanCallback<T>,
|
|
478
|
+
): Promise<T>;
|
|
446
479
|
|
|
447
480
|
/**
|
|
448
481
|
* Batch lineage utilities for fan-in trace correlation.
|
|
@@ -498,7 +531,10 @@ declare function withProducerSpan<T>(descriptor: ProducerDescriptor, fn: Produce
|
|
|
498
531
|
* console.log('Processing batch from traces:', lineage.trace_ids);
|
|
499
532
|
* ```
|
|
500
533
|
*/
|
|
501
|
-
declare function extractBatchLineage(
|
|
534
|
+
declare function extractBatchLineage(
|
|
535
|
+
items: BatchItem[],
|
|
536
|
+
options?: BatchLineageOptions,
|
|
537
|
+
): BatchLineageResult;
|
|
502
538
|
/**
|
|
503
539
|
* Async version of extractBatchLineage that uses crypto.subtle for hashing.
|
|
504
540
|
*
|
|
@@ -513,7 +549,10 @@ declare function extractBatchLineage(items: BatchItem[], options?: BatchLineageO
|
|
|
513
549
|
* const lineage = await extractBatchLineageAsync(batch, { maxLinks: 50 });
|
|
514
550
|
* ```
|
|
515
551
|
*/
|
|
516
|
-
declare function extractBatchLineageAsync(
|
|
552
|
+
declare function extractBatchLineageAsync(
|
|
553
|
+
items: BatchItem[],
|
|
554
|
+
options?: BatchLineageOptions,
|
|
555
|
+
): Promise<BatchLineageResult>;
|
|
517
556
|
|
|
518
557
|
/**
|
|
519
558
|
* Batch consumer wrapper for KafkaJS batch processing.
|
|
@@ -543,26 +582,28 @@ declare function extractBatchLineageAsync(items: BatchItem[], options?: BatchLin
|
|
|
543
582
|
* Matches the exact signature from KafkaJS.
|
|
544
583
|
*/
|
|
545
584
|
interface EachBatchPayload {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
585
|
+
batch: {
|
|
586
|
+
topic: string;
|
|
587
|
+
partition: number;
|
|
588
|
+
messages: Array<{
|
|
589
|
+
offset: string;
|
|
590
|
+
key?: Buffer | null;
|
|
591
|
+
value: Buffer | null;
|
|
592
|
+
headers?: Record<string, Buffer | string | undefined>;
|
|
593
|
+
}>;
|
|
594
|
+
firstOffset(): string | null;
|
|
595
|
+
lastOffset(): string;
|
|
596
|
+
highWatermark: string;
|
|
597
|
+
};
|
|
598
|
+
resolveOffset(offset: string): void;
|
|
599
|
+
heartbeat(): Promise<void>;
|
|
600
|
+
commitOffsetsIfNecessary(
|
|
601
|
+
offsets?: Record<string, Record<number, string>>,
|
|
602
|
+
): Promise<void>;
|
|
603
|
+
uncommittedOffsets(): Record<string, Record<number, string>>;
|
|
604
|
+
isRunning(): boolean;
|
|
605
|
+
isStale(): boolean;
|
|
606
|
+
pause(): () => void;
|
|
566
607
|
}
|
|
567
608
|
/**
|
|
568
609
|
* Batch consumer handler type.
|
|
@@ -572,14 +613,14 @@ type EachBatchHandler = (payload: EachBatchPayload) => Promise<void>;
|
|
|
572
613
|
* Progress metrics during batch processing.
|
|
573
614
|
*/
|
|
574
615
|
interface BatchProgressMetrics {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
616
|
+
/** Number of messages processed so far */
|
|
617
|
+
processed: number;
|
|
618
|
+
/** Number of messages that failed processing */
|
|
619
|
+
failed: number;
|
|
620
|
+
/** Number of messages skipped */
|
|
621
|
+
skipped: number;
|
|
622
|
+
/** Batch processing time in milliseconds */
|
|
623
|
+
batchProcessingTimeMs: number;
|
|
583
624
|
}
|
|
584
625
|
/**
|
|
585
626
|
* Per-message span mode.
|
|
@@ -592,23 +633,23 @@ type PerMessageSpanMode = 'all' | 'errors' | 'none';
|
|
|
592
633
|
* Configuration for batch consumer wrapper.
|
|
593
634
|
*/
|
|
594
635
|
interface BatchConsumerConfig {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
636
|
+
/**
|
|
637
|
+
* Name for the batch processing span (e.g., "orders.batch")
|
|
638
|
+
*/
|
|
639
|
+
name: string;
|
|
640
|
+
/**
|
|
641
|
+
* Consumer group name. Sets `messaging.kafka.consumer.group` attribute.
|
|
642
|
+
*/
|
|
643
|
+
consumerGroup?: string;
|
|
644
|
+
/**
|
|
645
|
+
* Per-message span creation mode. When 'all', message spans follow extracted trace context from headers when valid (trace continuation), otherwise parent to the batch span; all per-message spans are ended on batch completion.
|
|
646
|
+
* @default 'none' (to avoid cardinality explosion)
|
|
647
|
+
*/
|
|
648
|
+
perMessageSpans?: PerMessageSpanMode;
|
|
649
|
+
/**
|
|
650
|
+
* Optional callback for real-time visibility into batch processing.
|
|
651
|
+
*/
|
|
652
|
+
onProgress?: (metrics: BatchProgressMetrics) => void;
|
|
612
653
|
}
|
|
613
654
|
/**
|
|
614
655
|
* Wrap a KafkaJS eachBatch handler with observability.
|
|
@@ -644,16 +685,25 @@ interface BatchConsumerConfig {
|
|
|
644
685
|
* });
|
|
645
686
|
* ```
|
|
646
687
|
*/
|
|
647
|
-
declare function withBatchConsumer(
|
|
688
|
+
declare function withBatchConsumer(
|
|
689
|
+
config: BatchConsumerConfig,
|
|
690
|
+
handler: EachBatchHandler,
|
|
691
|
+
): EachBatchHandler;
|
|
648
692
|
/**
|
|
649
693
|
* Helper to create a per-message span for error cases.
|
|
650
694
|
* Call this in your error handler when using perMessageSpans: 'errors'.
|
|
651
695
|
*/
|
|
652
|
-
declare function createMessageErrorSpan(
|
|
696
|
+
declare function createMessageErrorSpan(
|
|
697
|
+
name: string,
|
|
698
|
+
message: {
|
|
653
699
|
offset: string;
|
|
654
700
|
key?: Buffer | null;
|
|
655
701
|
headers?: Record<string, Buffer | string | undefined>;
|
|
656
|
-
},
|
|
702
|
+
},
|
|
703
|
+
error: Error,
|
|
704
|
+
topic: string,
|
|
705
|
+
partition: number,
|
|
706
|
+
): void;
|
|
657
707
|
|
|
658
708
|
/**
|
|
659
709
|
* Stream processor for Kafka pipeline patterns.
|
|
@@ -694,72 +744,76 @@ declare function createMessageErrorSpan(name: string, message: {
|
|
|
694
744
|
* Input message type for stream processing.
|
|
695
745
|
*/
|
|
696
746
|
interface StreamMessage {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
747
|
+
headers?: RawKafkaHeaders;
|
|
748
|
+
key?: Buffer | null;
|
|
749
|
+
value: Buffer | null;
|
|
750
|
+
offset?: string;
|
|
701
751
|
}
|
|
702
752
|
/**
|
|
703
753
|
* Configuration for stream processor.
|
|
704
754
|
*/
|
|
705
755
|
interface StreamProcessorConfig {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
756
|
+
/**
|
|
757
|
+
* Name for the processor (e.g., "order-enrichment")
|
|
758
|
+
*/
|
|
759
|
+
name: string;
|
|
760
|
+
/**
|
|
761
|
+
* Expected stage names (for documentation/validation).
|
|
762
|
+
* Stages can be run in any order.
|
|
763
|
+
*/
|
|
764
|
+
stages?: string[];
|
|
715
765
|
}
|
|
716
766
|
/**
|
|
717
767
|
* Options for producing output messages.
|
|
718
768
|
*/
|
|
719
769
|
interface ProduceOptions {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
770
|
+
/**
|
|
771
|
+
* Create a SpanLink to the input message's extracted context.
|
|
772
|
+
* Useful for lineage tracking.
|
|
773
|
+
* @default false
|
|
774
|
+
*/
|
|
775
|
+
linkToInput?: boolean;
|
|
776
|
+
/**
|
|
777
|
+
* Additional headers to include (merged with trace headers).
|
|
778
|
+
*/
|
|
779
|
+
headers?: Record<string, string>;
|
|
730
780
|
}
|
|
731
781
|
/**
|
|
732
782
|
* Context passed to the processor callback.
|
|
733
783
|
*/
|
|
734
784
|
interface ProcessorContext {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
785
|
+
/**
|
|
786
|
+
* The processor-level span.
|
|
787
|
+
*/
|
|
788
|
+
span: Span;
|
|
789
|
+
/**
|
|
790
|
+
* Execute a named stage with automatic span creation.
|
|
791
|
+
*
|
|
792
|
+
* @param stageName - Name of the stage (e.g., "validate", "enrich")
|
|
793
|
+
* @param fn - Stage function to execute
|
|
794
|
+
* @returns Result of the stage function
|
|
795
|
+
*/
|
|
796
|
+
stage<T>(stageName: string, fn: () => T | Promise<T>): Promise<T>;
|
|
797
|
+
/**
|
|
798
|
+
* Produce a message with proper span creation and header injection.
|
|
799
|
+
*
|
|
800
|
+
* The returned headers should be used when actually sending the message.
|
|
801
|
+
*
|
|
802
|
+
* @param topic - Destination topic
|
|
803
|
+
* @param payload - Message payload
|
|
804
|
+
* @param options - Produce options
|
|
805
|
+
* @returns Headers to use when sending (includes trace context)
|
|
806
|
+
*/
|
|
807
|
+
produce(
|
|
808
|
+
topic: string,
|
|
809
|
+
payload: unknown,
|
|
810
|
+
options?: ProduceOptions,
|
|
811
|
+
): Promise<Record<string, string>>;
|
|
812
|
+
/**
|
|
813
|
+
* Get the extracted context from the input message.
|
|
814
|
+
* Useful for creating manual links or context propagation.
|
|
815
|
+
*/
|
|
816
|
+
inputContext: SpanContext | undefined;
|
|
763
817
|
}
|
|
764
818
|
/**
|
|
765
819
|
* Processor callback type.
|
|
@@ -769,14 +823,14 @@ type ProcessorCallback<T> = (ctx: ProcessorContext) => Promise<T>;
|
|
|
769
823
|
* Stream processor instance.
|
|
770
824
|
*/
|
|
771
825
|
interface StreamProcessor {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
826
|
+
/**
|
|
827
|
+
* Run the processor on an input message.
|
|
828
|
+
*
|
|
829
|
+
* @param message - Input Kafka message
|
|
830
|
+
* @param callback - Processor callback with stage/produce helpers
|
|
831
|
+
* @returns Result of the processor callback
|
|
832
|
+
*/
|
|
833
|
+
run<T>(message: StreamMessage, callback: ProcessorCallback<T>): Promise<T>;
|
|
780
834
|
}
|
|
781
835
|
/**
|
|
782
836
|
* Create a stream processor for pipeline-style message processing.
|
|
@@ -812,7 +866,9 @@ interface StreamProcessor {
|
|
|
812
866
|
* });
|
|
813
867
|
* ```
|
|
814
868
|
*/
|
|
815
|
-
declare function createStreamProcessor(
|
|
869
|
+
declare function createStreamProcessor(
|
|
870
|
+
config: StreamProcessorConfig,
|
|
871
|
+
): StreamProcessor;
|
|
816
872
|
|
|
817
873
|
/**
|
|
818
874
|
* Consumer metrics for Kafka observability.
|
|
@@ -853,79 +909,80 @@ type LagStrategy = 'polling' | 'event' | 'hybrid';
|
|
|
853
909
|
* Matches KafkaJS consumer shape.
|
|
854
910
|
*/
|
|
855
911
|
interface KafkaConsumer {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}>;
|
|
863
|
-
state: string;
|
|
912
|
+
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
913
|
+
describeGroup?(): Promise<{
|
|
914
|
+
members: Array<{
|
|
915
|
+
memberId: string;
|
|
916
|
+
clientId: string;
|
|
917
|
+
memberAssignment: Buffer;
|
|
864
918
|
}>;
|
|
919
|
+
state: string;
|
|
920
|
+
}>;
|
|
865
921
|
}
|
|
866
922
|
/**
|
|
867
923
|
* Minimal Kafka admin interface for lag calculation.
|
|
868
924
|
*/
|
|
869
925
|
interface KafkaAdmin {
|
|
870
|
-
|
|
926
|
+
fetchTopicOffsets(topic: string): Promise<
|
|
927
|
+
Array<{
|
|
928
|
+
partition: number;
|
|
929
|
+
offset: string;
|
|
930
|
+
high: string;
|
|
931
|
+
low: string;
|
|
932
|
+
}>
|
|
933
|
+
>;
|
|
934
|
+
fetchOffsets(options: { groupId: string; topics: string[] }): Promise<
|
|
935
|
+
Array<{
|
|
936
|
+
topic: string;
|
|
937
|
+
partitions: Array<{
|
|
871
938
|
partition: number;
|
|
872
939
|
offset: string;
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
fetchOffsets(options: {
|
|
877
|
-
groupId: string;
|
|
878
|
-
topics: string[];
|
|
879
|
-
}): Promise<Array<{
|
|
880
|
-
topic: string;
|
|
881
|
-
partitions: Array<{
|
|
882
|
-
partition: number;
|
|
883
|
-
offset: string;
|
|
884
|
-
}>;
|
|
885
|
-
}>>;
|
|
940
|
+
}>;
|
|
941
|
+
}>
|
|
942
|
+
>;
|
|
886
943
|
}
|
|
887
944
|
/**
|
|
888
945
|
* Configuration for consumer metrics.
|
|
889
946
|
*/
|
|
890
947
|
interface ConsumerMetricsConfig {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
948
|
+
/**
|
|
949
|
+
* The Kafka consumer to monitor.
|
|
950
|
+
*/
|
|
951
|
+
consumer: KafkaConsumer;
|
|
952
|
+
/**
|
|
953
|
+
* Optional Kafka admin client for lag calculation.
|
|
954
|
+
* Required if enableLag is true and lagStrategy is 'polling' or 'hybrid'.
|
|
955
|
+
*/
|
|
956
|
+
admin?: KafkaAdmin;
|
|
957
|
+
/**
|
|
958
|
+
* Consumer group ID (required for lag calculation).
|
|
959
|
+
*/
|
|
960
|
+
groupId?: string;
|
|
961
|
+
/**
|
|
962
|
+
* Topics to monitor for lag.
|
|
963
|
+
*/
|
|
964
|
+
topics?: string[];
|
|
965
|
+
/**
|
|
966
|
+
* Prefix for metric names.
|
|
967
|
+
* @default 'kafka.consumer'
|
|
968
|
+
*/
|
|
969
|
+
metricsPrefix?: string;
|
|
970
|
+
/**
|
|
971
|
+
* Enable consumer lag tracking.
|
|
972
|
+
* @default false
|
|
973
|
+
*/
|
|
974
|
+
enableLag?: boolean;
|
|
975
|
+
/**
|
|
976
|
+
* Strategy for lag calculation.
|
|
977
|
+
* @default 'hybrid'
|
|
978
|
+
*/
|
|
979
|
+
lagStrategy?: LagStrategy;
|
|
980
|
+
/**
|
|
981
|
+
* Interval for lag polling in milliseconds.
|
|
982
|
+
* Required when enableLag is true and lagStrategy is 'polling'.
|
|
983
|
+
* @default 30000
|
|
984
|
+
*/
|
|
985
|
+
lagPollIntervalMs?: number;
|
|
929
986
|
}
|
|
930
987
|
/**
|
|
931
988
|
* Consumer metrics collector.
|
|
@@ -938,54 +995,63 @@ interface ConsumerMetricsConfig {
|
|
|
938
995
|
* - kafka.consumer.lag (gauge, opt-in)
|
|
939
996
|
*/
|
|
940
997
|
declare class ConsumerMetrics {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
998
|
+
private readonly config;
|
|
999
|
+
private readonly meter;
|
|
1000
|
+
private readonly messagesProcessed;
|
|
1001
|
+
private readonly processingDuration;
|
|
1002
|
+
private readonly batchSize;
|
|
1003
|
+
private readonly rebalances;
|
|
1004
|
+
private readonly lag;
|
|
1005
|
+
private partitionStates;
|
|
1006
|
+
private lagPollInterval?;
|
|
1007
|
+
private isRunning;
|
|
1008
|
+
constructor(config: ConsumerMetricsConfig);
|
|
1009
|
+
/**
|
|
1010
|
+
* Start metrics collection.
|
|
1011
|
+
*/
|
|
1012
|
+
start(): Promise<void>;
|
|
1013
|
+
/**
|
|
1014
|
+
* Stop metrics collection.
|
|
1015
|
+
*/
|
|
1016
|
+
stop(): Promise<void>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Record a message being processed.
|
|
1019
|
+
*
|
|
1020
|
+
* @param topic - Message topic
|
|
1021
|
+
* @param partition - Message partition
|
|
1022
|
+
* @param durationMs - Processing duration in milliseconds
|
|
1023
|
+
*/
|
|
1024
|
+
recordMessageProcessed(
|
|
1025
|
+
topic: string,
|
|
1026
|
+
partition: number,
|
|
1027
|
+
durationMs?: number,
|
|
1028
|
+
): void;
|
|
1029
|
+
/**
|
|
1030
|
+
* Record a batch being processed.
|
|
1031
|
+
*
|
|
1032
|
+
* @param topic - Batch topic
|
|
1033
|
+
* @param partition - Batch partition
|
|
1034
|
+
* @param size - Number of messages in the batch
|
|
1035
|
+
*/
|
|
1036
|
+
recordBatch(topic: string, partition: number, size: number): void;
|
|
1037
|
+
/**
|
|
1038
|
+
* Update offset state for event-based lag tracking.
|
|
1039
|
+
*
|
|
1040
|
+
* @param topic - Topic name
|
|
1041
|
+
* @param partition - Partition number
|
|
1042
|
+
* @param offset - Current consumer offset
|
|
1043
|
+
* @param highWatermark - Optional high watermark
|
|
1044
|
+
*/
|
|
1045
|
+
updateOffset(
|
|
1046
|
+
topic: string,
|
|
1047
|
+
partition: number,
|
|
1048
|
+
offset: string,
|
|
1049
|
+
highWatermark?: string,
|
|
1050
|
+
): void;
|
|
1051
|
+
/**
|
|
1052
|
+
* Poll for lag using admin client.
|
|
1053
|
+
*/
|
|
1054
|
+
private pollLag;
|
|
989
1055
|
}
|
|
990
1056
|
|
|
991
1057
|
/**
|
|
@@ -1018,38 +1084,38 @@ type EventMode = 'events' | 'spans';
|
|
|
1018
1084
|
* Minimal Kafka consumer interface for event instrumentation.
|
|
1019
1085
|
*/
|
|
1020
1086
|
interface EventConsumer {
|
|
1021
|
-
|
|
1022
|
-
|
|
1087
|
+
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
1088
|
+
off?(event: string, listener: (...args: unknown[]) => void): void;
|
|
1023
1089
|
}
|
|
1024
1090
|
/**
|
|
1025
1091
|
* Configuration for consumer event instrumentation.
|
|
1026
1092
|
*/
|
|
1027
1093
|
interface ConsumerEventsConfig {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1094
|
+
/**
|
|
1095
|
+
* Event mode: 'events' attaches to spans, 'spans' creates new spans.
|
|
1096
|
+
* @default 'events'
|
|
1097
|
+
*/
|
|
1098
|
+
mode?: EventMode;
|
|
1099
|
+
/**
|
|
1100
|
+
* Trace rebalance events (GROUP_JOIN, REBALANCING).
|
|
1101
|
+
* @default true
|
|
1102
|
+
*/
|
|
1103
|
+
traceRebalances?: boolean;
|
|
1104
|
+
/**
|
|
1105
|
+
* Trace error events (CRASH, DISCONNECT).
|
|
1106
|
+
* @default true
|
|
1107
|
+
*/
|
|
1108
|
+
traceErrors?: boolean;
|
|
1109
|
+
/**
|
|
1110
|
+
* Trace heartbeat events.
|
|
1111
|
+
* @default false (too noisy for most use cases)
|
|
1112
|
+
*/
|
|
1113
|
+
traceHeartbeats?: boolean;
|
|
1114
|
+
/**
|
|
1115
|
+
* Optional lifecycle span to attach events to.
|
|
1116
|
+
* Only used when mode is 'events'.
|
|
1117
|
+
*/
|
|
1118
|
+
lifecycleSpan?: Span;
|
|
1053
1119
|
}
|
|
1054
1120
|
/**
|
|
1055
1121
|
* Cleanup function returned by instrumentConsumerEvents.
|
|
@@ -1076,6 +1142,53 @@ type CleanupFunction = () => void;
|
|
|
1076
1142
|
* cleanup();
|
|
1077
1143
|
* ```
|
|
1078
1144
|
*/
|
|
1079
|
-
declare function instrumentConsumerEvents(
|
|
1145
|
+
declare function instrumentConsumerEvents(
|
|
1146
|
+
consumer: EventConsumer,
|
|
1147
|
+
config?: ConsumerEventsConfig,
|
|
1148
|
+
): CleanupFunction;
|
|
1080
1149
|
|
|
1081
|
-
export {
|
|
1150
|
+
export {
|
|
1151
|
+
type BatchConsumerConfig,
|
|
1152
|
+
type BatchItem,
|
|
1153
|
+
type BatchLineageOptions,
|
|
1154
|
+
type BatchLineageResult,
|
|
1155
|
+
type BatchProgressMetrics,
|
|
1156
|
+
type CleanupFunction,
|
|
1157
|
+
type ConsumerEventsConfig,
|
|
1158
|
+
ConsumerMetrics,
|
|
1159
|
+
type ConsumerMetricsConfig,
|
|
1160
|
+
type ContextMode,
|
|
1161
|
+
type EachBatchHandler,
|
|
1162
|
+
type EachBatchPayload,
|
|
1163
|
+
type EventConsumer,
|
|
1164
|
+
type EventMode,
|
|
1165
|
+
type InjectOptions,
|
|
1166
|
+
type KafkaAdmin,
|
|
1167
|
+
type KafkaConsumer,
|
|
1168
|
+
type LagStrategy,
|
|
1169
|
+
type PerMessageSpanMode,
|
|
1170
|
+
type ProcessingDescriptor,
|
|
1171
|
+
type ProcessingSpanCallback,
|
|
1172
|
+
type ProcessorCallback,
|
|
1173
|
+
type ProcessorContext,
|
|
1174
|
+
type ProduceOptions,
|
|
1175
|
+
type ProducerDescriptor,
|
|
1176
|
+
type ProducerSpanCallback,
|
|
1177
|
+
type RawKafkaHeaders,
|
|
1178
|
+
type StreamMessage,
|
|
1179
|
+
type StreamProcessor,
|
|
1180
|
+
type StreamProcessorConfig,
|
|
1181
|
+
createMessageErrorSpan,
|
|
1182
|
+
createStreamProcessor,
|
|
1183
|
+
deriveCorrelationId,
|
|
1184
|
+
extractBatchLineage,
|
|
1185
|
+
extractBatchLineageAsync,
|
|
1186
|
+
extractCorrelationId,
|
|
1187
|
+
extractTraceContext,
|
|
1188
|
+
injectTraceHeaders,
|
|
1189
|
+
instrumentConsumerEvents,
|
|
1190
|
+
normalizeHeaders,
|
|
1191
|
+
withBatchConsumer,
|
|
1192
|
+
withProcessingSpan,
|
|
1193
|
+
withProducerSpan,
|
|
1194
|
+
};
|