autotel 2.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 +21 -0
- package/README.md +1946 -0
- package/dist/chunk-2LNRY4QK.js +273 -0
- package/dist/chunk-2LNRY4QK.js.map +1 -0
- package/dist/chunk-3HENGDW2.js +587 -0
- package/dist/chunk-3HENGDW2.js.map +1 -0
- package/dist/chunk-4OAT42CA.cjs +73 -0
- package/dist/chunk-4OAT42CA.cjs.map +1 -0
- package/dist/chunk-5GWX5LFW.js +70 -0
- package/dist/chunk-5GWX5LFW.js.map +1 -0
- package/dist/chunk-5R2M36QB.js +195 -0
- package/dist/chunk-5R2M36QB.js.map +1 -0
- package/dist/chunk-5ZN622AO.js +73 -0
- package/dist/chunk-5ZN622AO.js.map +1 -0
- package/dist/chunk-77MSMAUQ.cjs +498 -0
- package/dist/chunk-77MSMAUQ.cjs.map +1 -0
- package/dist/chunk-ABPEQ6RK.cjs +596 -0
- package/dist/chunk-ABPEQ6RK.cjs.map +1 -0
- package/dist/chunk-BWYGJKRB.js +95 -0
- package/dist/chunk-BWYGJKRB.js.map +1 -0
- package/dist/chunk-BZHG5IZ4.js +73 -0
- package/dist/chunk-BZHG5IZ4.js.map +1 -0
- package/dist/chunk-G7VZBCD6.cjs +35 -0
- package/dist/chunk-G7VZBCD6.cjs.map +1 -0
- package/dist/chunk-GVLK7YUU.cjs +30 -0
- package/dist/chunk-GVLK7YUU.cjs.map +1 -0
- package/dist/chunk-HCCXC7XG.js +205 -0
- package/dist/chunk-HCCXC7XG.js.map +1 -0
- package/dist/chunk-HE6T6FIX.cjs +203 -0
- package/dist/chunk-HE6T6FIX.cjs.map +1 -0
- package/dist/chunk-KIXWPOCO.cjs +100 -0
- package/dist/chunk-KIXWPOCO.cjs.map +1 -0
- package/dist/chunk-KVGNW3FC.js +87 -0
- package/dist/chunk-KVGNW3FC.js.map +1 -0
- package/dist/chunk-LITNXTTT.js +3 -0
- package/dist/chunk-LITNXTTT.js.map +1 -0
- package/dist/chunk-M4ANN7RL.js +114 -0
- package/dist/chunk-M4ANN7RL.js.map +1 -0
- package/dist/chunk-NC52UBR2.cjs +32 -0
- package/dist/chunk-NC52UBR2.cjs.map +1 -0
- package/dist/chunk-NHCNRQD3.cjs +212 -0
- package/dist/chunk-NHCNRQD3.cjs.map +1 -0
- package/dist/chunk-NZ72VDNY.cjs +4 -0
- package/dist/chunk-NZ72VDNY.cjs.map +1 -0
- package/dist/chunk-P6JUDYNO.js +57 -0
- package/dist/chunk-P6JUDYNO.js.map +1 -0
- package/dist/chunk-RJYY7BWX.js +1349 -0
- package/dist/chunk-RJYY7BWX.js.map +1 -0
- package/dist/chunk-TRI4V5BF.cjs +126 -0
- package/dist/chunk-TRI4V5BF.cjs.map +1 -0
- package/dist/chunk-UL33I6IS.js +139 -0
- package/dist/chunk-UL33I6IS.js.map +1 -0
- package/dist/chunk-URRW6M2C.cjs +61 -0
- package/dist/chunk-URRW6M2C.cjs.map +1 -0
- package/dist/chunk-UY3UYPBZ.cjs +77 -0
- package/dist/chunk-UY3UYPBZ.cjs.map +1 -0
- package/dist/chunk-W3253FGB.cjs +277 -0
- package/dist/chunk-W3253FGB.cjs.map +1 -0
- package/dist/chunk-W7LHZVQF.js +26 -0
- package/dist/chunk-W7LHZVQF.js.map +1 -0
- package/dist/chunk-WBWNM6LB.cjs +1360 -0
- package/dist/chunk-WBWNM6LB.cjs.map +1 -0
- package/dist/chunk-WFJ7L2RV.js +494 -0
- package/dist/chunk-WFJ7L2RV.js.map +1 -0
- package/dist/chunk-X4RMFFMR.js +28 -0
- package/dist/chunk-X4RMFFMR.js.map +1 -0
- package/dist/chunk-Y4Y2S7BM.cjs +92 -0
- package/dist/chunk-Y4Y2S7BM.cjs.map +1 -0
- package/dist/chunk-YLPNXZFI.cjs +143 -0
- package/dist/chunk-YLPNXZFI.cjs.map +1 -0
- package/dist/chunk-YTXEZ4SD.cjs +77 -0
- package/dist/chunk-YTXEZ4SD.cjs.map +1 -0
- package/dist/chunk-Z6ZWNWWR.js +30 -0
- package/dist/chunk-Z6ZWNWWR.js.map +1 -0
- package/dist/config.cjs +26 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +75 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/db.cjs +233 -0
- package/dist/db.cjs.map +1 -0
- package/dist/db.d.cts +123 -0
- package/dist/db.d.ts +123 -0
- package/dist/db.js +228 -0
- package/dist/db.js.map +1 -0
- package/dist/decorators.cjs +67 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +91 -0
- package/dist/decorators.d.ts +91 -0
- package/dist/decorators.js +65 -0
- package/dist/decorators.js.map +1 -0
- package/dist/event-subscriber.cjs +6 -0
- package/dist/event-subscriber.cjs.map +1 -0
- package/dist/event-subscriber.d.cts +116 -0
- package/dist/event-subscriber.d.ts +116 -0
- package/dist/event-subscriber.js +3 -0
- package/dist/event-subscriber.js.map +1 -0
- package/dist/event-testing.cjs +21 -0
- package/dist/event-testing.cjs.map +1 -0
- package/dist/event-testing.d.cts +110 -0
- package/dist/event-testing.d.ts +110 -0
- package/dist/event-testing.js +4 -0
- package/dist/event-testing.js.map +1 -0
- package/dist/event.cjs +30 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +282 -0
- package/dist/event.d.ts +282 -0
- package/dist/event.js +13 -0
- package/dist/event.js.map +1 -0
- package/dist/exporters.cjs +17 -0
- package/dist/exporters.cjs.map +1 -0
- package/dist/exporters.d.cts +1 -0
- package/dist/exporters.d.ts +1 -0
- package/dist/exporters.js +4 -0
- package/dist/exporters.js.map +1 -0
- package/dist/functional.cjs +46 -0
- package/dist/functional.cjs.map +1 -0
- package/dist/functional.d.cts +478 -0
- package/dist/functional.d.ts +478 -0
- package/dist/functional.js +13 -0
- package/dist/functional.js.map +1 -0
- package/dist/http.cjs +189 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +169 -0
- package/dist/http.d.ts +169 -0
- package/dist/http.js +184 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +333 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +758 -0
- package/dist/index.d.ts +758 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.cjs +182 -0
- package/dist/instrumentation.cjs.map +1 -0
- package/dist/instrumentation.d.cts +49 -0
- package/dist/instrumentation.d.ts +49 -0
- package/dist/instrumentation.js +179 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/logger.cjs +19 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +146 -0
- package/dist/logger.d.ts +146 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/dist/metric-helpers.cjs +31 -0
- package/dist/metric-helpers.cjs.map +1 -0
- package/dist/metric-helpers.d.cts +13 -0
- package/dist/metric-helpers.d.ts +13 -0
- package/dist/metric-helpers.js +6 -0
- package/dist/metric-helpers.js.map +1 -0
- package/dist/metric-testing.cjs +21 -0
- package/dist/metric-testing.cjs.map +1 -0
- package/dist/metric-testing.d.cts +110 -0
- package/dist/metric-testing.d.ts +110 -0
- package/dist/metric-testing.js +4 -0
- package/dist/metric-testing.js.map +1 -0
- package/dist/metric.cjs +26 -0
- package/dist/metric.cjs.map +1 -0
- package/dist/metric.d.cts +240 -0
- package/dist/metric.d.ts +240 -0
- package/dist/metric.js +9 -0
- package/dist/metric.js.map +1 -0
- package/dist/processors.cjs +17 -0
- package/dist/processors.cjs.map +1 -0
- package/dist/processors.d.cts +1 -0
- package/dist/processors.d.ts +1 -0
- package/dist/processors.js +4 -0
- package/dist/processors.js.map +1 -0
- package/dist/sampling.cjs +40 -0
- package/dist/sampling.cjs.map +1 -0
- package/dist/sampling.d.cts +260 -0
- package/dist/sampling.d.ts +260 -0
- package/dist/sampling.js +7 -0
- package/dist/sampling.js.map +1 -0
- package/dist/semantic-helpers.cjs +35 -0
- package/dist/semantic-helpers.cjs.map +1 -0
- package/dist/semantic-helpers.d.cts +442 -0
- package/dist/semantic-helpers.d.ts +442 -0
- package/dist/semantic-helpers.js +14 -0
- package/dist/semantic-helpers.js.map +1 -0
- package/dist/tail-sampling-processor.cjs +13 -0
- package/dist/tail-sampling-processor.cjs.map +1 -0
- package/dist/tail-sampling-processor.d.cts +27 -0
- package/dist/tail-sampling-processor.d.ts +27 -0
- package/dist/tail-sampling-processor.js +4 -0
- package/dist/tail-sampling-processor.js.map +1 -0
- package/dist/testing.cjs +286 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +291 -0
- package/dist/testing.d.ts +291 -0
- package/dist/testing.js +263 -0
- package/dist/testing.js.map +1 -0
- package/dist/trace-context-DRZdUvVY.d.cts +181 -0
- package/dist/trace-context-DRZdUvVY.d.ts +181 -0
- package/dist/trace-helpers.cjs +54 -0
- package/dist/trace-helpers.cjs.map +1 -0
- package/dist/trace-helpers.d.cts +524 -0
- package/dist/trace-helpers.d.ts +524 -0
- package/dist/trace-helpers.js +5 -0
- package/dist/trace-helpers.js.map +1 -0
- package/dist/tracer-provider.cjs +21 -0
- package/dist/tracer-provider.cjs.map +1 -0
- package/dist/tracer-provider.d.cts +169 -0
- package/dist/tracer-provider.d.ts +169 -0
- package/dist/tracer-provider.js +4 -0
- package/dist/tracer-provider.js.map +1 -0
- package/package.json +280 -0
- package/src/baggage-span-processor.test.ts +202 -0
- package/src/baggage-span-processor.ts +98 -0
- package/src/circuit-breaker.test.ts +341 -0
- package/src/circuit-breaker.ts +184 -0
- package/src/config.test.ts +94 -0
- package/src/config.ts +169 -0
- package/src/db.test.ts +252 -0
- package/src/db.ts +447 -0
- package/src/decorators.test.ts +203 -0
- package/src/decorators.ts +188 -0
- package/src/env-config.test.ts +246 -0
- package/src/env-config.ts +158 -0
- package/src/event-queue.test.ts +222 -0
- package/src/event-queue.ts +203 -0
- package/src/event-subscriber.ts +136 -0
- package/src/event-testing.ts +197 -0
- package/src/event.test.ts +718 -0
- package/src/event.ts +556 -0
- package/src/exporters.ts +96 -0
- package/src/functional.test.ts +1059 -0
- package/src/functional.ts +2295 -0
- package/src/http.test.ts +487 -0
- package/src/http.ts +424 -0
- package/src/index.ts +158 -0
- package/src/init.customization.test.ts +210 -0
- package/src/init.integrations.test.ts +366 -0
- package/src/init.openllmetry.test.ts +282 -0
- package/src/init.protocol.test.ts +215 -0
- package/src/init.ts +1426 -0
- package/src/instrumentation.test.ts +108 -0
- package/src/instrumentation.ts +308 -0
- package/src/logger.test.ts +117 -0
- package/src/logger.ts +246 -0
- package/src/metric-helpers.ts +47 -0
- package/src/metric-testing.ts +197 -0
- package/src/metric.ts +434 -0
- package/src/metrics.test.ts +205 -0
- package/src/operation-context.ts +93 -0
- package/src/processors.ts +106 -0
- package/src/rate-limiter.test.ts +199 -0
- package/src/rate-limiter.ts +98 -0
- package/src/sampling.test.ts +513 -0
- package/src/sampling.ts +428 -0
- package/src/semantic-helpers.test.ts +311 -0
- package/src/semantic-helpers.ts +584 -0
- package/src/shutdown.test.ts +311 -0
- package/src/shutdown.ts +222 -0
- package/src/stub.integration.test.ts +361 -0
- package/src/tail-sampling-processor.test.ts +226 -0
- package/src/tail-sampling-processor.ts +51 -0
- package/src/testing.ts +670 -0
- package/src/trace-context.ts +470 -0
- package/src/trace-helpers.new.test.ts +278 -0
- package/src/trace-helpers.test.ts +242 -0
- package/src/trace-helpers.ts +690 -0
- package/src/tracer-provider.test.ts +183 -0
- package/src/tracer-provider.ts +266 -0
- package/src/track.test.ts +153 -0
- package/src/track.ts +120 -0
- package/src/validation.test.ts +306 -0
- package/src/validation.ts +239 -0
- package/src/variable-name-inference.test.ts +178 -0
- package/src/variable-name-inference.ts +242 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { T as TraceContext } from './trace-context-DRZdUvVY.js';
|
|
2
|
+
import { Attributes } from '@opentelemetry/api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Semantic convention helpers for OpenTelemetry
|
|
6
|
+
*
|
|
7
|
+
* Pre-configured trace helpers that follow OpenTelemetry semantic conventions
|
|
8
|
+
* for common operation types. Reduces boilerplate and ensures consistency.
|
|
9
|
+
*
|
|
10
|
+
* Based on: https://opentelemetry.io/docs/specs/semconv/
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for LLM (Large Language Model) operations
|
|
15
|
+
*
|
|
16
|
+
* Follows Gen AI semantic conventions:
|
|
17
|
+
* https://opentelemetry.io/docs/specs/semconv/gen-ai/
|
|
18
|
+
*/
|
|
19
|
+
interface LLMConfig {
|
|
20
|
+
/** Model name (e.g., 'gpt-4', 'claude-3-opus') */
|
|
21
|
+
model: string;
|
|
22
|
+
/** Operation type */
|
|
23
|
+
operation?: 'chat' | 'completion' | 'embedding';
|
|
24
|
+
/** Model provider (e.g., 'openai', 'anthropic', 'cohere') */
|
|
25
|
+
system?: string;
|
|
26
|
+
/** Additional attributes to add to the span */
|
|
27
|
+
attributes?: Attributes;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for database operations
|
|
31
|
+
*
|
|
32
|
+
* Follows DB semantic conventions:
|
|
33
|
+
* https://opentelemetry.io/docs/specs/semconv/database/
|
|
34
|
+
*/
|
|
35
|
+
interface DBConfig {
|
|
36
|
+
/** Database system (e.g., 'postgresql', 'mongodb', 'redis') */
|
|
37
|
+
system: string;
|
|
38
|
+
/** Operation type (e.g., 'SELECT', 'INSERT', 'find', 'get') */
|
|
39
|
+
operation?: string;
|
|
40
|
+
/** Database name */
|
|
41
|
+
dbName?: string;
|
|
42
|
+
/** Collection/table name */
|
|
43
|
+
collection?: string;
|
|
44
|
+
/** Additional attributes to add to the span */
|
|
45
|
+
attributes?: Attributes;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for HTTP client operations
|
|
49
|
+
*
|
|
50
|
+
* Follows HTTP semantic conventions:
|
|
51
|
+
* https://opentelemetry.io/docs/specs/semconv/http/
|
|
52
|
+
*/
|
|
53
|
+
interface HTTPConfig {
|
|
54
|
+
/** HTTP method (e.g., 'GET', 'POST') */
|
|
55
|
+
method?: string;
|
|
56
|
+
/** Target URL or URL template */
|
|
57
|
+
url?: string;
|
|
58
|
+
/** Additional attributes to add to the span */
|
|
59
|
+
attributes?: Attributes;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Configuration for messaging operations
|
|
63
|
+
*
|
|
64
|
+
* Follows Messaging semantic conventions:
|
|
65
|
+
* https://opentelemetry.io/docs/specs/semconv/messaging/
|
|
66
|
+
*/
|
|
67
|
+
interface MessagingConfig {
|
|
68
|
+
/** Messaging system (e.g., 'kafka', 'rabbitmq', 'sqs') */
|
|
69
|
+
system: string;
|
|
70
|
+
/** Operation type */
|
|
71
|
+
operation?: 'publish' | 'receive' | 'process';
|
|
72
|
+
/** Destination name (queue/topic) */
|
|
73
|
+
destination?: string;
|
|
74
|
+
/** Additional attributes to add to the span */
|
|
75
|
+
attributes?: Attributes;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Trace LLM operations with Gen AI semantic conventions
|
|
79
|
+
*
|
|
80
|
+
* Automatically adds standard attributes for LLM operations:
|
|
81
|
+
* - gen.ai.request.model
|
|
82
|
+
* - gen.ai.operation.name
|
|
83
|
+
* - gen.ai.system
|
|
84
|
+
*
|
|
85
|
+
* **Use Cases:**
|
|
86
|
+
* - Chat completions
|
|
87
|
+
* - Text generation
|
|
88
|
+
* - Embeddings
|
|
89
|
+
* - Multi-step LLM workflows
|
|
90
|
+
*
|
|
91
|
+
* @param config - LLM operation configuration
|
|
92
|
+
* @returns Traced function factory with Gen AI attributes
|
|
93
|
+
*
|
|
94
|
+
* @example Chat completion with OpenAI
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { traceLLM } from 'autotel/semantic-helpers'
|
|
97
|
+
* import OpenAI from 'openai'
|
|
98
|
+
*
|
|
99
|
+
* const openai = new OpenAI()
|
|
100
|
+
*
|
|
101
|
+
* export const generateResponse = traceLLM({
|
|
102
|
+
* model: 'gpt-4-turbo',
|
|
103
|
+
* operation: 'chat',
|
|
104
|
+
* system: 'openai'
|
|
105
|
+
* })(ctx => async (prompt: string) => {
|
|
106
|
+
* const response = await openai.chat.completions.create({
|
|
107
|
+
* model: 'gpt-4-turbo',
|
|
108
|
+
* messages: [{ role: 'user', content: prompt }]
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* // Add usage metrics to span
|
|
112
|
+
* ctx.setAttribute('gen.ai.usage.completion_tokens', response.usage?.completion_tokens)
|
|
113
|
+
* ctx.setAttribute('gen.ai.usage.prompt_tokens', response.usage?.prompt_tokens)
|
|
114
|
+
*
|
|
115
|
+
* return response.choices[0].message.content
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Anthropic Claude with streaming
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { traceLLM } from 'autotel/semantic-helpers'
|
|
122
|
+
* import Anthropic from '@anthropic-ai/sdk'
|
|
123
|
+
*
|
|
124
|
+
* const anthropic = new Anthropic()
|
|
125
|
+
*
|
|
126
|
+
* export const streamResponse = traceLLM({
|
|
127
|
+
* model: 'claude-3-opus-20240229',
|
|
128
|
+
* operation: 'chat',
|
|
129
|
+
* system: 'anthropic'
|
|
130
|
+
* })(ctx => async function* (prompt: string) {
|
|
131
|
+
* const stream = await anthropic.messages.create({
|
|
132
|
+
* model: 'claude-3-opus-20240229',
|
|
133
|
+
* messages: [{ role: 'user', content: prompt }],
|
|
134
|
+
* stream: true,
|
|
135
|
+
* max_tokens: 1024
|
|
136
|
+
* })
|
|
137
|
+
*
|
|
138
|
+
* let totalTokens = 0
|
|
139
|
+
* for await (const event of stream) {
|
|
140
|
+
* if (event.type === 'content_block_delta') {
|
|
141
|
+
* yield event.delta.text
|
|
142
|
+
* }
|
|
143
|
+
* if (event.type === 'message_stop') {
|
|
144
|
+
* ctx.setAttribute('gen.ai.usage.completion_tokens', event.message.usage.output_tokens)
|
|
145
|
+
* totalTokens = event.message.usage.output_tokens
|
|
146
|
+
* }
|
|
147
|
+
* }
|
|
148
|
+
*
|
|
149
|
+
* return totalTokens
|
|
150
|
+
* })
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @example Embeddings
|
|
154
|
+
* ```typescript
|
|
155
|
+
* import { traceLLM } from 'autotel/semantic-helpers'
|
|
156
|
+
* import { OpenAIEmbeddings } from '@langchain/openai'
|
|
157
|
+
*
|
|
158
|
+
* const embeddings = new OpenAIEmbeddings()
|
|
159
|
+
*
|
|
160
|
+
* export const embed = traceLLM({
|
|
161
|
+
* model: 'text-embedding-3-small',
|
|
162
|
+
* operation: 'embedding',
|
|
163
|
+
* system: 'openai'
|
|
164
|
+
* })(ctx => async (text: string) => {
|
|
165
|
+
* const result = await embeddings.embedQuery(text)
|
|
166
|
+
* ctx.setAttribute('gen.ai.response.embedding_length', result.length)
|
|
167
|
+
* return result
|
|
168
|
+
* })
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
declare function traceLLM<TArgs extends unknown[], TReturn>(config: LLMConfig): (fnFactory: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => ((...args: TArgs) => Promise<TReturn>);
|
|
174
|
+
/**
|
|
175
|
+
* Trace database operations with DB semantic conventions
|
|
176
|
+
*
|
|
177
|
+
* Automatically adds standard attributes for database operations:
|
|
178
|
+
* - db.system
|
|
179
|
+
* - db.operation
|
|
180
|
+
* - db.name
|
|
181
|
+
* - db.collection.name (for NoSQL)
|
|
182
|
+
*
|
|
183
|
+
* **Use Cases:**
|
|
184
|
+
* - SQL queries (PostgreSQL, MySQL, SQLite)
|
|
185
|
+
* - NoSQL operations (MongoDB, DynamoDB, Redis)
|
|
186
|
+
* - ORM queries (Prisma, TypeORM, Drizzle)
|
|
187
|
+
*
|
|
188
|
+
* @param config - Database operation configuration
|
|
189
|
+
* @returns Traced function factory with DB attributes
|
|
190
|
+
*
|
|
191
|
+
* @example PostgreSQL query
|
|
192
|
+
* ```typescript
|
|
193
|
+
* import { traceDB } from 'autotel/semantic-helpers'
|
|
194
|
+
* import { pool } from './db'
|
|
195
|
+
*
|
|
196
|
+
* export const getUser = traceDB({
|
|
197
|
+
* system: 'postgresql',
|
|
198
|
+
* operation: 'SELECT',
|
|
199
|
+
* dbName: 'app_db',
|
|
200
|
+
* collection: 'users'
|
|
201
|
+
* })(ctx => async (userId: string) => {
|
|
202
|
+
* const query = 'SELECT * FROM users WHERE id = $1'
|
|
203
|
+
* ctx.setAttribute('db.statement', query)
|
|
204
|
+
*
|
|
205
|
+
* const result = await pool.query(query, [userId])
|
|
206
|
+
* ctx.setAttribute('db.rows_affected', result.rowCount)
|
|
207
|
+
*
|
|
208
|
+
* return result.rows[0]
|
|
209
|
+
* })
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @example MongoDB with Mongoose
|
|
213
|
+
* ```typescript
|
|
214
|
+
* import { traceDB } from 'autotel/semantic-helpers'
|
|
215
|
+
* import { User } from './models/User'
|
|
216
|
+
*
|
|
217
|
+
* export const findUsers = traceDB({
|
|
218
|
+
* system: 'mongodb',
|
|
219
|
+
* operation: 'find',
|
|
220
|
+
* dbName: 'app_db',
|
|
221
|
+
* collection: 'users'
|
|
222
|
+
* })(ctx => async (filter: object) => {
|
|
223
|
+
* ctx.setAttribute('db.mongodb.filter', JSON.stringify(filter))
|
|
224
|
+
*
|
|
225
|
+
* const users = await User.find(filter).limit(100)
|
|
226
|
+
* ctx.setAttribute('db.response.count', users.length)
|
|
227
|
+
*
|
|
228
|
+
* return users
|
|
229
|
+
* })
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example Redis operations
|
|
233
|
+
* ```typescript
|
|
234
|
+
* import { traceDB } from 'autotel/semantic-helpers'
|
|
235
|
+
* import { redis } from './redis'
|
|
236
|
+
*
|
|
237
|
+
* export const cacheGet = traceDB({
|
|
238
|
+
* system: 'redis',
|
|
239
|
+
* operation: 'GET'
|
|
240
|
+
* })(ctx => async (key: string) => {
|
|
241
|
+
* ctx.setAttribute('db.redis.key', key)
|
|
242
|
+
*
|
|
243
|
+
* const value = await redis.get(key)
|
|
244
|
+
* ctx.setAttribute('db.response.cache_hit', value !== null)
|
|
245
|
+
*
|
|
246
|
+
* return value
|
|
247
|
+
* })
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example Prisma with detailed query info
|
|
251
|
+
* ```typescript
|
|
252
|
+
* import { traceDB } from 'autotel/semantic-helpers'
|
|
253
|
+
* import { prisma } from './prisma'
|
|
254
|
+
*
|
|
255
|
+
* export const createPost = traceDB({
|
|
256
|
+
* system: 'postgresql',
|
|
257
|
+
* operation: 'INSERT',
|
|
258
|
+
* dbName: 'app_db',
|
|
259
|
+
* collection: 'posts'
|
|
260
|
+
* })(ctx => async (data: { title: string; content: string; authorId: string }) => {
|
|
261
|
+
* ctx.setAttribute('db.prisma.model', 'Post')
|
|
262
|
+
* ctx.setAttribute('db.prisma.action', 'create')
|
|
263
|
+
*
|
|
264
|
+
* const post = await prisma.post.create({ data })
|
|
265
|
+
*
|
|
266
|
+
* ctx.setAttribute('db.response.id', post.id)
|
|
267
|
+
* return post
|
|
268
|
+
* })
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
declare function traceDB<TArgs extends unknown[], TReturn>(config: DBConfig): (fnFactory: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => ((...args: TArgs) => Promise<TReturn>);
|
|
274
|
+
/**
|
|
275
|
+
* Trace HTTP client operations with HTTP semantic conventions
|
|
276
|
+
*
|
|
277
|
+
* Automatically adds standard attributes for HTTP requests:
|
|
278
|
+
* - http.request.method
|
|
279
|
+
* - url.full
|
|
280
|
+
*
|
|
281
|
+
* **Use Cases:**
|
|
282
|
+
* - External API calls
|
|
283
|
+
* - Microservice communication
|
|
284
|
+
* - Third-party integrations
|
|
285
|
+
*
|
|
286
|
+
* @param config - HTTP operation configuration
|
|
287
|
+
* @returns Traced function factory with HTTP attributes
|
|
288
|
+
*
|
|
289
|
+
* @example Fetch API
|
|
290
|
+
* ```typescript
|
|
291
|
+
* import { traceHTTP } from 'autotel/semantic-helpers'
|
|
292
|
+
*
|
|
293
|
+
* export const fetchUser = traceHTTP({
|
|
294
|
+
* method: 'GET',
|
|
295
|
+
* url: 'https://api.example.com/users/:id'
|
|
296
|
+
* })(ctx => async (userId: string) => {
|
|
297
|
+
* const url = `https://api.example.com/users/${userId}`
|
|
298
|
+
* ctx.setAttribute('url.full', url)
|
|
299
|
+
*
|
|
300
|
+
* const response = await fetch(url)
|
|
301
|
+
* ctx.setAttribute('http.response.status_code', response.status)
|
|
302
|
+
*
|
|
303
|
+
* if (!response.ok) {
|
|
304
|
+
* ctx.setAttribute('error', true)
|
|
305
|
+
* throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
|
306
|
+
* }
|
|
307
|
+
*
|
|
308
|
+
* return response.json()
|
|
309
|
+
* })
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* @example Axios with retry logic
|
|
313
|
+
* ```typescript
|
|
314
|
+
* import { traceHTTP } from 'autotel/semantic-helpers'
|
|
315
|
+
* import axios from 'axios'
|
|
316
|
+
*
|
|
317
|
+
* export const sendWebhook = traceHTTP({
|
|
318
|
+
* method: 'POST',
|
|
319
|
+
* url: 'https://webhook.example.com/events'
|
|
320
|
+
* })(ctx => async (payload: object) => {
|
|
321
|
+
* let attempts = 0
|
|
322
|
+
* const maxAttempts = 3
|
|
323
|
+
*
|
|
324
|
+
* while (attempts < maxAttempts) {
|
|
325
|
+
* try {
|
|
326
|
+
* attempts++
|
|
327
|
+
* ctx.setAttribute('http.request.resend_count', attempts - 1)
|
|
328
|
+
*
|
|
329
|
+
* const response = await axios.post('https://webhook.example.com/events', payload)
|
|
330
|
+
* ctx.setAttribute('http.response.status_code', response.status)
|
|
331
|
+
* return response.data
|
|
332
|
+
* } catch (error) {
|
|
333
|
+
* if (attempts >= maxAttempts) throw error
|
|
334
|
+
* await new Promise(resolve => setTimeout(resolve, 1000 * attempts))
|
|
335
|
+
* }
|
|
336
|
+
* }
|
|
337
|
+
* })
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @public
|
|
341
|
+
*/
|
|
342
|
+
declare function traceHTTP<TArgs extends unknown[], TReturn>(config: HTTPConfig): (fnFactory: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => ((...args: TArgs) => Promise<TReturn>);
|
|
343
|
+
/**
|
|
344
|
+
* Trace messaging operations with Messaging semantic conventions
|
|
345
|
+
*
|
|
346
|
+
* Automatically adds standard attributes for messaging:
|
|
347
|
+
* - messaging.system
|
|
348
|
+
* - messaging.operation
|
|
349
|
+
* - messaging.destination.name
|
|
350
|
+
*
|
|
351
|
+
* **Use Cases:**
|
|
352
|
+
* - Publishing messages to queues/topics
|
|
353
|
+
* - Consuming messages from queues/topics
|
|
354
|
+
* - Event-driven architectures
|
|
355
|
+
*
|
|
356
|
+
* @param config - Messaging operation configuration
|
|
357
|
+
* @returns Traced function factory with Messaging attributes
|
|
358
|
+
*
|
|
359
|
+
* @example Publishing to Kafka
|
|
360
|
+
* ```typescript
|
|
361
|
+
* import { traceMessaging } from 'autotel/semantic-helpers'
|
|
362
|
+
* import { kafka } from './kafka'
|
|
363
|
+
*
|
|
364
|
+
* const producer = kafka.producer()
|
|
365
|
+
*
|
|
366
|
+
* export const publishEvent = traceMessaging({
|
|
367
|
+
* system: 'kafka',
|
|
368
|
+
* operation: 'publish',
|
|
369
|
+
* destination: 'user-events'
|
|
370
|
+
* })(ctx => async (event: { type: string; userId: string; data: object }) => {
|
|
371
|
+
* ctx.setAttribute('messaging.message.type', event.type)
|
|
372
|
+
* ctx.setAttribute('messaging.kafka.partition', 0)
|
|
373
|
+
*
|
|
374
|
+
* await producer.send({
|
|
375
|
+
* topic: 'user-events',
|
|
376
|
+
* messages: [
|
|
377
|
+
* {
|
|
378
|
+
* key: event.userId,
|
|
379
|
+
* value: JSON.stringify(event.data)
|
|
380
|
+
* }
|
|
381
|
+
* ]
|
|
382
|
+
* })
|
|
383
|
+
*
|
|
384
|
+
* ctx.setAttribute('messaging.message.id', event.userId)
|
|
385
|
+
* })
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @example Consuming from RabbitMQ
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { traceMessaging } from 'autotel/semantic-helpers'
|
|
391
|
+
* import { channel } from './rabbitmq'
|
|
392
|
+
*
|
|
393
|
+
* export const processOrder = traceMessaging({
|
|
394
|
+
* system: 'rabbitmq',
|
|
395
|
+
* operation: 'process',
|
|
396
|
+
* destination: 'orders'
|
|
397
|
+
* })(ctx => async (message: { orderId: string; items: object[] }) => {
|
|
398
|
+
* ctx.setAttribute('messaging.message.id', message.orderId)
|
|
399
|
+
* ctx.setAttribute('messaging.message.body.size', JSON.stringify(message).length)
|
|
400
|
+
*
|
|
401
|
+
* // Process order logic
|
|
402
|
+
* const result = await processOrderInternal(message)
|
|
403
|
+
*
|
|
404
|
+
* ctx.setAttribute('messaging.operation.result', 'success')
|
|
405
|
+
* return result
|
|
406
|
+
* })
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* @example AWS SQS with batch processing
|
|
410
|
+
* ```typescript
|
|
411
|
+
* import { traceMessaging } from 'autotel/semantic-helpers'
|
|
412
|
+
* import { SQS } from '@aws-sdk/client-sqs'
|
|
413
|
+
*
|
|
414
|
+
* const sqs = new SQS()
|
|
415
|
+
*
|
|
416
|
+
* export const sendBatch = traceMessaging({
|
|
417
|
+
* system: 'aws_sqs',
|
|
418
|
+
* operation: 'publish',
|
|
419
|
+
* destination: 'notifications-queue'
|
|
420
|
+
* })(ctx => async (messages: Array<{ id: string; body: object }>) => {
|
|
421
|
+
* ctx.setAttribute('messaging.batch.message_count', messages.length)
|
|
422
|
+
*
|
|
423
|
+
* const result = await sqs.sendMessageBatch({
|
|
424
|
+
* QueueUrl: process.env.QUEUE_URL,
|
|
425
|
+
* Entries: messages.map(msg => ({
|
|
426
|
+
* Id: msg.id,
|
|
427
|
+
* MessageBody: JSON.stringify(msg.body)
|
|
428
|
+
* }))
|
|
429
|
+
* })
|
|
430
|
+
*
|
|
431
|
+
* ctx.setAttribute('messaging.operation.success_count', result.Successful?.length || 0)
|
|
432
|
+
* ctx.setAttribute('messaging.operation.failed_count', result.Failed?.length || 0)
|
|
433
|
+
*
|
|
434
|
+
* return result
|
|
435
|
+
* })
|
|
436
|
+
* ```
|
|
437
|
+
*
|
|
438
|
+
* @public
|
|
439
|
+
*/
|
|
440
|
+
declare function traceMessaging<TArgs extends unknown[], TReturn>(config: MessagingConfig): (fnFactory: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => ((...args: TArgs) => Promise<TReturn>);
|
|
441
|
+
|
|
442
|
+
export { type DBConfig, type HTTPConfig, type LLMConfig, type MessagingConfig, traceDB, traceHTTP, traceLLM, traceMessaging };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { traceDB, traceHTTP, traceLLM, traceMessaging } from './chunk-BWYGJKRB.js';
|
|
2
|
+
import './chunk-RJYY7BWX.js';
|
|
3
|
+
import './chunk-M4ANN7RL.js';
|
|
4
|
+
import './chunk-HCCXC7XG.js';
|
|
5
|
+
import './chunk-UL33I6IS.js';
|
|
6
|
+
import './chunk-3HENGDW2.js';
|
|
7
|
+
import './chunk-X4RMFFMR.js';
|
|
8
|
+
import './chunk-5R2M36QB.js';
|
|
9
|
+
import './chunk-5GWX5LFW.js';
|
|
10
|
+
import './chunk-KVGNW3FC.js';
|
|
11
|
+
import './chunk-P6JUDYNO.js';
|
|
12
|
+
import './chunk-Z6ZWNWWR.js';
|
|
13
|
+
//# sourceMappingURL=semantic-helpers.js.map
|
|
14
|
+
//# sourceMappingURL=semantic-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"semantic-helpers.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGVLK7YUU_cjs = require('./chunk-GVLK7YUU.cjs');
|
|
4
|
+
require('./chunk-G7VZBCD6.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "TailSamplingSpanProcessor", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkGVLK7YUU_cjs.TailSamplingSpanProcessor; }
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=tail-sampling-processor.cjs.map
|
|
13
|
+
//# sourceMappingURL=tail-sampling-processor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"tail-sampling-processor.cjs"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SpanProcessor, Span, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
import { Context } from '@opentelemetry/api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tail Sampling Span Processor
|
|
6
|
+
*
|
|
7
|
+
* Filters spans based on the `sampling.tail.keep` attribute set during execution.
|
|
8
|
+
* This enables adaptive sampling where we decide whether to keep a span AFTER
|
|
9
|
+
* the operation completes, based on criteria like errors, duration, etc.
|
|
10
|
+
*
|
|
11
|
+
* How it works:
|
|
12
|
+
* 1. Decorator creates span optimistically (head sampling returns true)
|
|
13
|
+
* 2. Operation executes and completes
|
|
14
|
+
* 3. Decorator calls shouldKeepTrace() and sets sampling.tail.keep attribute
|
|
15
|
+
* 4. This processor checks the attribute and drops spans marked as false
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare class TailSamplingSpanProcessor implements SpanProcessor {
|
|
19
|
+
private wrappedProcessor;
|
|
20
|
+
constructor(wrappedProcessor: SpanProcessor);
|
|
21
|
+
onStart(span: Span, parentContext: Context): void;
|
|
22
|
+
onEnd(span: ReadableSpan): void;
|
|
23
|
+
forceFlush(): Promise<void>;
|
|
24
|
+
shutdown(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { TailSamplingSpanProcessor };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SpanProcessor, Span, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
import { Context } from '@opentelemetry/api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tail Sampling Span Processor
|
|
6
|
+
*
|
|
7
|
+
* Filters spans based on the `sampling.tail.keep` attribute set during execution.
|
|
8
|
+
* This enables adaptive sampling where we decide whether to keep a span AFTER
|
|
9
|
+
* the operation completes, based on criteria like errors, duration, etc.
|
|
10
|
+
*
|
|
11
|
+
* How it works:
|
|
12
|
+
* 1. Decorator creates span optimistically (head sampling returns true)
|
|
13
|
+
* 2. Operation executes and completes
|
|
14
|
+
* 3. Decorator calls shouldKeepTrace() and sets sampling.tail.keep attribute
|
|
15
|
+
* 4. This processor checks the attribute and drops spans marked as false
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare class TailSamplingSpanProcessor implements SpanProcessor {
|
|
19
|
+
private wrappedProcessor;
|
|
20
|
+
constructor(wrappedProcessor: SpanProcessor);
|
|
21
|
+
onStart(span: Span, parentContext: Context): void;
|
|
22
|
+
onEnd(span: ReadableSpan): void;
|
|
23
|
+
forceFlush(): Promise<void>;
|
|
24
|
+
shutdown(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { TailSamplingSpanProcessor };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"tail-sampling-processor.js"}
|