@blaxel/telemetry 0.2.17-dev.121 → 0.2.17-preview.38
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/telemetry.js +0 -83
- package/dist/telemetry_provider.d.ts +2 -0
- package/dist/telemetry_provider.js +17 -39
- package/package.json +2 -2
package/dist/telemetry.js
CHANGED
|
@@ -192,96 +192,15 @@ class TelemetryManager {
|
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
instrumentApp() {
|
|
195
|
-
core_1.logger.debug("Available propagation fields before setup:", api_1.propagation.fields());
|
|
196
195
|
core_1.telemetryRegistry.registerProvider(new telemetry_provider_1.OtelTelemetryProvider());
|
|
197
196
|
const httpInstrumentation = new instrumentation_http_1.HttpInstrumentation({
|
|
198
197
|
requireParentforOutgoingSpans: true,
|
|
199
|
-
requireParentforIncomingSpans: false, // Allow root spans for incoming requests
|
|
200
|
-
ignoreIncomingRequestHook: () => false, // Don't ignore any requests
|
|
201
|
-
ignoreOutgoingRequestHook: () => false, // Don't ignore any requests
|
|
202
|
-
requestHook: (span, request) => {
|
|
203
|
-
// Log incoming headers for debugging
|
|
204
|
-
if ("headers" in request && request.headers) {
|
|
205
|
-
core_1.logger.debug("Incoming HTTP headers:", JSON.stringify(request.headers));
|
|
206
|
-
// Specifically log trace context headers
|
|
207
|
-
const headers = request.headers;
|
|
208
|
-
const traceHeaders = {
|
|
209
|
-
traceparent: headers.traceparent,
|
|
210
|
-
tracestate: headers.tracestate,
|
|
211
|
-
"x-blaxel-authorization": headers["x-blaxel-authorization"],
|
|
212
|
-
"x-blaxel-workspace": headers["x-blaxel-workspace"],
|
|
213
|
-
};
|
|
214
|
-
core_1.logger.debug("Trace context headers:", JSON.stringify(traceHeaders));
|
|
215
|
-
// Manual trace context extraction for debugging
|
|
216
|
-
if (headers.traceparent) {
|
|
217
|
-
try {
|
|
218
|
-
const traceparentValue = Array.isArray(headers.traceparent)
|
|
219
|
-
? headers.traceparent[0]
|
|
220
|
-
: headers.traceparent;
|
|
221
|
-
core_1.logger.debug("Manual traceparent parsing:", traceparentValue);
|
|
222
|
-
// Try to manually parse the traceparent header
|
|
223
|
-
const parts = traceparentValue.split("-");
|
|
224
|
-
if (parts.length === 4) {
|
|
225
|
-
core_1.logger.debug("Traceparent parts:", JSON.stringify({
|
|
226
|
-
version: parts[0],
|
|
227
|
-
traceId: parts[1],
|
|
228
|
-
spanId: parts[2],
|
|
229
|
-
flags: parts[3],
|
|
230
|
-
}));
|
|
231
|
-
// Check if this looks like a valid traceparent
|
|
232
|
-
if (parts[1] !== "00000000000000000000000000000000" &&
|
|
233
|
-
parts[2] !== "0000000000000000") {
|
|
234
|
-
core_1.logger.debug("Traceparent appears valid - extraction should work");
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
core_1.logger.debug("Traceparent contains invalid IDs");
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
// Extract trace context manually to see what should be extracted
|
|
241
|
-
const extractedContext = api_1.propagation.extract(api_1.context.active(), headers);
|
|
242
|
-
const extractedSpan = api_1.trace.getSpan(extractedContext);
|
|
243
|
-
if (extractedSpan) {
|
|
244
|
-
const extractedSpanContext = extractedSpan.spanContext();
|
|
245
|
-
core_1.logger.debug("Manual context extraction result:", JSON.stringify({
|
|
246
|
-
traceId: extractedSpanContext.traceId,
|
|
247
|
-
spanId: extractedSpanContext.spanId,
|
|
248
|
-
traceFlags: extractedSpanContext.traceFlags,
|
|
249
|
-
}));
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
core_1.logger.debug("Manual context extraction failed - no span found");
|
|
253
|
-
core_1.logger.debug("Available propagation fields:", api_1.propagation.fields());
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
core_1.logger.debug("Manual context extraction error:", error);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// Log the span context that was created from the incoming request
|
|
261
|
-
const spanContext = span.spanContext();
|
|
262
|
-
core_1.logger.debug("HTTP span context:", JSON.stringify({
|
|
263
|
-
traceId: spanContext.traceId,
|
|
264
|
-
spanId: spanContext.spanId,
|
|
265
|
-
traceFlags: spanContext.traceFlags,
|
|
266
|
-
}));
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
responseHook: (span) => {
|
|
270
|
-
const spanContext = span.spanContext();
|
|
271
|
-
core_1.logger.debug("HTTP response span context:", JSON.stringify({
|
|
272
|
-
traceId: spanContext.traceId,
|
|
273
|
-
spanId: spanContext.spanId,
|
|
274
|
-
traceFlags: spanContext.traceFlags,
|
|
275
|
-
}));
|
|
276
|
-
},
|
|
277
198
|
});
|
|
278
199
|
(0, instrumentation_1.registerInstrumentations)({
|
|
279
200
|
instrumentations: [httpInstrumentation],
|
|
280
201
|
});
|
|
281
202
|
}
|
|
282
203
|
setExporters() {
|
|
283
|
-
// Log current propagators for debugging
|
|
284
|
-
core_1.logger.debug("Current propagators:", api_1.propagation.fields());
|
|
285
204
|
const resource = new BlaxelResource(this.resourceAttributes);
|
|
286
205
|
const logExporter = this.getLogExporter();
|
|
287
206
|
this.loggerProvider = new sdk_logs_1.LoggerProvider({
|
|
@@ -304,8 +223,6 @@ class TelemetryManager {
|
|
|
304
223
|
],
|
|
305
224
|
});
|
|
306
225
|
this.nodeTracerProvider.register();
|
|
307
|
-
// Ensure W3C trace context propagation is working
|
|
308
|
-
core_1.logger.debug("Propagation fields after tracer registration:", api_1.propagation.fields());
|
|
309
226
|
const metricExporter = this.getMetricExporter();
|
|
310
227
|
this.meterProvider = new sdk_metrics_1.MeterProvider({
|
|
311
228
|
resource,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BlaxelSpan, BlaxelSpanOptions, BlaxelTelemetryProvider } from "@blaxel/core";
|
|
2
2
|
export declare class OtelTelemetryProvider implements BlaxelTelemetryProvider {
|
|
3
|
+
private spans;
|
|
4
|
+
retrieveActiveSpanContext(): import("@opentelemetry/api").Context;
|
|
3
5
|
startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
|
|
4
6
|
flush(): Promise<void>;
|
|
5
7
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OtelTelemetryProvider = void 0;
|
|
4
4
|
const api_1 = require("@opentelemetry/api");
|
|
5
5
|
const telemetry_1 = require("./telemetry");
|
|
6
|
-
const core_1 = require("@blaxel/core");
|
|
7
6
|
class OtelSpan {
|
|
8
7
|
span;
|
|
8
|
+
closed = false;
|
|
9
9
|
constructor(span) {
|
|
10
10
|
this.span = span;
|
|
11
11
|
}
|
|
@@ -21,11 +21,12 @@ class OtelSpan {
|
|
|
21
21
|
}
|
|
22
22
|
setStatus(status, message) {
|
|
23
23
|
this.span.setStatus({
|
|
24
|
-
code: status ===
|
|
24
|
+
code: status === 'ok' ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
|
|
25
25
|
message,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
end() {
|
|
29
|
+
this.closed = true;
|
|
29
30
|
this.span.end();
|
|
30
31
|
}
|
|
31
32
|
getContext() {
|
|
@@ -33,49 +34,26 @@ class OtelSpan {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
class OtelTelemetryProvider {
|
|
37
|
+
spans = [];
|
|
38
|
+
retrieveActiveSpanContext() {
|
|
39
|
+
for (let i = this.spans.length - 1; i >= 0; i--) {
|
|
40
|
+
const span = this.spans[i];
|
|
41
|
+
if (!span.closed) {
|
|
42
|
+
return api_1.trace.setSpanContext(api_1.ROOT_CONTEXT, span.getContext());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return api_1.context.active();
|
|
46
|
+
}
|
|
36
47
|
startSpan(name, options) {
|
|
37
|
-
// Use the tracer from the registered NodeTracerProvider
|
|
38
48
|
const tracer = api_1.trace.getTracer("blaxel");
|
|
39
|
-
// Prepare OpenTelemetry span options
|
|
40
49
|
const otelOptions = {
|
|
41
50
|
attributes: options?.attributes,
|
|
42
51
|
root: options?.isRoot,
|
|
43
52
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
core_1.logger.info(`Creating span "${name}":`, JSON.stringify({
|
|
49
|
-
hasActiveSpan: !!activeSpan,
|
|
50
|
-
activeSpanId: activeSpan?.spanContext().spanId,
|
|
51
|
-
isRoot: options?.isRoot,
|
|
52
|
-
hasParentContext: !!options?.parentContext,
|
|
53
|
-
parentContext: JSON.stringify(options?.parentContext),
|
|
54
|
-
activeContext: JSON.stringify(ctx),
|
|
55
|
-
otelOptions: JSON.stringify(otelOptions),
|
|
56
|
-
activeTraceId: activeSpan?.spanContext().traceId,
|
|
57
|
-
contextKeys: Object.keys(ctx),
|
|
58
|
-
}));
|
|
59
|
-
if (options?.parentContext) {
|
|
60
|
-
// If explicit parent context is provided, use it
|
|
61
|
-
ctx = api_1.trace.setSpanContext(api_1.ROOT_CONTEXT, options.parentContext);
|
|
62
|
-
}
|
|
63
|
-
else if (options?.isRoot) {
|
|
64
|
-
// If explicitly marked as root, use ROOT_CONTEXT
|
|
65
|
-
ctx = api_1.ROOT_CONTEXT;
|
|
66
|
-
}
|
|
67
|
-
// Otherwise, use the active context (default behavior)
|
|
68
|
-
// Start the span with proper context
|
|
69
|
-
const span = tracer.startSpan(name, otelOptions, ctx);
|
|
70
|
-
const otelSpan = new OtelSpan(span);
|
|
71
|
-
// Additional debugging
|
|
72
|
-
const spanContext = span.spanContext();
|
|
73
|
-
core_1.logger.info(`Created span "${name}":`, JSON.stringify({
|
|
74
|
-
spanId: spanContext.spanId,
|
|
75
|
-
traceId: spanContext.traceId,
|
|
76
|
-
parentSpanId: activeSpan?.spanContext().spanId || "none",
|
|
77
|
-
}));
|
|
78
|
-
return otelSpan;
|
|
53
|
+
const ctx = this.retrieveActiveSpanContext();
|
|
54
|
+
const span = new OtelSpan(tracer.startSpan(name, otelOptions, ctx));
|
|
55
|
+
this.spans.push(span);
|
|
56
|
+
return span;
|
|
79
57
|
}
|
|
80
58
|
async flush() {
|
|
81
59
|
await telemetry_1.blaxelTelemetry.flush();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/telemetry",
|
|
3
|
-
"version": "0.2.17-
|
|
3
|
+
"version": "0.2.17-preview.38",
|
|
4
4
|
"description": "Blaxel SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
72
72
|
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
73
73
|
"ai": "^4.3.13",
|
|
74
|
-
"@blaxel/core": "0.2.17-
|
|
74
|
+
"@blaxel/core": "0.2.17-preview.38"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@eslint/js": "^9.26.0",
|