@blaxel/telemetry 0.2.18-dev.148 → 0.2.18-dev.150
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 +1 -50
- package/dist/telemetry_provider.d.ts +0 -5
- package/dist/telemetry_provider.js +5 -112
- package/package.json +2 -2
package/dist/telemetry.js
CHANGED
|
@@ -195,56 +195,7 @@ class TelemetryManager {
|
|
|
195
195
|
core_1.telemetryRegistry.registerProvider(new telemetry_provider_1.OtelTelemetryProvider());
|
|
196
196
|
const httpInstrumentation = new instrumentation_http_1.HttpInstrumentation({
|
|
197
197
|
requireParentforOutgoingSpans: true,
|
|
198
|
-
|
|
199
|
-
startIncomingSpanHook: (request) => {
|
|
200
|
-
const headers = request.headers;
|
|
201
|
-
const traceparent = headers?.traceparent;
|
|
202
|
-
const tracestate = headers?.tracestate;
|
|
203
|
-
if (traceparent) {
|
|
204
|
-
core_1.logger.debug("Incoming request with traceparent header", {
|
|
205
|
-
traceparent,
|
|
206
|
-
tracestate,
|
|
207
|
-
url: request.url,
|
|
208
|
-
method: request.method,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
core_1.logger.debug("Incoming request without traceparent header", {
|
|
213
|
-
url: request.url,
|
|
214
|
-
method: request.method,
|
|
215
|
-
headers: Object.keys(headers || {}),
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
// Return attributes object as expected by the hook
|
|
219
|
-
return {};
|
|
220
|
-
},
|
|
221
|
-
startOutgoingSpanHook: (request) => {
|
|
222
|
-
core_1.logger.debug("Starting outgoing request span", {
|
|
223
|
-
path: request.path,
|
|
224
|
-
method: request.method,
|
|
225
|
-
});
|
|
226
|
-
// Return attributes object as expected by the hook
|
|
227
|
-
return {};
|
|
228
|
-
},
|
|
229
|
-
// Add additional hooks for debugging
|
|
230
|
-
responseHook: (span, response) => {
|
|
231
|
-
const statusCode = "statusCode" in response ? response.statusCode : undefined;
|
|
232
|
-
const headers = "headers" in response ? response.headers : undefined;
|
|
233
|
-
core_1.logger.debug("HTTP response received", {
|
|
234
|
-
statusCode,
|
|
235
|
-
headers: headers ? Object.keys(headers) : [],
|
|
236
|
-
});
|
|
237
|
-
},
|
|
238
|
-
requestHook: (span, request) => {
|
|
239
|
-
const url = "url" in request ? request.url : undefined;
|
|
240
|
-
const method = "method" in request ? request.method : undefined;
|
|
241
|
-
const headers = "headers" in request ? request.headers : undefined;
|
|
242
|
-
core_1.logger.debug("HTTP request being made", {
|
|
243
|
-
url,
|
|
244
|
-
method,
|
|
245
|
-
headers: headers ? Object.keys(headers) : [],
|
|
246
|
-
});
|
|
247
|
-
},
|
|
198
|
+
requireParentforIncomingSpans: true,
|
|
248
199
|
});
|
|
249
200
|
(0, instrumentation_1.registerInstrumentations)({
|
|
250
201
|
instrumentations: [httpInstrumentation],
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { BlaxelSpan, BlaxelSpanOptions, BlaxelTelemetryProvider } from "@blaxel/core";
|
|
2
2
|
export declare class OtelTelemetryProvider implements BlaxelTelemetryProvider {
|
|
3
3
|
startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
|
|
4
|
-
/**
|
|
5
|
-
* Extract context from headers manually
|
|
6
|
-
* This can be used when automatic context propagation isn't working
|
|
7
|
-
*/
|
|
8
|
-
extractContextFromHeaders(headers: Record<string, string | string[]>): unknown;
|
|
9
4
|
flush(): Promise<void>;
|
|
10
5
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OtelTelemetryProvider = void 0;
|
|
4
|
-
const core_1 = require("@blaxel/core");
|
|
5
4
|
const api_1 = require("@opentelemetry/api");
|
|
6
5
|
const telemetry_1 = require("./telemetry");
|
|
7
6
|
class OtelSpan {
|
|
@@ -36,126 +35,20 @@ class OtelTelemetryProvider {
|
|
|
36
35
|
startSpan(name, options) {
|
|
37
36
|
// Use the tracer from the registered NodeTracerProvider
|
|
38
37
|
const tracer = api_1.trace.getTracer("blaxel");
|
|
39
|
-
// Get the current active context
|
|
40
|
-
let ctx = api_1.context.active();
|
|
41
|
-
const activeSpan = api_1.trace.getActiveSpan();
|
|
42
|
-
// Log context information for debugging
|
|
43
|
-
if (activeSpan) {
|
|
44
|
-
const spanContext = activeSpan.spanContext();
|
|
45
|
-
core_1.logger.debug("Creating span with active parent context", {
|
|
46
|
-
spanName: name,
|
|
47
|
-
parentTraceId: spanContext.traceId,
|
|
48
|
-
parentSpanId: spanContext.spanId,
|
|
49
|
-
isRoot: options?.isRoot,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
core_1.logger.debug("Creating span without active parent context", {
|
|
54
|
-
spanName: name,
|
|
55
|
-
isRoot: options?.isRoot,
|
|
56
|
-
contextProvided: !!options?.parentContext,
|
|
57
|
-
});
|
|
58
|
-
// Try to extract context from headers if available in the environment
|
|
59
|
-
// This is a fallback when HttpInstrumentation doesn't set the context properly
|
|
60
|
-
if (typeof globalThis !== "undefined" && globalThis.process?.env) {
|
|
61
|
-
const headers = {};
|
|
62
|
-
// Check if there are any trace headers in the environment
|
|
63
|
-
if (process.env.TRACEPARENT) {
|
|
64
|
-
headers["traceparent"] = process.env.TRACEPARENT;
|
|
65
|
-
}
|
|
66
|
-
if (process.env.TRACESTATE) {
|
|
67
|
-
headers["tracestate"] = process.env.TRACESTATE;
|
|
68
|
-
}
|
|
69
|
-
if (headers.traceparent) {
|
|
70
|
-
core_1.logger.debug("Found traceparent in environment, attempting to extract context", {
|
|
71
|
-
traceparent: headers.traceparent,
|
|
72
|
-
tracestate: headers.tracestate,
|
|
73
|
-
});
|
|
74
|
-
try {
|
|
75
|
-
const extractedContext = api_1.propagation.extract(api_1.context.active(), headers);
|
|
76
|
-
const extractedSpan = api_1.trace.getSpan(extractedContext);
|
|
77
|
-
if (extractedSpan) {
|
|
78
|
-
ctx = extractedContext;
|
|
79
|
-
core_1.logger.debug("Successfully extracted context from traceparent", {
|
|
80
|
-
extractedTraceId: extractedSpan.spanContext().traceId,
|
|
81
|
-
extractedSpanId: extractedSpan.spanContext().spanId,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
core_1.logger.debug("Failed to extract context from traceparent", {
|
|
87
|
-
error: error instanceof Error ? error.message : String(error),
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Handle parent context if provided
|
|
94
|
-
if (options?.parentContext) {
|
|
95
|
-
ctx = options.parentContext;
|
|
96
|
-
core_1.logger.debug("Using provided parent context for span", {
|
|
97
|
-
spanName: name,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
38
|
// Prepare OpenTelemetry span options
|
|
101
39
|
const otelOptions = {
|
|
102
40
|
attributes: options?.attributes,
|
|
103
41
|
root: options?.isRoot,
|
|
104
42
|
};
|
|
43
|
+
// Handle parent context if provided
|
|
44
|
+
let ctx = api_1.context.active();
|
|
45
|
+
if (options?.parentContext) {
|
|
46
|
+
ctx = options.parentContext;
|
|
47
|
+
}
|
|
105
48
|
// Start the span
|
|
106
49
|
const span = tracer.startSpan(name, otelOptions, ctx);
|
|
107
|
-
const spanContext = span.spanContext();
|
|
108
|
-
core_1.logger.debug("Span created successfully", {
|
|
109
|
-
spanName: name,
|
|
110
|
-
traceId: spanContext.traceId,
|
|
111
|
-
spanId: spanContext.spanId,
|
|
112
|
-
isRoot: options?.isRoot,
|
|
113
|
-
});
|
|
114
50
|
return new OtelSpan(span);
|
|
115
51
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Extract context from headers manually
|
|
118
|
-
* This can be used when automatic context propagation isn't working
|
|
119
|
-
*/
|
|
120
|
-
extractContextFromHeaders(headers) {
|
|
121
|
-
try {
|
|
122
|
-
// Normalize headers to string values
|
|
123
|
-
const normalizedHeaders = {};
|
|
124
|
-
Object.entries(headers).forEach(([key, value]) => {
|
|
125
|
-
if (Array.isArray(value)) {
|
|
126
|
-
normalizedHeaders[key.toLowerCase()] = value[0] || "";
|
|
127
|
-
}
|
|
128
|
-
else if (typeof value === "string") {
|
|
129
|
-
normalizedHeaders[key.toLowerCase()] = value;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
core_1.logger.debug("Attempting to extract context from headers", {
|
|
133
|
-
headers: Object.keys(normalizedHeaders),
|
|
134
|
-
traceparent: normalizedHeaders.traceparent,
|
|
135
|
-
tracestate: normalizedHeaders.tracestate,
|
|
136
|
-
});
|
|
137
|
-
const extractedContext = api_1.propagation.extract(api_1.context.active(), normalizedHeaders);
|
|
138
|
-
const extractedSpan = api_1.trace.getSpan(extractedContext);
|
|
139
|
-
if (extractedSpan) {
|
|
140
|
-
const spanContext = extractedSpan.spanContext();
|
|
141
|
-
core_1.logger.debug("Successfully extracted context from headers", {
|
|
142
|
-
traceId: spanContext.traceId,
|
|
143
|
-
spanId: spanContext.spanId,
|
|
144
|
-
});
|
|
145
|
-
return extractedContext;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
core_1.logger.debug("No span found in extracted context");
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
core_1.logger.debug("Failed to extract context from headers", {
|
|
154
|
-
error: error instanceof Error ? error.message : String(error),
|
|
155
|
-
});
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
52
|
async flush() {
|
|
160
53
|
await telemetry_1.blaxelTelemetry.flush();
|
|
161
54
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/telemetry",
|
|
3
|
-
"version": "0.2.18-dev.
|
|
3
|
+
"version": "0.2.18-dev.150",
|
|
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.18-dev.
|
|
74
|
+
"@blaxel/core": "0.2.18-dev.150"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@eslint/js": "^9.26.0",
|