@pingops/sdk 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/README.md +157 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/init-state.d.ts +17 -0
- package/dist/init-state.d.ts.map +1 -0
- package/dist/init-state.js +22 -0
- package/dist/init-state.js.map +1 -0
- package/dist/initialize.d.ts +20 -0
- package/dist/initialize.d.ts.map +1 -0
- package/dist/initialize.js +86 -0
- package/dist/initialize.js.map +1 -0
- package/dist/instrumentation.d.ts +14 -0
- package/dist/instrumentation.d.ts.map +1 -0
- package/dist/instrumentation.js +76 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/logger.d.ts +25 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +40 -0
- package/dist/logger.js.map +1 -0
- package/dist/pingops.d.ts +85 -0
- package/dist/pingops.d.ts.map +1 -0
- package/dist/pingops.js +259 -0
- package/dist/pingops.js.map +1 -0
- package/dist/span-wrapper.d.ts +60 -0
- package/dist/span-wrapper.d.ts.map +1 -0
- package/dist/span-wrapper.js +118 -0
- package/dist/span-wrapper.js.map +1 -0
- package/dist/tracer-provider.d.ts +175 -0
- package/dist/tracer-provider.d.ts.map +1 -0
- package/dist/tracer-provider.js +537 -0
- package/dist/tracer-provider.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracer Provider with global state and isolated TracerProvider architecture
|
|
3
|
+
*
|
|
4
|
+
* This module provides an isolated TracerProvider that shares the same
|
|
5
|
+
* span processors (like PingopsSpanProcessor) with the main OpenTelemetry SDK.
|
|
6
|
+
* This ensures manual spans created via startSpan are properly processed.
|
|
7
|
+
*
|
|
8
|
+
* Architecture follows Langfuse's pattern with global state management.
|
|
9
|
+
*/
|
|
10
|
+
import { context, SpanKind, SpanStatusCode, trace } from '@opentelemetry/api';
|
|
11
|
+
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
12
|
+
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
13
|
+
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
14
|
+
import { createLogger } from '@pingops/core';
|
|
15
|
+
import { PINGOPS_PARENT_SPAN_ATTRIBUTES_KEY } from '@pingops/core';
|
|
16
|
+
/**
|
|
17
|
+
* Global symbol for PingOps state
|
|
18
|
+
*/
|
|
19
|
+
const PINGOPS_GLOBAL_SYMBOL = Symbol.for('pingops');
|
|
20
|
+
/**
|
|
21
|
+
* Logger instance for tracer provider
|
|
22
|
+
*/
|
|
23
|
+
const log = createLogger('[PingOps TracerProvider]');
|
|
24
|
+
/**
|
|
25
|
+
* Creates initial global state
|
|
26
|
+
*/
|
|
27
|
+
function createState() {
|
|
28
|
+
return {
|
|
29
|
+
isolatedTracerProvider: null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the global state, creating it if it doesn't exist
|
|
34
|
+
*/
|
|
35
|
+
function getGlobalState() {
|
|
36
|
+
const initialState = createState();
|
|
37
|
+
try {
|
|
38
|
+
const g = globalThis;
|
|
39
|
+
if (typeof g !== 'object' || g === null) {
|
|
40
|
+
// Fallback if globalThis is not available
|
|
41
|
+
log.warn('globalThis is not available, using fallback state');
|
|
42
|
+
return initialState;
|
|
43
|
+
}
|
|
44
|
+
if (!g[PINGOPS_GLOBAL_SYMBOL]) {
|
|
45
|
+
log.debug('Creating new global state');
|
|
46
|
+
Object.defineProperty(g, PINGOPS_GLOBAL_SYMBOL, {
|
|
47
|
+
value: initialState,
|
|
48
|
+
writable: false, // lock the slot (not the contents)
|
|
49
|
+
configurable: false,
|
|
50
|
+
enumerable: false,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
log.debug('Retrieved existing global state');
|
|
55
|
+
}
|
|
56
|
+
return g[PINGOPS_GLOBAL_SYMBOL];
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
log.error('Failed to access global state:', err instanceof Error ? err.message : String(err));
|
|
60
|
+
// Fallback on error
|
|
61
|
+
return initialState;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sets an isolated TracerProvider for PingOps tracing operations.
|
|
66
|
+
*
|
|
67
|
+
* This allows PingOps to use its own TracerProvider instance, separate from
|
|
68
|
+
* the global OpenTelemetry TracerProvider. This is useful for avoiding conflicts
|
|
69
|
+
* with other OpenTelemetry instrumentation in the application.
|
|
70
|
+
*
|
|
71
|
+
* @param provider - The TracerProvider instance to use, or null to clear the isolated provider
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export function setPingopsTracerProvider(provider) {
|
|
75
|
+
const state = getGlobalState();
|
|
76
|
+
const hadProvider = state.isolatedTracerProvider !== null;
|
|
77
|
+
state.isolatedTracerProvider = provider;
|
|
78
|
+
if (provider) {
|
|
79
|
+
log.info('Set isolated TracerProvider', {
|
|
80
|
+
hadPrevious: hadProvider,
|
|
81
|
+
providerType: provider.constructor.name,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
log.info('Cleared isolated TracerProvider', { hadPrevious: hadProvider });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the TracerProvider for PingOps tracing operations.
|
|
90
|
+
*
|
|
91
|
+
* Returns the isolated TracerProvider if one has been set via setPingopsTracerProvider(),
|
|
92
|
+
* otherwise falls back to the global OpenTelemetry TracerProvider.
|
|
93
|
+
*
|
|
94
|
+
* @returns The TracerProvider instance to use for PingOps tracing
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export function getPingopsTracerProvider() {
|
|
98
|
+
const { isolatedTracerProvider } = getGlobalState();
|
|
99
|
+
if (isolatedTracerProvider) {
|
|
100
|
+
log.debug('Using isolated TracerProvider', {
|
|
101
|
+
providerType: isolatedTracerProvider.constructor.name,
|
|
102
|
+
});
|
|
103
|
+
return isolatedTracerProvider;
|
|
104
|
+
}
|
|
105
|
+
const globalProvider = trace.getTracerProvider();
|
|
106
|
+
log.debug('Using global TracerProvider', {
|
|
107
|
+
providerType: globalProvider.constructor.name,
|
|
108
|
+
});
|
|
109
|
+
return globalProvider;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the OpenTelemetry tracer instance for PingOps.
|
|
113
|
+
*
|
|
114
|
+
* This function returns a tracer specifically configured for PingOps
|
|
115
|
+
* with the correct tracer name and version.
|
|
116
|
+
*
|
|
117
|
+
* @returns The PingOps OpenTelemetry tracer instance
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
function getPingopsTracer() {
|
|
121
|
+
const provider = getPingopsTracerProvider();
|
|
122
|
+
const tracer = provider.getTracer('@pingops/sdk', '0.1.0');
|
|
123
|
+
log.debug('Retrieved PingOps tracer', {
|
|
124
|
+
tracerName: '@pingops/sdk',
|
|
125
|
+
version: '0.1.0',
|
|
126
|
+
});
|
|
127
|
+
return tracer;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Initializes the isolated TracerProvider with the given span processors
|
|
131
|
+
*
|
|
132
|
+
* This creates a separate TracerProvider that shares the same span processors
|
|
133
|
+
* (like PingopsSpanProcessor) with the main SDK. This ensures manual spans
|
|
134
|
+
* are processed correctly.
|
|
135
|
+
*
|
|
136
|
+
* @param spanProcessors - Array of span processors to use (e.g., PingopsSpanProcessor)
|
|
137
|
+
* @param serviceName - Service name for resource attributes
|
|
138
|
+
* @deprecated Use setPingopsTracerProvider instead
|
|
139
|
+
*/
|
|
140
|
+
export function initializeTracerProvider(spanProcessors, serviceName) {
|
|
141
|
+
log.info('Initializing TracerProvider', {
|
|
142
|
+
serviceName,
|
|
143
|
+
spanProcessorCount: spanProcessors.length,
|
|
144
|
+
});
|
|
145
|
+
// Create resource with service name
|
|
146
|
+
const resource = resourceFromAttributes({
|
|
147
|
+
[ATTR_SERVICE_NAME]: serviceName,
|
|
148
|
+
});
|
|
149
|
+
log.debug('Created resource', { serviceName });
|
|
150
|
+
// In version 2.2.0, span processors are passed in the constructor
|
|
151
|
+
const tracerProvider = new NodeTracerProvider({
|
|
152
|
+
resource,
|
|
153
|
+
spanProcessors,
|
|
154
|
+
});
|
|
155
|
+
log.debug('Created NodeTracerProvider', {
|
|
156
|
+
spanProcessorCount: spanProcessors.length,
|
|
157
|
+
});
|
|
158
|
+
// Register the provider globally
|
|
159
|
+
tracerProvider.register();
|
|
160
|
+
log.info('Registered TracerProvider globally');
|
|
161
|
+
// Set it in global state
|
|
162
|
+
setPingopsTracerProvider(tracerProvider);
|
|
163
|
+
log.info('TracerProvider initialization complete');
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gets the isolated TracerProvider instance
|
|
167
|
+
*
|
|
168
|
+
* @returns The TracerProvider instance, or null if not initialized
|
|
169
|
+
* @deprecated Use getPingopsTracerProvider instead
|
|
170
|
+
*/
|
|
171
|
+
export function getTracerProvider() {
|
|
172
|
+
const provider = getPingopsTracerProvider();
|
|
173
|
+
return provider instanceof NodeTracerProvider ? provider : null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Shuts down the TracerProvider and flushes remaining spans
|
|
177
|
+
*/
|
|
178
|
+
export async function shutdownTracerProvider() {
|
|
179
|
+
log.info('Shutting down TracerProvider');
|
|
180
|
+
const provider = getPingopsTracerProvider();
|
|
181
|
+
// Check if provider has shutdown method (NodeTracerProvider and compatible providers)
|
|
182
|
+
if (provider && typeof provider.shutdown === 'function') {
|
|
183
|
+
log.debug('Calling provider.shutdown()');
|
|
184
|
+
try {
|
|
185
|
+
await provider.shutdown();
|
|
186
|
+
log.info('TracerProvider shutdown complete');
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
log.error('Error during TracerProvider shutdown:', error instanceof Error ? error.message : String(error));
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
log.warn('TracerProvider does not have shutdown method, skipping');
|
|
195
|
+
}
|
|
196
|
+
setPingopsTracerProvider(null);
|
|
197
|
+
log.info('TracerProvider shutdown finished');
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Wraps a promise to automatically end the span when the promise resolves or rejects.
|
|
201
|
+
*
|
|
202
|
+
* @param promise - The promise to wrap
|
|
203
|
+
* @param span - The span to end when promise completes
|
|
204
|
+
* @param endOnExit - Whether to end the span on exit (default: true)
|
|
205
|
+
* @returns The wrapped promise
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
function wrapPromise(promise, span, endOnExit) {
|
|
209
|
+
const spanContext = span.spanContext();
|
|
210
|
+
log.debug('Wrapping promise for span', {
|
|
211
|
+
spanId: spanContext.spanId,
|
|
212
|
+
traceId: spanContext.traceId,
|
|
213
|
+
endOnExit: endOnExit !== false,
|
|
214
|
+
});
|
|
215
|
+
return promise.then((value) => {
|
|
216
|
+
log.debug('Promise resolved, ending span', {
|
|
217
|
+
spanId: spanContext.spanId,
|
|
218
|
+
traceId: spanContext.traceId,
|
|
219
|
+
spanAttributes: span.attributes || {},
|
|
220
|
+
});
|
|
221
|
+
if (endOnExit !== false) {
|
|
222
|
+
span.end();
|
|
223
|
+
}
|
|
224
|
+
return value;
|
|
225
|
+
}, (err) => {
|
|
226
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
227
|
+
log.error('Promise rejected, marking span as error', {
|
|
228
|
+
spanId: spanContext.spanId,
|
|
229
|
+
traceId: spanContext.traceId,
|
|
230
|
+
error: errorMessage,
|
|
231
|
+
});
|
|
232
|
+
span.setStatus({
|
|
233
|
+
code: SpanStatusCode.ERROR,
|
|
234
|
+
message: errorMessage,
|
|
235
|
+
});
|
|
236
|
+
if (err instanceof Error) {
|
|
237
|
+
span.recordException(err);
|
|
238
|
+
}
|
|
239
|
+
if (endOnExit !== false) {
|
|
240
|
+
span.end();
|
|
241
|
+
}
|
|
242
|
+
throw err;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Starts a span, executes the function, and automatically ends the span
|
|
247
|
+
*
|
|
248
|
+
* This function uses the isolated TracerProvider to ensure spans are
|
|
249
|
+
* properly processed by PingopsSpanProcessor and other registered processors.
|
|
250
|
+
*
|
|
251
|
+
* The span is automatically set as active in the OpenTelemetry context, allowing
|
|
252
|
+
* child spans and updates to work correctly.
|
|
253
|
+
*
|
|
254
|
+
* @param name - Span name
|
|
255
|
+
* @param options - Span options including attributes
|
|
256
|
+
* @param fn - Function to execute within the span context (can be sync or async)
|
|
257
|
+
* @returns The result of the function
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* import { startSpan } from '@pingops/sdk';
|
|
262
|
+
*
|
|
263
|
+
* const result = await startSpan('your-span-name', {
|
|
264
|
+
* attributes: {
|
|
265
|
+
* customer_id: 'cust_123',
|
|
266
|
+
* correlation_id: 'req_456',
|
|
267
|
+
* },
|
|
268
|
+
* }, async (span) => {
|
|
269
|
+
* const result = await fetch('https://api.example.com');
|
|
270
|
+
* return 'done';
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export function startSpan(name, options, fn) {
|
|
275
|
+
log.info('Starting span', {
|
|
276
|
+
name,
|
|
277
|
+
attributeCount: Object.keys(options.attributes || {}).length,
|
|
278
|
+
hasStartTime: options.startTime !== undefined,
|
|
279
|
+
});
|
|
280
|
+
const tracer = getPingopsTracer();
|
|
281
|
+
const { attributes = {}, startTime } = options;
|
|
282
|
+
// Store initial attributes in context so they propagate to child spans
|
|
283
|
+
const activeContext = context.active();
|
|
284
|
+
const contextWithAttributes = activeContext.setValue(PINGOPS_PARENT_SPAN_ATTRIBUTES_KEY, attributes);
|
|
285
|
+
return context.with(contextWithAttributes, () => {
|
|
286
|
+
return tracer.startActiveSpan(name, {
|
|
287
|
+
kind: SpanKind.CLIENT,
|
|
288
|
+
attributes,
|
|
289
|
+
startTime,
|
|
290
|
+
}, context.active(), (span) => {
|
|
291
|
+
const spanContext = span.spanContext();
|
|
292
|
+
log.debug('Span started', {
|
|
293
|
+
name,
|
|
294
|
+
spanId: spanContext.spanId,
|
|
295
|
+
traceId: spanContext.traceId,
|
|
296
|
+
attributeCount: Object.keys(attributes).length,
|
|
297
|
+
});
|
|
298
|
+
try {
|
|
299
|
+
const result = fn(span);
|
|
300
|
+
if (result instanceof Promise) {
|
|
301
|
+
log.debug('Function returned Promise, wrapping', {
|
|
302
|
+
spanId: spanContext.spanId,
|
|
303
|
+
traceId: spanContext.traceId,
|
|
304
|
+
});
|
|
305
|
+
return wrapPromise(result, span, true);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
log.debug('Function returned sync value, ending span', {
|
|
309
|
+
spanId: spanContext.spanId,
|
|
310
|
+
traceId: spanContext.traceId,
|
|
311
|
+
});
|
|
312
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
313
|
+
span.end();
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
319
|
+
log.error('Error in span execution', {
|
|
320
|
+
name,
|
|
321
|
+
spanId: spanContext.spanId,
|
|
322
|
+
traceId: spanContext.traceId,
|
|
323
|
+
error: errorMessage,
|
|
324
|
+
});
|
|
325
|
+
span.setStatus({
|
|
326
|
+
code: SpanStatusCode.ERROR,
|
|
327
|
+
message: errorMessage,
|
|
328
|
+
});
|
|
329
|
+
if (err instanceof Error) {
|
|
330
|
+
span.recordException(err);
|
|
331
|
+
}
|
|
332
|
+
span.end();
|
|
333
|
+
throw err;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Updates the currently active trace with new attributes.
|
|
340
|
+
*
|
|
341
|
+
* This function finds the currently active OpenTelemetry span and updates
|
|
342
|
+
* it with trace-level attributes. If no active span is found, a warning is logged.
|
|
343
|
+
*
|
|
344
|
+
* @param attributes - Trace attributes to set
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* import { updateActiveTrace } from '@pingops/sdk';
|
|
349
|
+
*
|
|
350
|
+
* // Inside an active span context
|
|
351
|
+
* updateActiveTrace({
|
|
352
|
+
* userId: 'user-123',
|
|
353
|
+
* sessionId: 'session-456',
|
|
354
|
+
* tags: ['production', 'critical'],
|
|
355
|
+
* });
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export function updateActiveTrace(attributes) {
|
|
359
|
+
log.debug('Updating active trace', {
|
|
360
|
+
hasUserId: attributes.userId !== undefined,
|
|
361
|
+
hasSessionId: attributes.sessionId !== undefined,
|
|
362
|
+
hasTags: attributes.tags !== undefined,
|
|
363
|
+
hasMetadata: attributes.metadata !== undefined,
|
|
364
|
+
customAttributeCount: Object.keys(attributes).filter(k => !['userId', 'sessionId', 'tags', 'metadata'].includes(k)).length,
|
|
365
|
+
});
|
|
366
|
+
const span = trace.getActiveSpan();
|
|
367
|
+
if (!span) {
|
|
368
|
+
log.warn('No active span found, skipping trace update');
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const spanContext = span.spanContext();
|
|
372
|
+
log.debug('Found active span for trace update', {
|
|
373
|
+
spanId: spanContext.spanId,
|
|
374
|
+
traceId: spanContext.traceId,
|
|
375
|
+
});
|
|
376
|
+
// Convert trace attributes to OpenTelemetry attributes
|
|
377
|
+
const otelAttributes = {};
|
|
378
|
+
if (attributes.userId !== undefined) {
|
|
379
|
+
otelAttributes['user.id'] = attributes.userId;
|
|
380
|
+
log.debug('Setting user.id', { userId: attributes.userId });
|
|
381
|
+
}
|
|
382
|
+
if (attributes.sessionId !== undefined) {
|
|
383
|
+
otelAttributes['session.id'] = attributes.sessionId;
|
|
384
|
+
log.debug('Setting session.id', { sessionId: attributes.sessionId });
|
|
385
|
+
}
|
|
386
|
+
if (attributes.tags !== undefined) {
|
|
387
|
+
otelAttributes['trace.tags'] = attributes.tags;
|
|
388
|
+
log.debug('Setting trace.tags', { tags: attributes.tags });
|
|
389
|
+
}
|
|
390
|
+
if (attributes.metadata !== undefined) {
|
|
391
|
+
// Flatten metadata with dot notation
|
|
392
|
+
for (const [key, value] of Object.entries(attributes.metadata)) {
|
|
393
|
+
otelAttributes[`trace.metadata.${key}`] =
|
|
394
|
+
typeof value === 'string' ? value : JSON.stringify(value);
|
|
395
|
+
}
|
|
396
|
+
log.debug('Setting trace.metadata', {
|
|
397
|
+
metadataKeys: Object.keys(attributes.metadata),
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
// Add any other custom attributes
|
|
401
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
402
|
+
if (key !== 'userId' &&
|
|
403
|
+
key !== 'sessionId' &&
|
|
404
|
+
key !== 'tags' &&
|
|
405
|
+
key !== 'metadata') {
|
|
406
|
+
otelAttributes[key] = value;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
span.setAttributes(otelAttributes);
|
|
410
|
+
log.info('Updated active trace', {
|
|
411
|
+
spanId: spanContext.spanId,
|
|
412
|
+
traceId: spanContext.traceId,
|
|
413
|
+
attributeCount: Object.keys(otelAttributes).length,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Updates the currently active span with new attributes.
|
|
418
|
+
*
|
|
419
|
+
* This function finds the currently active OpenTelemetry span in the execution context
|
|
420
|
+
* and updates it with span-level attributes. If no active span exists, the update is skipped.
|
|
421
|
+
*
|
|
422
|
+
* @param attributes - Span attributes to update
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* import { startSpan, updateActiveSpan } from '@pingops/sdk';
|
|
427
|
+
*
|
|
428
|
+
* await startSpan('data-processing', {
|
|
429
|
+
* attributes: { step: 'initialization' },
|
|
430
|
+
* }, async (span) => {
|
|
431
|
+
* // Process data...
|
|
432
|
+
* const result = await processData(inputData);
|
|
433
|
+
*
|
|
434
|
+
* // Update with results
|
|
435
|
+
* updateActiveSpan({
|
|
436
|
+
* attributes: { processed_records: result.count },
|
|
437
|
+
* output: { success: true },
|
|
438
|
+
* });
|
|
439
|
+
* });
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
export function updateActiveSpan(attributes) {
|
|
443
|
+
log.debug('Updating active span', {
|
|
444
|
+
hasAttributes: attributes.attributes !== undefined,
|
|
445
|
+
hasInput: attributes.input !== undefined,
|
|
446
|
+
hasOutput: attributes.output !== undefined,
|
|
447
|
+
hasMetadata: attributes.metadata !== undefined,
|
|
448
|
+
customAttributeCount: Object.keys(attributes).filter(k => !['attributes', 'input', 'output', 'metadata'].includes(k)).length,
|
|
449
|
+
});
|
|
450
|
+
const span = trace.getActiveSpan();
|
|
451
|
+
if (!span) {
|
|
452
|
+
log.warn('No active span found, skipping span update');
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const spanContext = span.spanContext();
|
|
456
|
+
log.debug('Found active span for update', {
|
|
457
|
+
spanId: spanContext.spanId,
|
|
458
|
+
traceId: spanContext.traceId,
|
|
459
|
+
});
|
|
460
|
+
const otelAttributes = {};
|
|
461
|
+
// Handle nested attributes object
|
|
462
|
+
if (attributes.attributes) {
|
|
463
|
+
Object.assign(otelAttributes, attributes.attributes);
|
|
464
|
+
log.debug('Added nested attributes', {
|
|
465
|
+
attributeCount: Object.keys(attributes.attributes).length,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
// Handle input/output
|
|
469
|
+
if (attributes.input !== undefined) {
|
|
470
|
+
otelAttributes['span.input'] =
|
|
471
|
+
typeof attributes.input === 'string'
|
|
472
|
+
? attributes.input
|
|
473
|
+
: JSON.stringify(attributes.input);
|
|
474
|
+
log.debug('Setting span.input', {
|
|
475
|
+
inputType: typeof attributes.input,
|
|
476
|
+
inputLength: typeof attributes.input === 'string'
|
|
477
|
+
? attributes.input.length
|
|
478
|
+
: JSON.stringify(attributes.input).length,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (attributes.output !== undefined) {
|
|
482
|
+
otelAttributes['span.output'] =
|
|
483
|
+
typeof attributes.output === 'string'
|
|
484
|
+
? attributes.output
|
|
485
|
+
: JSON.stringify(attributes.output);
|
|
486
|
+
log.debug('Setting span.output', {
|
|
487
|
+
outputType: typeof attributes.output,
|
|
488
|
+
outputLength: typeof attributes.output === 'string'
|
|
489
|
+
? attributes.output.length
|
|
490
|
+
: JSON.stringify(attributes.output).length,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
// Handle metadata
|
|
494
|
+
if (attributes.metadata !== undefined) {
|
|
495
|
+
for (const [key, value] of Object.entries(attributes.metadata)) {
|
|
496
|
+
otelAttributes[`span.metadata.${key}`] =
|
|
497
|
+
typeof value === 'string' ? value : JSON.stringify(value);
|
|
498
|
+
}
|
|
499
|
+
log.debug('Setting span.metadata', {
|
|
500
|
+
metadataKeys: Object.keys(attributes.metadata),
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
// Add any other custom attributes (excluding the special keys)
|
|
504
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
505
|
+
if (key !== 'attributes' &&
|
|
506
|
+
key !== 'input' &&
|
|
507
|
+
key !== 'output' &&
|
|
508
|
+
key !== 'metadata') {
|
|
509
|
+
otelAttributes[key] = value;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
span.setAttributes(otelAttributes);
|
|
513
|
+
// Store attributes in context so they propagate to child spans
|
|
514
|
+
// This allows child spans (like HTTP spans) to inherit parent attributes
|
|
515
|
+
const activeContext = context.active();
|
|
516
|
+
const existingAttributes = activeContext.getValue(PINGOPS_PARENT_SPAN_ATTRIBUTES_KEY);
|
|
517
|
+
const mergedAttributes = existingAttributes
|
|
518
|
+
? { ...existingAttributes, ...otelAttributes }
|
|
519
|
+
: otelAttributes;
|
|
520
|
+
// Update context with merged attributes
|
|
521
|
+
// Note: The context is immutable, so we create a new context with the merged attributes
|
|
522
|
+
// This new context will be used by child spans created after this point
|
|
523
|
+
const updatedContext = activeContext.setValue(PINGOPS_PARENT_SPAN_ATTRIBUTES_KEY, mergedAttributes);
|
|
524
|
+
// Execute in the updated context so future child spans inherit the attributes
|
|
525
|
+
// This is a no-op for the current execution, but ensures the context is set for child spans
|
|
526
|
+
context.with(updatedContext, () => {
|
|
527
|
+
// Context is now updated - child spans created from this point will inherit attributes
|
|
528
|
+
});
|
|
529
|
+
log.info('Updated active span', {
|
|
530
|
+
spanId: spanContext.spanId,
|
|
531
|
+
traceId: spanContext.traceId,
|
|
532
|
+
spanAttributes: span.attributes || {},
|
|
533
|
+
attributes: otelAttributes,
|
|
534
|
+
contextAttributesStored: true,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
//# sourceMappingURL=tracer-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracer-provider.js","sourceRoot":"","sources":["../src/tracer-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAa,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC;AAEnE;;GAEG;AACH,MAAM,qBAAqB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2
|
+
"name": "@pingops/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PingOps SDK for Node.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"pingops",
|
|
13
|
+
"monitoring",
|
|
14
|
+
"observability",
|
|
15
|
+
"opentelemetry",
|
|
16
|
+
"sdk",
|
|
17
|
+
"nodejs"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@opentelemetry/api": "^1.9.0",
|
|
25
|
+
"@opentelemetry/resources": "^2.2.0",
|
|
26
|
+
"@opentelemetry/sdk-node": "^0.208.0",
|
|
27
|
+
"@opentelemetry/sdk-trace-node": "^2.2.0",
|
|
28
|
+
"@opentelemetry/semantic-conventions": "^1.38.0",
|
|
29
|
+
"@pingops/otel": "^0.1.0",
|
|
30
|
+
"@pingops/core": "^0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^20.11.0",
|
|
34
|
+
"typescript": "^5.6.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc --watch",
|
|
39
|
+
"clean": "rm -rf dist"
|
|
40
|
+
}
|
|
41
|
+
}
|