@brizz/sdk 0.1.45 → 0.1.47
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 +13 -7
- package/dist/{chunk-CBEDIRVK.cjs → chunk-EWT4TUB7.cjs} +6 -6
- package/dist/{chunk-BAQTZKGI.js → chunk-V727EJE5.js} +7 -7
- package/dist/index.cjs +371 -59
- package/dist/index.js +350 -38
- package/dist/{mcp-CCFYA5CI.cjs → mcp-3FOEDOF2.cjs} +11 -11
- package/dist/{mcp-FTYCIWL4.js → mcp-GANFYW4J.js} +1 -1
- 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/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 +29 -22
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-V727EJE5.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-GANFYW4J.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();
|
|
@@ -396,7 +693,8 @@ import { QdrantInstrumentation as QdrantInstrumentation2 } from "@traceloop/inst
|
|
|
396
693
|
import { TogetherInstrumentation as TogetherInstrumentation2 } from "@traceloop/instrumentation-together";
|
|
397
694
|
|
|
398
695
|
// src/internal/instrumentation/langchain.ts
|
|
399
|
-
import {
|
|
696
|
+
import { createRequire } from "module";
|
|
697
|
+
import { context as context2 } from "@opentelemetry/api";
|
|
400
698
|
var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
|
|
401
699
|
var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
|
|
402
700
|
var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -406,7 +704,7 @@ var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
406
704
|
ORGANIZATION_DOMAIN
|
|
407
705
|
]);
|
|
408
706
|
function runMetadataFromContext() {
|
|
409
|
-
const bag =
|
|
707
|
+
const bag = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
410
708
|
if (!bag) {
|
|
411
709
|
return void 0;
|
|
412
710
|
}
|
|
@@ -454,6 +752,12 @@ function patchInstalledCallbackManager() {
|
|
|
454
752
|
} catch (error) {
|
|
455
753
|
logger.debug(`LangChain callback manager not patched: ${String(error)}`);
|
|
456
754
|
}
|
|
755
|
+
try {
|
|
756
|
+
const requireFromSdk = createRequire(import.meta.url);
|
|
757
|
+
patchCallbackManagerModule(requireFromSdk("@langchain/core/callbacks/manager"));
|
|
758
|
+
} catch (error) {
|
|
759
|
+
logger.debug(`LangChain CJS callback manager not patched: ${String(error)}`);
|
|
760
|
+
}
|
|
457
761
|
})();
|
|
458
762
|
}
|
|
459
763
|
function restampLangChainSpan(span) {
|
|
@@ -568,6 +872,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
568
872
|
}
|
|
569
873
|
})();
|
|
570
874
|
}
|
|
875
|
+
if (this.manualModules?.langgraph) {
|
|
876
|
+
try {
|
|
877
|
+
new LangGraphInstrumentation().manuallyInstrument(this.manualModules.langgraph);
|
|
878
|
+
logger.debug("Manual instrumentation enabled for LangGraph");
|
|
879
|
+
} catch (error) {
|
|
880
|
+
logger.error(`Failed to apply LangGraph instrumentation: ${String(error)}`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
571
883
|
if (this.manualModules?.google_vertexai) {
|
|
572
884
|
const vertexModule = this.manualModules.google_vertexai;
|
|
573
885
|
void (async () => {
|
|
@@ -602,7 +914,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
602
914
|
const mcpModules = this.manualModules.mcp;
|
|
603
915
|
void (async () => {
|
|
604
916
|
try {
|
|
605
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
917
|
+
const { MCPInstrumentation } = await import("./mcp-GANFYW4J.js");
|
|
606
918
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
607
919
|
instrumentation.manuallyInstrument(mcpModules);
|
|
608
920
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -645,9 +957,9 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
645
957
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
646
958
|
|
|
647
959
|
// src/internal/trace/session.ts
|
|
648
|
-
import { context as
|
|
960
|
+
import { context as context3, trace as trace2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
649
961
|
function setCurrentSpanCustomProperties(properties) {
|
|
650
|
-
const current =
|
|
962
|
+
const current = trace2.getActiveSpan();
|
|
651
963
|
if (!current || !current.isRecording()) {
|
|
652
964
|
return;
|
|
653
965
|
}
|
|
@@ -659,11 +971,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
659
971
|
}
|
|
660
972
|
}
|
|
661
973
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
662
|
-
const base =
|
|
974
|
+
const base = context3.active();
|
|
663
975
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
664
976
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
665
977
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
666
|
-
return
|
|
978
|
+
return context3.with(next, fn, thisArg, ...args);
|
|
667
979
|
}
|
|
668
980
|
function withProperties(properties, fn, thisArg) {
|
|
669
981
|
return function wrapped(...args) {
|
|
@@ -675,9 +987,9 @@ function withProperties(properties, fn, thisArg) {
|
|
|
675
987
|
);
|
|
676
988
|
};
|
|
677
989
|
}
|
|
678
|
-
function propagatePropertiesImperatively(properties, base =
|
|
990
|
+
function propagatePropertiesImperatively(properties, base = context3.active()) {
|
|
679
991
|
try {
|
|
680
|
-
const manager =
|
|
992
|
+
const manager = context3;
|
|
681
993
|
const mgr = manager._getContextManager?.();
|
|
682
994
|
const store = mgr?._asyncLocalStorage;
|
|
683
995
|
if (!store || typeof store.enterWith !== "function") {
|
|
@@ -779,7 +1091,7 @@ function withServiceName(name, fn, thisArg) {
|
|
|
779
1091
|
return withProperties(serviceNameProperties(name), fn, thisArg);
|
|
780
1092
|
}
|
|
781
1093
|
function resolveServiceNameFromContext() {
|
|
782
|
-
const props =
|
|
1094
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
783
1095
|
return props?.[SERVICE_NAME];
|
|
784
1096
|
}
|
|
785
1097
|
function userProperties(user) {
|
|
@@ -846,7 +1158,7 @@ function withMessageId(id, fn, thisArg) {
|
|
|
846
1158
|
return withProperties({ [MESSAGE_ID]: id }, fn, thisArg);
|
|
847
1159
|
}
|
|
848
1160
|
function inheritedMuteTools() {
|
|
849
|
-
const properties =
|
|
1161
|
+
const properties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
850
1162
|
return properties?.[MUTE_TOOLS];
|
|
851
1163
|
}
|
|
852
1164
|
function muteProperties(options) {
|
|
@@ -906,9 +1218,9 @@ var Session = class {
|
|
|
906
1218
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
907
1219
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
908
1220
|
*/
|
|
909
|
-
setInput(text,
|
|
1221
|
+
setInput(text, context7) {
|
|
910
1222
|
this.inputs.push(text);
|
|
911
|
-
this.inputContexts.push(
|
|
1223
|
+
this.inputContexts.push(context7 ?? {});
|
|
912
1224
|
this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
|
|
913
1225
|
this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
|
|
914
1226
|
}
|
|
@@ -922,9 +1234,9 @@ var Session = class {
|
|
|
922
1234
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
923
1235
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
924
1236
|
*/
|
|
925
|
-
setOutput(text,
|
|
1237
|
+
setOutput(text, context7) {
|
|
926
1238
|
this.outputs.push(text);
|
|
927
|
-
this.outputContexts.push(
|
|
1239
|
+
this.outputContexts.push(context7 ?? {});
|
|
928
1240
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
929
1241
|
this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
|
|
930
1242
|
}
|
|
@@ -1027,18 +1339,18 @@ var SessionTitle = class {
|
|
|
1027
1339
|
}
|
|
1028
1340
|
};
|
|
1029
1341
|
function getActiveSession() {
|
|
1030
|
-
return
|
|
1342
|
+
return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1031
1343
|
}
|
|
1032
1344
|
function resolveSessionIdFromContext() {
|
|
1033
1345
|
const active = getActiveSession();
|
|
1034
1346
|
if (active) {
|
|
1035
1347
|
return active.sessionId;
|
|
1036
1348
|
}
|
|
1037
|
-
const props =
|
|
1349
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1038
1350
|
return props?.[SESSION_ID];
|
|
1039
1351
|
}
|
|
1040
1352
|
function resolveMessageIdFromContext() {
|
|
1041
|
-
const props =
|
|
1353
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1042
1354
|
return props?.[MESSAGE_ID];
|
|
1043
1355
|
}
|
|
1044
1356
|
function emitExternalLink(sessionId, url, title, linkType) {
|
|
@@ -1233,7 +1545,7 @@ function recordMetricImpl(options) {
|
|
|
1233
1545
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
1234
1546
|
const isTitle = options?.mode === "title";
|
|
1235
1547
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1236
|
-
const tracer =
|
|
1548
|
+
const tracer = trace2.getTracer("@brizz/sdk");
|
|
1237
1549
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
1238
1550
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1239
1551
|
if (extraProperties) {
|
|
@@ -1252,8 +1564,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1252
1564
|
}
|
|
1253
1565
|
}
|
|
1254
1566
|
return callWithProperties(contextProperties, () => {
|
|
1255
|
-
const sessionCtx =
|
|
1256
|
-
return
|
|
1567
|
+
const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1568
|
+
return context3.with(sessionCtx, () => {
|
|
1257
1569
|
try {
|
|
1258
1570
|
const result = callback(session);
|
|
1259
1571
|
if (result && typeof result.then === "function") {
|
|
@@ -1262,7 +1574,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1262
1574
|
return value;
|
|
1263
1575
|
}).catch((error) => {
|
|
1264
1576
|
span.recordException(error);
|
|
1265
|
-
span.setStatus({ code:
|
|
1577
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1266
1578
|
span.end();
|
|
1267
1579
|
throw error;
|
|
1268
1580
|
});
|
|
@@ -1271,7 +1583,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1271
1583
|
return result;
|
|
1272
1584
|
} catch (error) {
|
|
1273
1585
|
span.recordException(error);
|
|
1274
|
-
span.setStatus({ code:
|
|
1586
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1275
1587
|
span.end();
|
|
1276
1588
|
throw error;
|
|
1277
1589
|
}
|
|
@@ -1281,7 +1593,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1281
1593
|
}
|
|
1282
1594
|
function startSessionTitle(callback, options) {
|
|
1283
1595
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1284
|
-
const tracer =
|
|
1596
|
+
const tracer = trace2.getTracer("@brizz/sdk");
|
|
1285
1597
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1286
1598
|
if (resolvedSessionId) {
|
|
1287
1599
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -1300,7 +1612,7 @@ function startSessionTitle(callback, options) {
|
|
|
1300
1612
|
return value;
|
|
1301
1613
|
}).catch((error) => {
|
|
1302
1614
|
span.recordException(error);
|
|
1303
|
-
span.setStatus({ code:
|
|
1615
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1304
1616
|
span.end();
|
|
1305
1617
|
throw error;
|
|
1306
1618
|
});
|
|
@@ -1309,7 +1621,7 @@ function startSessionTitle(callback, options) {
|
|
|
1309
1621
|
return result;
|
|
1310
1622
|
} catch (error) {
|
|
1311
1623
|
span.recordException(error);
|
|
1312
|
-
span.setStatus({ code:
|
|
1624
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1313
1625
|
span.end();
|
|
1314
1626
|
throw error;
|
|
1315
1627
|
}
|
|
@@ -1318,7 +1630,7 @@ function startSessionTitle(callback, options) {
|
|
|
1318
1630
|
}
|
|
1319
1631
|
|
|
1320
1632
|
// src/internal/log/processors/log-processor.ts
|
|
1321
|
-
import { context as
|
|
1633
|
+
import { context as context4 } from "@opentelemetry/api";
|
|
1322
1634
|
import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
1323
1635
|
|
|
1324
1636
|
// src/internal/masking/patterns.ts
|
|
@@ -1756,7 +2068,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
|
|
|
1756
2068
|
if (maskingConfig) {
|
|
1757
2069
|
maskLog(logRecord, maskingConfig);
|
|
1758
2070
|
}
|
|
1759
|
-
const associationProperties =
|
|
2071
|
+
const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1760
2072
|
if (associationProperties) {
|
|
1761
2073
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1762
2074
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1776,7 +2088,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
1776
2088
|
if (maskingConfig) {
|
|
1777
2089
|
maskLog(logRecord, maskingConfig);
|
|
1778
2090
|
}
|
|
1779
|
-
const associationProperties =
|
|
2091
|
+
const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1780
2092
|
if (associationProperties) {
|
|
1781
2093
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1782
2094
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2254,13 +2566,13 @@ var BrizzSpanExporter = class {
|
|
|
2254
2566
|
};
|
|
2255
2567
|
|
|
2256
2568
|
// src/internal/trace/processors/span-processor.ts
|
|
2257
|
-
import { context as
|
|
2569
|
+
import { context as context5 } from "@opentelemetry/api";
|
|
2258
2570
|
import {
|
|
2259
2571
|
BatchSpanProcessor,
|
|
2260
2572
|
SimpleSpanProcessor
|
|
2261
2573
|
} from "@opentelemetry/sdk-trace-base";
|
|
2262
2574
|
function applyContextAttributes(span) {
|
|
2263
|
-
const sessionProperties =
|
|
2575
|
+
const sessionProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2264
2576
|
if (sessionProperties) {
|
|
2265
2577
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2266
2578
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2457,12 +2769,12 @@ function getSpanProcessor() {
|
|
|
2457
2769
|
|
|
2458
2770
|
// src/internal/trace/agent.ts
|
|
2459
2771
|
import { randomUUID } from "crypto";
|
|
2460
|
-
import { context as
|
|
2772
|
+
import { context as context6, propagation } from "@opentelemetry/api";
|
|
2461
2773
|
function newInstanceId() {
|
|
2462
2774
|
return randomUUID().replaceAll("-", "").slice(0, 8);
|
|
2463
2775
|
}
|
|
2464
2776
|
function activeProperties() {
|
|
2465
|
-
return
|
|
2777
|
+
return context6.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
|
|
2466
2778
|
}
|
|
2467
2779
|
function encodeToken(agent) {
|
|
2468
2780
|
const payload = {
|
|
@@ -2477,7 +2789,7 @@ function encodeToken(agent) {
|
|
|
2477
2789
|
function currentTraceparent() {
|
|
2478
2790
|
const carrier = {};
|
|
2479
2791
|
try {
|
|
2480
|
-
propagation.inject(
|
|
2792
|
+
propagation.inject(context6.active(), carrier);
|
|
2481
2793
|
} catch {
|
|
2482
2794
|
}
|
|
2483
2795
|
return carrier["traceparent"] ?? "";
|
|
@@ -2521,7 +2833,7 @@ function resolveAgent(agent) {
|
|
|
2521
2833
|
let parentId;
|
|
2522
2834
|
let name;
|
|
2523
2835
|
let sessionId = "";
|
|
2524
|
-
let parentContext =
|
|
2836
|
+
let parentContext = context6.active();
|
|
2525
2837
|
if (options.token === void 0) {
|
|
2526
2838
|
id = options.id || newInstanceId();
|
|
2527
2839
|
parentId = options.parentId || activeProperties()[AGENT_ID] || "";
|
|
@@ -2558,7 +2870,7 @@ function startAgent(agent, callback) {
|
|
|
2558
2870
|
return callback(unreadableAgent(agent));
|
|
2559
2871
|
}
|
|
2560
2872
|
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2561
|
-
return
|
|
2873
|
+
return context6.with(
|
|
2562
2874
|
parentContext,
|
|
2563
2875
|
() => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
|
|
2564
2876
|
);
|