@blaxel/telemetry 0.2.71-dev.101 → 0.2.71-preview.102
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/telemetry.js +0 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/telemetry.js +0 -3
- package/package.json +2 -2
- package/dist/cjs/instrumentation/blaxel_core.js +0 -200
- package/dist/cjs/types/instrumentation/blaxel_core.d.ts +0 -5
- package/dist/esm/instrumentation/blaxel_core.js +0 -197
package/dist/esm/telemetry.js
CHANGED
|
@@ -6,7 +6,6 @@ import { envDetector } from "@opentelemetry/resources";
|
|
|
6
6
|
import { MeterProvider, PeriodicExportingMetricReader, } from "@opentelemetry/sdk-metrics";
|
|
7
7
|
import { AlwaysOnSampler, BatchSpanProcessor, NodeTracerProvider, } from "@opentelemetry/sdk-trace-node";
|
|
8
8
|
import { AuthRefreshingMetricExporter, AuthRefreshingSpanExporter, createMetricExporter, createTraceExporter } from "./auth_refresh_exporters.js";
|
|
9
|
-
import { instrumentBlaxelCore } from "./instrumentation/blaxel_core.js";
|
|
10
9
|
import { OtelTelemetryProvider } from "./telemetry_provider.js";
|
|
11
10
|
export class BlaxelResource {
|
|
12
11
|
attributes;
|
|
@@ -197,8 +196,6 @@ class TelemetryManager {
|
|
|
197
196
|
registerInstrumentations({
|
|
198
197
|
instrumentations: [httpInstrumentation],
|
|
199
198
|
});
|
|
200
|
-
// Instrument @blaxel/core classes via monkey patching
|
|
201
|
-
instrumentBlaxelCore();
|
|
202
199
|
}
|
|
203
200
|
setExporters() {
|
|
204
201
|
const resource = new BlaxelResource(this.resourceAttributes);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/telemetry",
|
|
3
|
-
"version": "0.2.71-
|
|
3
|
+
"version": "0.2.71-preview.102",
|
|
4
4
|
"description": "Blaxel SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@ai-sdk/google": "^2.0.25",
|
|
55
55
|
"@ai-sdk/groq": "^2.0.26",
|
|
56
56
|
"@ai-sdk/openai": "^2.0.57",
|
|
57
|
-
"@blaxel/core": "0.2.71-
|
|
57
|
+
"@blaxel/core": "0.2.71-preview.102",
|
|
58
58
|
"@opentelemetry/api": "^1.9.0",
|
|
59
59
|
"@opentelemetry/api-logs": "^0.200.0",
|
|
60
60
|
"@opentelemetry/exporter-logs-otlp-http": "^0.200.0",
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.instrumentBlaxelCore = instrumentBlaxelCore;
|
|
4
|
-
const core_1 = require("@blaxel/core");
|
|
5
|
-
/**
|
|
6
|
-
* Monkey-patches BlAgent.prototype.run to wrap with telemetry spans.
|
|
7
|
-
*/
|
|
8
|
-
function patchBlAgent() {
|
|
9
|
-
const origRun = core_1.BlAgent.prototype.run;
|
|
10
|
-
core_1.BlAgent.prototype.run = async function (input, headers = {}, params = {}) {
|
|
11
|
-
const span = (0, core_1.startSpan)(this.agentName, {
|
|
12
|
-
attributes: {
|
|
13
|
-
"agent.name": this.agentName,
|
|
14
|
-
"agent.args": JSON.stringify(input),
|
|
15
|
-
"span.type": "agent.run",
|
|
16
|
-
},
|
|
17
|
-
isRoot: false,
|
|
18
|
-
});
|
|
19
|
-
try {
|
|
20
|
-
const result = await origRun.call(this, input, headers, params);
|
|
21
|
-
span.setAttribute("agent.run.result", result);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
catch (err) {
|
|
25
|
-
if (err instanceof Error) {
|
|
26
|
-
span.setAttribute("agent.run.error", err.stack);
|
|
27
|
-
}
|
|
28
|
-
throw err;
|
|
29
|
-
}
|
|
30
|
-
finally {
|
|
31
|
-
span.end();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Monkey-patches BlJob.prototype.run to wrap with telemetry spans.
|
|
37
|
-
*/
|
|
38
|
-
function patchBlJob() {
|
|
39
|
-
const origRun = core_1.BlJob.prototype.run;
|
|
40
|
-
core_1.BlJob.prototype.run = async function (tasks, options) {
|
|
41
|
-
const span = (0, core_1.startSpan)(this.jobName, {
|
|
42
|
-
attributes: {
|
|
43
|
-
"job.name": this.jobName,
|
|
44
|
-
"span.type": "job.run",
|
|
45
|
-
},
|
|
46
|
-
isRoot: false,
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
const result = await origRun.call(this, tasks, options);
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
if (err instanceof Error) {
|
|
54
|
-
span.setAttribute("job.run.error", err.stack);
|
|
55
|
-
}
|
|
56
|
-
throw err;
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
span.end();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Monkey-patches McpTool.prototype.listTools and McpTool.prototype.call
|
|
65
|
-
* to wrap with telemetry spans.
|
|
66
|
-
*/
|
|
67
|
-
function patchMcpTool() {
|
|
68
|
-
const origListTools = core_1.McpTool.prototype.listTools;
|
|
69
|
-
const origCall = core_1.McpTool.prototype.call;
|
|
70
|
-
core_1.McpTool.prototype.listTools = async function () {
|
|
71
|
-
const span = (0, core_1.startSpan)(this.name, {
|
|
72
|
-
attributes: {
|
|
73
|
-
"span.type": "tool.list",
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
try {
|
|
77
|
-
const result = await origListTools.call(this);
|
|
78
|
-
span.setAttribute("tool.list.result", JSON.stringify(result));
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
span.setStatus("error");
|
|
83
|
-
span.recordException(err);
|
|
84
|
-
throw err;
|
|
85
|
-
}
|
|
86
|
-
finally {
|
|
87
|
-
span.end();
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
core_1.McpTool.prototype.call = async function (toolName, args) {
|
|
91
|
-
const span = (0, core_1.startSpan)(this.name + "." + toolName, {
|
|
92
|
-
attributes: {
|
|
93
|
-
"span.type": "tool.call",
|
|
94
|
-
"tool.name": toolName,
|
|
95
|
-
"tool.args": JSON.stringify(args),
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
try {
|
|
99
|
-
const result = await origCall.call(this, toolName, args);
|
|
100
|
-
span.setAttribute("tool.call.result", JSON.stringify(result));
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
catch (err) {
|
|
104
|
-
span.setStatus("error");
|
|
105
|
-
span.recordException(err);
|
|
106
|
-
throw err;
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
span.end();
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Monkey-patches BlaxelMcpServerTransport to add telemetry spans
|
|
115
|
-
* for incoming messages (via onmessage setter) and outgoing messages (via send).
|
|
116
|
-
*/
|
|
117
|
-
function patchMcpServer() {
|
|
118
|
-
// Patch the onmessage setter to wrap the handler with span tracking
|
|
119
|
-
const origDescriptor = Object.getOwnPropertyDescriptor(core_1.BlaxelMcpServerTransport.prototype, "onmessage");
|
|
120
|
-
if (origDescriptor?.set) {
|
|
121
|
-
const origSetter = origDescriptor.set;
|
|
122
|
-
Object.defineProperty(core_1.BlaxelMcpServerTransport.prototype, "onmessage", {
|
|
123
|
-
...origDescriptor,
|
|
124
|
-
set(handler) {
|
|
125
|
-
if (handler) {
|
|
126
|
-
const tracedHandler = async (message) => {
|
|
127
|
-
const messageId = message.id ? String(message.id) : "";
|
|
128
|
-
const [clientId] = messageId.includes(":")
|
|
129
|
-
? messageId.split(":")
|
|
130
|
-
: [undefined];
|
|
131
|
-
const span = (0, core_1.startSpan)("mcp.message", {
|
|
132
|
-
attributes: {
|
|
133
|
-
"span.type": "mcp.message",
|
|
134
|
-
...(clientId ? { "mcp.client.id": clientId } : {}),
|
|
135
|
-
...(message.method
|
|
136
|
-
? { "mcp.method": message.method }
|
|
137
|
-
: {}),
|
|
138
|
-
...(message.params?.name
|
|
139
|
-
? {
|
|
140
|
-
"mcp.toolName": message.params.name,
|
|
141
|
-
}
|
|
142
|
-
: {}),
|
|
143
|
-
},
|
|
144
|
-
isRoot: false,
|
|
145
|
-
});
|
|
146
|
-
try {
|
|
147
|
-
await Promise.resolve(handler(message));
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
span.setStatus("error");
|
|
151
|
-
span.recordException(err);
|
|
152
|
-
throw err;
|
|
153
|
-
}
|
|
154
|
-
finally {
|
|
155
|
-
span.end();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
origSetter.call(this, tracedHandler);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
origSetter.call(this, handler);
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
// Patch the send method to wrap with span tracking
|
|
167
|
-
const origSend = core_1.BlaxelMcpServerTransport.prototype.send;
|
|
168
|
-
core_1.BlaxelMcpServerTransport.prototype.send = async function (msg) {
|
|
169
|
-
const span = (0, core_1.startSpan)("mcp.send", {
|
|
170
|
-
attributes: {
|
|
171
|
-
"span.type": "mcp.send",
|
|
172
|
-
},
|
|
173
|
-
isRoot: false,
|
|
174
|
-
});
|
|
175
|
-
try {
|
|
176
|
-
await origSend.call(this, msg);
|
|
177
|
-
span.setAttributes({
|
|
178
|
-
"mcp.message.response_sent": true,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
span.setStatus("error");
|
|
183
|
-
span.recordException(err);
|
|
184
|
-
throw err;
|
|
185
|
-
}
|
|
186
|
-
finally {
|
|
187
|
-
span.end();
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Instruments all @blaxel/core classes with telemetry via monkey patching.
|
|
193
|
-
* This should be called during telemetry initialization.
|
|
194
|
-
*/
|
|
195
|
-
function instrumentBlaxelCore() {
|
|
196
|
-
patchBlAgent();
|
|
197
|
-
patchBlJob();
|
|
198
|
-
patchMcpTool();
|
|
199
|
-
patchMcpServer();
|
|
200
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { BlAgent, BlaxelMcpServerTransport, BlJob, McpTool, startSpan, } from "@blaxel/core";
|
|
2
|
-
/**
|
|
3
|
-
* Monkey-patches BlAgent.prototype.run to wrap with telemetry spans.
|
|
4
|
-
*/
|
|
5
|
-
function patchBlAgent() {
|
|
6
|
-
const origRun = BlAgent.prototype.run;
|
|
7
|
-
BlAgent.prototype.run = async function (input, headers = {}, params = {}) {
|
|
8
|
-
const span = startSpan(this.agentName, {
|
|
9
|
-
attributes: {
|
|
10
|
-
"agent.name": this.agentName,
|
|
11
|
-
"agent.args": JSON.stringify(input),
|
|
12
|
-
"span.type": "agent.run",
|
|
13
|
-
},
|
|
14
|
-
isRoot: false,
|
|
15
|
-
});
|
|
16
|
-
try {
|
|
17
|
-
const result = await origRun.call(this, input, headers, params);
|
|
18
|
-
span.setAttribute("agent.run.result", result);
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
if (err instanceof Error) {
|
|
23
|
-
span.setAttribute("agent.run.error", err.stack);
|
|
24
|
-
}
|
|
25
|
-
throw err;
|
|
26
|
-
}
|
|
27
|
-
finally {
|
|
28
|
-
span.end();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Monkey-patches BlJob.prototype.run to wrap with telemetry spans.
|
|
34
|
-
*/
|
|
35
|
-
function patchBlJob() {
|
|
36
|
-
const origRun = BlJob.prototype.run;
|
|
37
|
-
BlJob.prototype.run = async function (tasks, options) {
|
|
38
|
-
const span = startSpan(this.jobName, {
|
|
39
|
-
attributes: {
|
|
40
|
-
"job.name": this.jobName,
|
|
41
|
-
"span.type": "job.run",
|
|
42
|
-
},
|
|
43
|
-
isRoot: false,
|
|
44
|
-
});
|
|
45
|
-
try {
|
|
46
|
-
const result = await origRun.call(this, tasks, options);
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
if (err instanceof Error) {
|
|
51
|
-
span.setAttribute("job.run.error", err.stack);
|
|
52
|
-
}
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
span.end();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Monkey-patches McpTool.prototype.listTools and McpTool.prototype.call
|
|
62
|
-
* to wrap with telemetry spans.
|
|
63
|
-
*/
|
|
64
|
-
function patchMcpTool() {
|
|
65
|
-
const origListTools = McpTool.prototype.listTools;
|
|
66
|
-
const origCall = McpTool.prototype.call;
|
|
67
|
-
McpTool.prototype.listTools = async function () {
|
|
68
|
-
const span = startSpan(this.name, {
|
|
69
|
-
attributes: {
|
|
70
|
-
"span.type": "tool.list",
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
try {
|
|
74
|
-
const result = await origListTools.call(this);
|
|
75
|
-
span.setAttribute("tool.list.result", JSON.stringify(result));
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
span.setStatus("error");
|
|
80
|
-
span.recordException(err);
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
span.end();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
McpTool.prototype.call = async function (toolName, args) {
|
|
88
|
-
const span = startSpan(this.name + "." + toolName, {
|
|
89
|
-
attributes: {
|
|
90
|
-
"span.type": "tool.call",
|
|
91
|
-
"tool.name": toolName,
|
|
92
|
-
"tool.args": JSON.stringify(args),
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
try {
|
|
96
|
-
const result = await origCall.call(this, toolName, args);
|
|
97
|
-
span.setAttribute("tool.call.result", JSON.stringify(result));
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
span.setStatus("error");
|
|
102
|
-
span.recordException(err);
|
|
103
|
-
throw err;
|
|
104
|
-
}
|
|
105
|
-
finally {
|
|
106
|
-
span.end();
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Monkey-patches BlaxelMcpServerTransport to add telemetry spans
|
|
112
|
-
* for incoming messages (via onmessage setter) and outgoing messages (via send).
|
|
113
|
-
*/
|
|
114
|
-
function patchMcpServer() {
|
|
115
|
-
// Patch the onmessage setter to wrap the handler with span tracking
|
|
116
|
-
const origDescriptor = Object.getOwnPropertyDescriptor(BlaxelMcpServerTransport.prototype, "onmessage");
|
|
117
|
-
if (origDescriptor?.set) {
|
|
118
|
-
const origSetter = origDescriptor.set;
|
|
119
|
-
Object.defineProperty(BlaxelMcpServerTransport.prototype, "onmessage", {
|
|
120
|
-
...origDescriptor,
|
|
121
|
-
set(handler) {
|
|
122
|
-
if (handler) {
|
|
123
|
-
const tracedHandler = async (message) => {
|
|
124
|
-
const messageId = message.id ? String(message.id) : "";
|
|
125
|
-
const [clientId] = messageId.includes(":")
|
|
126
|
-
? messageId.split(":")
|
|
127
|
-
: [undefined];
|
|
128
|
-
const span = startSpan("mcp.message", {
|
|
129
|
-
attributes: {
|
|
130
|
-
"span.type": "mcp.message",
|
|
131
|
-
...(clientId ? { "mcp.client.id": clientId } : {}),
|
|
132
|
-
...(message.method
|
|
133
|
-
? { "mcp.method": message.method }
|
|
134
|
-
: {}),
|
|
135
|
-
...(message.params?.name
|
|
136
|
-
? {
|
|
137
|
-
"mcp.toolName": message.params.name,
|
|
138
|
-
}
|
|
139
|
-
: {}),
|
|
140
|
-
},
|
|
141
|
-
isRoot: false,
|
|
142
|
-
});
|
|
143
|
-
try {
|
|
144
|
-
await Promise.resolve(handler(message));
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
span.setStatus("error");
|
|
148
|
-
span.recordException(err);
|
|
149
|
-
throw err;
|
|
150
|
-
}
|
|
151
|
-
finally {
|
|
152
|
-
span.end();
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
origSetter.call(this, tracedHandler);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
origSetter.call(this, handler);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
// Patch the send method to wrap with span tracking
|
|
164
|
-
const origSend = BlaxelMcpServerTransport.prototype.send;
|
|
165
|
-
BlaxelMcpServerTransport.prototype.send = async function (msg) {
|
|
166
|
-
const span = startSpan("mcp.send", {
|
|
167
|
-
attributes: {
|
|
168
|
-
"span.type": "mcp.send",
|
|
169
|
-
},
|
|
170
|
-
isRoot: false,
|
|
171
|
-
});
|
|
172
|
-
try {
|
|
173
|
-
await origSend.call(this, msg);
|
|
174
|
-
span.setAttributes({
|
|
175
|
-
"mcp.message.response_sent": true,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
span.setStatus("error");
|
|
180
|
-
span.recordException(err);
|
|
181
|
-
throw err;
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
span.end();
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Instruments all @blaxel/core classes with telemetry via monkey patching.
|
|
190
|
-
* This should be called during telemetry initialization.
|
|
191
|
-
*/
|
|
192
|
-
export function instrumentBlaxelCore() {
|
|
193
|
-
patchBlAgent();
|
|
194
|
-
patchBlJob();
|
|
195
|
-
patchMcpTool();
|
|
196
|
-
patchMcpServer();
|
|
197
|
-
}
|