@brizz/sdk 0.1.44 → 0.1.46
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 +8 -2
- package/dist/{chunk-AELIATPI.js → chunk-USYGGHMA.js} +7 -7
- package/dist/{chunk-A3HH5OUL.cjs → chunk-VFWTFL7E.cjs} +6 -6
- package/dist/index.cjs +462 -65
- package/dist/index.js +433 -36
- package/dist/{mcp-5FSUXYHM.cjs → mcp-M3WRCR7G.cjs} +11 -11
- package/dist/{mcp-7EJXVCPI.js → mcp-YHBVF7QU.js} +1 -1
- package/dist/types/cjs/internal/instrumentation/langchain.d.ts +4 -0
- package/dist/types/cjs/internal/instrumentation/langgraph/attributes.d.ts +38 -0
- package/dist/types/cjs/internal/instrumentation/langgraph/index.d.ts +1 -0
- package/dist/types/cjs/internal/instrumentation/langgraph/instrumentation.d.ts +11 -0
- package/dist/types/cjs/internal/instrumentation/registry.d.ts +1 -0
- package/dist/types/esm/internal/instrumentation/langchain.d.ts +4 -0
- package/dist/types/esm/internal/instrumentation/langgraph/attributes.d.ts +38 -0
- package/dist/types/esm/internal/instrumentation/langgraph/index.d.ts +1 -0
- package/dist/types/esm/internal/instrumentation/langgraph/instrumentation.d.ts +11 -0
- package/dist/types/esm/internal/instrumentation/registry.d.ts +1 -0
- package/package.json +40 -32
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
configure,
|
|
7
7
|
getSDKVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-USYGGHMA.js";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_LOG_LEVEL,
|
|
11
11
|
LogLevel,
|
|
@@ -89,6 +89,294 @@ import { LlamaIndexInstrumentation } from "@traceloop/instrumentation-llamaindex
|
|
|
89
89
|
import { PineconeInstrumentation } from "@traceloop/instrumentation-pinecone";
|
|
90
90
|
import { QdrantInstrumentation } from "@traceloop/instrumentation-qdrant";
|
|
91
91
|
import { TogetherInstrumentation } from "@traceloop/instrumentation-together";
|
|
92
|
+
|
|
93
|
+
// src/internal/instrumentation/langgraph/instrumentation.ts
|
|
94
|
+
import { SpanStatusCode, context, createContextKey, trace } from "@opentelemetry/api";
|
|
95
|
+
import {
|
|
96
|
+
InstrumentationBase,
|
|
97
|
+
InstrumentationNodeModuleDefinition
|
|
98
|
+
} from "@opentelemetry/instrumentation";
|
|
99
|
+
|
|
100
|
+
// src/internal/instrumentation/langgraph/attributes.ts
|
|
101
|
+
var INSTRUMENTATION_NAME = "@brizz/sdk/langgraph";
|
|
102
|
+
var INSTRUMENTATION_VERSION = getSDKVersion();
|
|
103
|
+
var MODULE_NAME = "@langchain/langgraph";
|
|
104
|
+
var SUPPORTED_VERSIONS = [">=0.2.0 <2"];
|
|
105
|
+
var CHECKPOINT_SPAN_NAME = "brizz.langgraph.checkpoint";
|
|
106
|
+
var ATTR_CHECKPOINT_PARENT_ID = "brizz.checkpoint_parent_id";
|
|
107
|
+
var ATTR_CHECKPOINT_ID = "brizz.checkpoint_id";
|
|
108
|
+
var ATTR_CHECKPOINT_NS = "brizz.checkpoint_ns";
|
|
109
|
+
var ATTR_CHECKPOINT_THREAD_ID = "brizz.checkpoint_thread_id";
|
|
110
|
+
function asNonEmptyString(value) {
|
|
111
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
112
|
+
}
|
|
113
|
+
function readCheckpointId(config) {
|
|
114
|
+
return asNonEmptyString(config?.configurable?.checkpoint_id);
|
|
115
|
+
}
|
|
116
|
+
function readCheckpointNs(config) {
|
|
117
|
+
return asNonEmptyString(config?.configurable?.checkpoint_ns);
|
|
118
|
+
}
|
|
119
|
+
function readThreadId(config) {
|
|
120
|
+
return asNonEmptyString(config?.configurable?.thread_id);
|
|
121
|
+
}
|
|
122
|
+
function readWrittenCheckpointId(checkpoint) {
|
|
123
|
+
return asNonEmptyString(checkpoint?.id);
|
|
124
|
+
}
|
|
125
|
+
function resolveCheckpointer(graph, config) {
|
|
126
|
+
const inherited = config?.configurable?.__pregel_checkpointer;
|
|
127
|
+
const candidate = inherited ?? graph.checkpointer;
|
|
128
|
+
return typeof candidate === "object" && candidate !== null ? candidate : void 0;
|
|
129
|
+
}
|
|
130
|
+
function resolvePregelPrototype(module2) {
|
|
131
|
+
if (typeof module2 !== "object" || module2 === null) {
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
134
|
+
const exports2 = module2;
|
|
135
|
+
const direct = exports2["Pregel"]?.prototype;
|
|
136
|
+
if (isPregelPrototype(direct)) {
|
|
137
|
+
return direct;
|
|
138
|
+
}
|
|
139
|
+
for (const name of ["CompiledStateGraph", "CompiledGraph", "MessageGraph"]) {
|
|
140
|
+
let proto = exports2[name]?.prototype;
|
|
141
|
+
while (proto && proto !== Object.prototype) {
|
|
142
|
+
if (isPregelPrototype(proto)) {
|
|
143
|
+
return proto;
|
|
144
|
+
}
|
|
145
|
+
proto = Object.getPrototypeOf(proto);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
function isPregelPrototype(value) {
|
|
151
|
+
if (typeof value !== "object" || value === null) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return typeof value.stream === "function" && typeof value.getState === "function" && Object.prototype.hasOwnProperty.call(value, "stream") && Object.prototype.hasOwnProperty.call(value, "getState");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/internal/instrumentation/langgraph/instrumentation.ts
|
|
158
|
+
var PATCHED_FLAG = /* @__PURE__ */ Symbol.for("brizz.langgraph.patched");
|
|
159
|
+
var CHECKPOINT_SPAN_KEY = createContextKey("brizz.langgraph.checkpoint_span");
|
|
160
|
+
var patchedSavers = /* @__PURE__ */ new WeakSet();
|
|
161
|
+
var parentRecorded = /* @__PURE__ */ new WeakSet();
|
|
162
|
+
var LangGraphInstrumentation = class extends InstrumentationBase {
|
|
163
|
+
constructor(config = {}) {
|
|
164
|
+
super(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION, config);
|
|
165
|
+
}
|
|
166
|
+
init() {
|
|
167
|
+
return [
|
|
168
|
+
new InstrumentationNodeModuleDefinition(
|
|
169
|
+
MODULE_NAME,
|
|
170
|
+
SUPPORTED_VERSIONS,
|
|
171
|
+
(moduleExports) => {
|
|
172
|
+
this.applyPatch(moduleExports);
|
|
173
|
+
return moduleExports;
|
|
174
|
+
},
|
|
175
|
+
(moduleExports) => moduleExports
|
|
176
|
+
)
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Patch a LangGraph module the caller already imported.
|
|
181
|
+
*
|
|
182
|
+
* The module-load hook above only fires for CommonJS requires, so an ESM or
|
|
183
|
+
* bundled consumer reaches the instrumentation through here — via
|
|
184
|
+
* `Brizz.initialize({ instrumentModules: { langgraph } })`. Accepts either
|
|
185
|
+
* the package root or its `pregel` subpath.
|
|
186
|
+
*/
|
|
187
|
+
manuallyInstrument(moduleExports) {
|
|
188
|
+
this.applyPatch(moduleExports);
|
|
189
|
+
}
|
|
190
|
+
applyPatch(moduleExports) {
|
|
191
|
+
const proto = resolvePregelPrototype(moduleExports);
|
|
192
|
+
if (!proto) {
|
|
193
|
+
logger.debug("Brizz LangGraph: module does not expose a Pregel prototype \u2014 skipping patch");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (patchPregelStream(proto, () => this.tracer)) {
|
|
197
|
+
logger.debug("Brizz LangGraph: patched Pregel.stream for checkpoint spans");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
function patchPregelStream(proto, getTracer) {
|
|
202
|
+
const target = proto;
|
|
203
|
+
if (target[PATCHED_FLAG]) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
const originalStream = proto.stream;
|
|
207
|
+
if (typeof originalStream !== "function") {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
proto.stream = async function patchedStream(input, options) {
|
|
211
|
+
const run = beginRun(this, options, getTracer);
|
|
212
|
+
if (!run) {
|
|
213
|
+
return await originalStream.call(this, input, options);
|
|
214
|
+
}
|
|
215
|
+
let stream;
|
|
216
|
+
try {
|
|
217
|
+
stream = await context.with(run.runContext, () => originalStream.call(this, input, options));
|
|
218
|
+
} catch (error) {
|
|
219
|
+
endRun(run, error);
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
return attachRunToIteration(stream, run);
|
|
223
|
+
};
|
|
224
|
+
target[PATCHED_FLAG] = true;
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
function patchSaver(checkpointer) {
|
|
228
|
+
const proto = Object.getPrototypeOf(checkpointer);
|
|
229
|
+
if (!proto || patchedSavers.has(proto)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
patchedSavers.add(proto);
|
|
233
|
+
const originalPut = proto.put;
|
|
234
|
+
if (typeof originalPut !== "function") {
|
|
235
|
+
logger.debug("Brizz LangGraph: checkpointer exposes no put \u2014 checkpoint ids unavailable");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const patchedPut = function brizzPut(config, checkpoint, ...rest) {
|
|
239
|
+
recordCheckpoint(config, checkpoint);
|
|
240
|
+
return originalPut.call(this, config, checkpoint, ...rest);
|
|
241
|
+
};
|
|
242
|
+
proto.put = patchedPut;
|
|
243
|
+
}
|
|
244
|
+
function recordCheckpoint(config, checkpoint) {
|
|
245
|
+
try {
|
|
246
|
+
const span = context.active().getValue(CHECKPOINT_SPAN_KEY);
|
|
247
|
+
if (!span?.isRecording()) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const checkpointId = readWrittenCheckpointId(checkpoint);
|
|
251
|
+
if (checkpointId) {
|
|
252
|
+
span.setAttribute(ATTR_CHECKPOINT_ID, checkpointId);
|
|
253
|
+
}
|
|
254
|
+
if (parentRecorded.has(span)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
parentRecorded.add(span);
|
|
258
|
+
setIfKnown(span, ATTR_CHECKPOINT_PARENT_ID, readCheckpointId(config));
|
|
259
|
+
setIfKnown(span, ATTR_CHECKPOINT_THREAD_ID, readThreadId(config));
|
|
260
|
+
setIfKnown(span, ATTR_CHECKPOINT_NS, readCheckpointNs(config));
|
|
261
|
+
} catch (error) {
|
|
262
|
+
logger.debug(`Brizz LangGraph: could not record a checkpoint write: ${String(error)}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function setIfKnown(span, key, value) {
|
|
266
|
+
if (value) {
|
|
267
|
+
span.setAttribute(key, value);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function beginRun(graph, options, getTracer) {
|
|
271
|
+
try {
|
|
272
|
+
if (!options?.configurable) {
|
|
273
|
+
return void 0;
|
|
274
|
+
}
|
|
275
|
+
const checkpointer = resolveCheckpointer(graph, options);
|
|
276
|
+
if (!checkpointer) {
|
|
277
|
+
return void 0;
|
|
278
|
+
}
|
|
279
|
+
patchSaver(checkpointer);
|
|
280
|
+
const span = getTracer().startSpan(CHECKPOINT_SPAN_NAME);
|
|
281
|
+
return {
|
|
282
|
+
span,
|
|
283
|
+
runContext: trace.setSpan(context.active(), span).setValue(CHECKPOINT_SPAN_KEY, span)
|
|
284
|
+
};
|
|
285
|
+
} catch (error) {
|
|
286
|
+
logger.debug(`Brizz LangGraph: could not start checkpoint span: ${String(error)}`);
|
|
287
|
+
return void 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
var CONTROL_FLOW_ERROR_NAMES = /* @__PURE__ */ new Set([
|
|
291
|
+
"GraphInterrupt",
|
|
292
|
+
"GraphBubbleUp",
|
|
293
|
+
"GraphDrained",
|
|
294
|
+
"NodeInterrupt",
|
|
295
|
+
"ParentCommand"
|
|
296
|
+
]);
|
|
297
|
+
function isControlFlow(error) {
|
|
298
|
+
const name = error?.name;
|
|
299
|
+
return typeof name === "string" && CONTROL_FLOW_ERROR_NAMES.has(name);
|
|
300
|
+
}
|
|
301
|
+
function endRun(run, error) {
|
|
302
|
+
try {
|
|
303
|
+
if (error !== void 0 && !isControlFlow(error)) {
|
|
304
|
+
run.span.recordException(
|
|
305
|
+
error instanceof Error ? error : new Error(String(error), { cause: error })
|
|
306
|
+
);
|
|
307
|
+
run.span.setStatus({ code: SpanStatusCode.ERROR });
|
|
308
|
+
}
|
|
309
|
+
} catch (spanError) {
|
|
310
|
+
logger.debug(`Brizz LangGraph: could not finish checkpoint span: ${String(spanError)}`);
|
|
311
|
+
} finally {
|
|
312
|
+
run.span.end();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function attachRunToIteration(stream, run) {
|
|
316
|
+
if (typeof stream !== "object" || stream === null) {
|
|
317
|
+
endRun(run);
|
|
318
|
+
return stream;
|
|
319
|
+
}
|
|
320
|
+
const iterable = stream;
|
|
321
|
+
const originalIterator = iterable[Symbol.asyncIterator];
|
|
322
|
+
if (typeof originalIterator !== "function") {
|
|
323
|
+
endRun(run);
|
|
324
|
+
return stream;
|
|
325
|
+
}
|
|
326
|
+
let settled = false;
|
|
327
|
+
const settle = (error) => {
|
|
328
|
+
if (settled) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
settled = true;
|
|
332
|
+
endRun(run, error);
|
|
333
|
+
};
|
|
334
|
+
Object.defineProperty(iterable, Symbol.asyncIterator, {
|
|
335
|
+
configurable: true,
|
|
336
|
+
writable: true,
|
|
337
|
+
value: function brizzCheckpointIterator() {
|
|
338
|
+
const inner = originalIterator.call(this);
|
|
339
|
+
return {
|
|
340
|
+
[Symbol.asyncIterator]() {
|
|
341
|
+
return this;
|
|
342
|
+
},
|
|
343
|
+
async next(...args) {
|
|
344
|
+
let result;
|
|
345
|
+
try {
|
|
346
|
+
result = await context.with(run.runContext, () => inner.next(...args));
|
|
347
|
+
} catch (error) {
|
|
348
|
+
settle(error);
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
if (result.done) {
|
|
352
|
+
settle();
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
},
|
|
356
|
+
async return(value) {
|
|
357
|
+
try {
|
|
358
|
+
return inner.return ? await context.with(run.runContext, () => inner.return(value)) : { value, done: true };
|
|
359
|
+
} finally {
|
|
360
|
+
settle();
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
async throw(error) {
|
|
364
|
+
try {
|
|
365
|
+
if (!inner.throw) {
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
return await context.with(run.runContext, () => inner.throw(error));
|
|
369
|
+
} finally {
|
|
370
|
+
settle(error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
return iterable;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/internal/instrumentation/auto-init.ts
|
|
92
380
|
var exceptionLogger = (error) => {
|
|
93
381
|
logger.error(`Exception in instrumentation: ${String(error)}`);
|
|
94
382
|
};
|
|
@@ -130,7 +418,7 @@ function loadGenAIInstrumentations() {
|
|
|
130
418
|
function loadMCPInstrumentation() {
|
|
131
419
|
void (async () => {
|
|
132
420
|
try {
|
|
133
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
421
|
+
const { MCPInstrumentation } = await import("./mcp-YHBVF7QU.js");
|
|
134
422
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
135
423
|
registerInstrumentations({ instrumentations: [mcp] });
|
|
136
424
|
logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -141,6 +429,14 @@ function loadMCPInstrumentation() {
|
|
|
141
429
|
}
|
|
142
430
|
})();
|
|
143
431
|
}
|
|
432
|
+
function loadLangGraphInstrumentation() {
|
|
433
|
+
try {
|
|
434
|
+
registerInstrumentations({ instrumentations: [new LangGraphInstrumentation()] });
|
|
435
|
+
logger.debug("Auto-loaded LangGraph instrumentation");
|
|
436
|
+
} catch (error) {
|
|
437
|
+
logger.debug(`LangGraph instrumentation not loaded: ${String(error)}`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
144
440
|
function loadVertexAIInstrumentation() {
|
|
145
441
|
void (async () => {
|
|
146
442
|
try {
|
|
@@ -218,6 +514,7 @@ function autoInitializeInstrumentations() {
|
|
|
218
514
|
try {
|
|
219
515
|
const genAIInstrumentations = loadGenAIInstrumentations();
|
|
220
516
|
loadMCPInstrumentation();
|
|
517
|
+
loadLangGraphInstrumentation();
|
|
221
518
|
loadVertexAIInstrumentation();
|
|
222
519
|
loadGoogleGenAIInstrumentation();
|
|
223
520
|
loadVercelAITelemetry();
|
|
@@ -394,6 +691,94 @@ import { LlamaIndexInstrumentation as LlamaIndexInstrumentation2 } from "@tracel
|
|
|
394
691
|
import { PineconeInstrumentation as PineconeInstrumentation2 } from "@traceloop/instrumentation-pinecone";
|
|
395
692
|
import { QdrantInstrumentation as QdrantInstrumentation2 } from "@traceloop/instrumentation-qdrant";
|
|
396
693
|
import { TogetherInstrumentation as TogetherInstrumentation2 } from "@traceloop/instrumentation-together";
|
|
694
|
+
|
|
695
|
+
// src/internal/instrumentation/langchain.ts
|
|
696
|
+
import { context as context2 } from "@opentelemetry/api";
|
|
697
|
+
var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
|
|
698
|
+
var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
|
|
699
|
+
var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
700
|
+
USER_EMAIL,
|
|
701
|
+
USER_NAME,
|
|
702
|
+
ORGANIZATION_NAME,
|
|
703
|
+
ORGANIZATION_DOMAIN
|
|
704
|
+
]);
|
|
705
|
+
function runMetadataFromContext() {
|
|
706
|
+
const bag = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
707
|
+
if (!bag) {
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
const metadata = {};
|
|
711
|
+
for (const [name, value] of Object.entries(bag)) {
|
|
712
|
+
if (!OMITTED_KEYS.has(name)) {
|
|
713
|
+
metadata[`${BRIZZ}.${name}`] = String(value);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
717
|
+
}
|
|
718
|
+
function patchCallbackManagerModule(module2) {
|
|
719
|
+
const callbackManager = module2?.CallbackManager;
|
|
720
|
+
if (callbackManager === null || typeof callbackManager !== "function" && typeof callbackManager !== "object") {
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
const statics = callbackManager;
|
|
724
|
+
if (statics[PATCHED_MARKER] === true) {
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
const key = "_configureSync" in statics ? "_configureSync" : "configure";
|
|
728
|
+
const original = statics[key];
|
|
729
|
+
if (typeof original !== "function") {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
const configure2 = original;
|
|
733
|
+
statics[key] = function(...args) {
|
|
734
|
+
const manager = configure2.apply(this, args);
|
|
735
|
+
try {
|
|
736
|
+
const metadata = runMetadataFromContext();
|
|
737
|
+
if (manager && metadata) {
|
|
738
|
+
manager.addMetadata(metadata);
|
|
739
|
+
}
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
return manager;
|
|
743
|
+
};
|
|
744
|
+
statics[PATCHED_MARKER] = true;
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
function patchInstalledCallbackManager() {
|
|
748
|
+
void (async () => {
|
|
749
|
+
try {
|
|
750
|
+
patchCallbackManagerModule(await import("@langchain/core/callbacks/manager"));
|
|
751
|
+
} catch (error) {
|
|
752
|
+
logger.debug(`LangChain callback manager not patched: ${String(error)}`);
|
|
753
|
+
}
|
|
754
|
+
})();
|
|
755
|
+
}
|
|
756
|
+
function restampLangChainSpan(span) {
|
|
757
|
+
try {
|
|
758
|
+
const scope = span.instrumentationScope;
|
|
759
|
+
if (scope?.name !== SCOPE_NAME) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const attrs = span.attributes;
|
|
763
|
+
const metadata = attrs["metadata"];
|
|
764
|
+
if (typeof metadata !== "string" || !metadata.includes(`"${BRIZZ}.`)) {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const parsed = JSON.parse(metadata);
|
|
768
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
772
|
+
if (key.startsWith(`${BRIZZ}.`) && value !== null && value !== void 0) {
|
|
773
|
+
attrs[key] = String(value);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
} catch (error) {
|
|
777
|
+
logger.debug("Skipped LangChain span re-stamp", { err: error });
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// src/internal/instrumentation/registry.ts
|
|
397
782
|
var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
398
783
|
static instance;
|
|
399
784
|
static getInstance() {
|
|
@@ -471,6 +856,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
471
856
|
const { LangChainInstrumentation } = await import("@arizeai/openinference-instrumentation-langchain");
|
|
472
857
|
const lcInst = new LangChainInstrumentation();
|
|
473
858
|
lcInst.manuallyInstrument(callbackManagerModule);
|
|
859
|
+
patchCallbackManagerModule(callbackManagerModule);
|
|
474
860
|
logger.debug("Manual instrumentation enabled for LangChain");
|
|
475
861
|
} catch (error) {
|
|
476
862
|
logger.error(
|
|
@@ -479,6 +865,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
479
865
|
}
|
|
480
866
|
})();
|
|
481
867
|
}
|
|
868
|
+
if (this.manualModules?.langgraph) {
|
|
869
|
+
try {
|
|
870
|
+
new LangGraphInstrumentation().manuallyInstrument(this.manualModules.langgraph);
|
|
871
|
+
logger.debug("Manual instrumentation enabled for LangGraph");
|
|
872
|
+
} catch (error) {
|
|
873
|
+
logger.error(`Failed to apply LangGraph instrumentation: ${String(error)}`);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
482
876
|
if (this.manualModules?.google_vertexai) {
|
|
483
877
|
const vertexModule = this.manualModules.google_vertexai;
|
|
484
878
|
void (async () => {
|
|
@@ -513,7 +907,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
513
907
|
const mcpModules = this.manualModules.mcp;
|
|
514
908
|
void (async () => {
|
|
515
909
|
try {
|
|
516
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
910
|
+
const { MCPInstrumentation } = await import("./mcp-YHBVF7QU.js");
|
|
517
911
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
518
912
|
instrumentation.manuallyInstrument(mcpModules);
|
|
519
913
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -556,9 +950,9 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
556
950
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
557
951
|
|
|
558
952
|
// src/internal/trace/session.ts
|
|
559
|
-
import { context, trace, SpanStatusCode } from "@opentelemetry/api";
|
|
953
|
+
import { context as context3, trace as trace2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
560
954
|
function setCurrentSpanCustomProperties(properties) {
|
|
561
|
-
const current =
|
|
955
|
+
const current = trace2.getActiveSpan();
|
|
562
956
|
if (!current || !current.isRecording()) {
|
|
563
957
|
return;
|
|
564
958
|
}
|
|
@@ -570,11 +964,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
570
964
|
}
|
|
571
965
|
}
|
|
572
966
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
573
|
-
const base =
|
|
967
|
+
const base = context3.active();
|
|
574
968
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
575
969
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
576
970
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
577
|
-
return
|
|
971
|
+
return context3.with(next, fn, thisArg, ...args);
|
|
578
972
|
}
|
|
579
973
|
function withProperties(properties, fn, thisArg) {
|
|
580
974
|
return function wrapped(...args) {
|
|
@@ -586,9 +980,9 @@ function withProperties(properties, fn, thisArg) {
|
|
|
586
980
|
);
|
|
587
981
|
};
|
|
588
982
|
}
|
|
589
|
-
function propagatePropertiesImperatively(properties, base =
|
|
983
|
+
function propagatePropertiesImperatively(properties, base = context3.active()) {
|
|
590
984
|
try {
|
|
591
|
-
const manager =
|
|
985
|
+
const manager = context3;
|
|
592
986
|
const mgr = manager._getContextManager?.();
|
|
593
987
|
const store = mgr?._asyncLocalStorage;
|
|
594
988
|
if (!store || typeof store.enterWith !== "function") {
|
|
@@ -690,7 +1084,7 @@ function withServiceName(name, fn, thisArg) {
|
|
|
690
1084
|
return withProperties(serviceNameProperties(name), fn, thisArg);
|
|
691
1085
|
}
|
|
692
1086
|
function resolveServiceNameFromContext() {
|
|
693
|
-
const props =
|
|
1087
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
694
1088
|
return props?.[SERVICE_NAME];
|
|
695
1089
|
}
|
|
696
1090
|
function userProperties(user) {
|
|
@@ -757,7 +1151,7 @@ function withMessageId(id, fn, thisArg) {
|
|
|
757
1151
|
return withProperties({ [MESSAGE_ID]: id }, fn, thisArg);
|
|
758
1152
|
}
|
|
759
1153
|
function inheritedMuteTools() {
|
|
760
|
-
const properties =
|
|
1154
|
+
const properties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
761
1155
|
return properties?.[MUTE_TOOLS];
|
|
762
1156
|
}
|
|
763
1157
|
function muteProperties(options) {
|
|
@@ -817,9 +1211,9 @@ var Session = class {
|
|
|
817
1211
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
818
1212
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
819
1213
|
*/
|
|
820
|
-
setInput(text,
|
|
1214
|
+
setInput(text, context7) {
|
|
821
1215
|
this.inputs.push(text);
|
|
822
|
-
this.inputContexts.push(
|
|
1216
|
+
this.inputContexts.push(context7 ?? {});
|
|
823
1217
|
this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
|
|
824
1218
|
this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
|
|
825
1219
|
}
|
|
@@ -833,9 +1227,9 @@ var Session = class {
|
|
|
833
1227
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
834
1228
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
835
1229
|
*/
|
|
836
|
-
setOutput(text,
|
|
1230
|
+
setOutput(text, context7) {
|
|
837
1231
|
this.outputs.push(text);
|
|
838
|
-
this.outputContexts.push(
|
|
1232
|
+
this.outputContexts.push(context7 ?? {});
|
|
839
1233
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
840
1234
|
this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
|
|
841
1235
|
}
|
|
@@ -938,18 +1332,18 @@ var SessionTitle = class {
|
|
|
938
1332
|
}
|
|
939
1333
|
};
|
|
940
1334
|
function getActiveSession() {
|
|
941
|
-
return
|
|
1335
|
+
return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
942
1336
|
}
|
|
943
1337
|
function resolveSessionIdFromContext() {
|
|
944
1338
|
const active = getActiveSession();
|
|
945
1339
|
if (active) {
|
|
946
1340
|
return active.sessionId;
|
|
947
1341
|
}
|
|
948
|
-
const props =
|
|
1342
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
949
1343
|
return props?.[SESSION_ID];
|
|
950
1344
|
}
|
|
951
1345
|
function resolveMessageIdFromContext() {
|
|
952
|
-
const props =
|
|
1346
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
953
1347
|
return props?.[MESSAGE_ID];
|
|
954
1348
|
}
|
|
955
1349
|
function emitExternalLink(sessionId, url, title, linkType) {
|
|
@@ -1144,7 +1538,7 @@ function recordMetricImpl(options) {
|
|
|
1144
1538
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
1145
1539
|
const isTitle = options?.mode === "title";
|
|
1146
1540
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1147
|
-
const tracer =
|
|
1541
|
+
const tracer = trace2.getTracer("@brizz/sdk");
|
|
1148
1542
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
1149
1543
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1150
1544
|
if (extraProperties) {
|
|
@@ -1163,8 +1557,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1163
1557
|
}
|
|
1164
1558
|
}
|
|
1165
1559
|
return callWithProperties(contextProperties, () => {
|
|
1166
|
-
const sessionCtx =
|
|
1167
|
-
return
|
|
1560
|
+
const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1561
|
+
return context3.with(sessionCtx, () => {
|
|
1168
1562
|
try {
|
|
1169
1563
|
const result = callback(session);
|
|
1170
1564
|
if (result && typeof result.then === "function") {
|
|
@@ -1173,7 +1567,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1173
1567
|
return value;
|
|
1174
1568
|
}).catch((error) => {
|
|
1175
1569
|
span.recordException(error);
|
|
1176
|
-
span.setStatus({ code:
|
|
1570
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1177
1571
|
span.end();
|
|
1178
1572
|
throw error;
|
|
1179
1573
|
});
|
|
@@ -1182,7 +1576,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1182
1576
|
return result;
|
|
1183
1577
|
} catch (error) {
|
|
1184
1578
|
span.recordException(error);
|
|
1185
|
-
span.setStatus({ code:
|
|
1579
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1186
1580
|
span.end();
|
|
1187
1581
|
throw error;
|
|
1188
1582
|
}
|
|
@@ -1192,7 +1586,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1192
1586
|
}
|
|
1193
1587
|
function startSessionTitle(callback, options) {
|
|
1194
1588
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1195
|
-
const tracer =
|
|
1589
|
+
const tracer = trace2.getTracer("@brizz/sdk");
|
|
1196
1590
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1197
1591
|
if (resolvedSessionId) {
|
|
1198
1592
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -1211,7 +1605,7 @@ function startSessionTitle(callback, options) {
|
|
|
1211
1605
|
return value;
|
|
1212
1606
|
}).catch((error) => {
|
|
1213
1607
|
span.recordException(error);
|
|
1214
|
-
span.setStatus({ code:
|
|
1608
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1215
1609
|
span.end();
|
|
1216
1610
|
throw error;
|
|
1217
1611
|
});
|
|
@@ -1220,7 +1614,7 @@ function startSessionTitle(callback, options) {
|
|
|
1220
1614
|
return result;
|
|
1221
1615
|
} catch (error) {
|
|
1222
1616
|
span.recordException(error);
|
|
1223
|
-
span.setStatus({ code:
|
|
1617
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1224
1618
|
span.end();
|
|
1225
1619
|
throw error;
|
|
1226
1620
|
}
|
|
@@ -1229,7 +1623,7 @@ function startSessionTitle(callback, options) {
|
|
|
1229
1623
|
}
|
|
1230
1624
|
|
|
1231
1625
|
// src/internal/log/processors/log-processor.ts
|
|
1232
|
-
import { context as
|
|
1626
|
+
import { context as context4 } from "@opentelemetry/api";
|
|
1233
1627
|
import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
1234
1628
|
|
|
1235
1629
|
// src/internal/masking/patterns.ts
|
|
@@ -1667,7 +2061,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
|
|
|
1667
2061
|
if (maskingConfig) {
|
|
1668
2062
|
maskLog(logRecord, maskingConfig);
|
|
1669
2063
|
}
|
|
1670
|
-
const associationProperties =
|
|
2064
|
+
const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1671
2065
|
if (associationProperties) {
|
|
1672
2066
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1673
2067
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1687,7 +2081,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
1687
2081
|
if (maskingConfig) {
|
|
1688
2082
|
maskLog(logRecord, maskingConfig);
|
|
1689
2083
|
}
|
|
1690
|
-
const associationProperties =
|
|
2084
|
+
const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1691
2085
|
if (associationProperties) {
|
|
1692
2086
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1693
2087
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2165,13 +2559,13 @@ var BrizzSpanExporter = class {
|
|
|
2165
2559
|
};
|
|
2166
2560
|
|
|
2167
2561
|
// src/internal/trace/processors/span-processor.ts
|
|
2168
|
-
import { context as
|
|
2562
|
+
import { context as context5 } from "@opentelemetry/api";
|
|
2169
2563
|
import {
|
|
2170
2564
|
BatchSpanProcessor,
|
|
2171
2565
|
SimpleSpanProcessor
|
|
2172
2566
|
} from "@opentelemetry/sdk-trace-base";
|
|
2173
2567
|
function applyContextAttributes(span) {
|
|
2174
|
-
const sessionProperties =
|
|
2568
|
+
const sessionProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2175
2569
|
if (sessionProperties) {
|
|
2176
2570
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2177
2571
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2195,6 +2589,7 @@ var BrizzSimpleSpanProcessor = class extends SimpleSpanProcessor {
|
|
|
2195
2589
|
super.onStart(span, parentContext);
|
|
2196
2590
|
}
|
|
2197
2591
|
onEnd(span) {
|
|
2592
|
+
restampLangChainSpan(span);
|
|
2198
2593
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2199
2594
|
if (maskingConfig) {
|
|
2200
2595
|
maskReadableSpan(span, maskingConfig);
|
|
@@ -2213,6 +2608,7 @@ var BrizzBatchSpanProcessor = class extends BatchSpanProcessor {
|
|
|
2213
2608
|
super.onStart(span, parentContext);
|
|
2214
2609
|
}
|
|
2215
2610
|
onEnd(span) {
|
|
2611
|
+
restampLangChainSpan(span);
|
|
2216
2612
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2217
2613
|
if (maskingConfig) {
|
|
2218
2614
|
maskReadableSpan(span, maskingConfig);
|
|
@@ -2366,12 +2762,12 @@ function getSpanProcessor() {
|
|
|
2366
2762
|
|
|
2367
2763
|
// src/internal/trace/agent.ts
|
|
2368
2764
|
import { randomUUID } from "crypto";
|
|
2369
|
-
import { context as
|
|
2765
|
+
import { context as context6, propagation } from "@opentelemetry/api";
|
|
2370
2766
|
function newInstanceId() {
|
|
2371
2767
|
return randomUUID().replaceAll("-", "").slice(0, 8);
|
|
2372
2768
|
}
|
|
2373
2769
|
function activeProperties() {
|
|
2374
|
-
return
|
|
2770
|
+
return context6.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
|
|
2375
2771
|
}
|
|
2376
2772
|
function encodeToken(agent) {
|
|
2377
2773
|
const payload = {
|
|
@@ -2386,7 +2782,7 @@ function encodeToken(agent) {
|
|
|
2386
2782
|
function currentTraceparent() {
|
|
2387
2783
|
const carrier = {};
|
|
2388
2784
|
try {
|
|
2389
|
-
propagation.inject(
|
|
2785
|
+
propagation.inject(context6.active(), carrier);
|
|
2390
2786
|
} catch {
|
|
2391
2787
|
}
|
|
2392
2788
|
return carrier["traceparent"] ?? "";
|
|
@@ -2430,7 +2826,7 @@ function resolveAgent(agent) {
|
|
|
2430
2826
|
let parentId;
|
|
2431
2827
|
let name;
|
|
2432
2828
|
let sessionId = "";
|
|
2433
|
-
let parentContext =
|
|
2829
|
+
let parentContext = context6.active();
|
|
2434
2830
|
if (options.token === void 0) {
|
|
2435
2831
|
id = options.id || newInstanceId();
|
|
2436
2832
|
parentId = options.parentId || activeProperties()[AGENT_ID] || "";
|
|
@@ -2467,7 +2863,7 @@ function startAgent(agent, callback) {
|
|
|
2467
2863
|
return callback(unreadableAgent(agent));
|
|
2468
2864
|
}
|
|
2469
2865
|
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2470
|
-
return
|
|
2866
|
+
return context6.with(
|
|
2471
2867
|
parentContext,
|
|
2472
2868
|
() => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
|
|
2473
2869
|
);
|
|
@@ -2521,6 +2917,7 @@ var _Brizz = class __Brizz {
|
|
|
2521
2917
|
setupInstrumentation(options) {
|
|
2522
2918
|
const registry = InstrumentationRegistry.getInstance();
|
|
2523
2919
|
configure(resolveMcpSessionTracking(options.mcpSessionTracking));
|
|
2920
|
+
patchInstalledCallbackManager();
|
|
2524
2921
|
if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
|
|
2525
2922
|
registry.setManualModules(options.instrumentModules);
|
|
2526
2923
|
}
|