@brizz/sdk 0.1.45 → 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-BAQTZKGI.js → chunk-USYGGHMA.js} +7 -7
- package/dist/{chunk-CBEDIRVK.cjs → chunk-VFWTFL7E.cjs} +6 -6
- package/dist/index.cjs +364 -59
- package/dist/index.js +343 -38
- package/dist/{mcp-CCFYA5CI.cjs → mcp-M3WRCR7G.cjs} +11 -11
- package/dist/{mcp-FTYCIWL4.js → mcp-YHBVF7QU.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 +9 -3
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();
|
|
@@ -396,7 +693,7 @@ 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 { context } from "@opentelemetry/api";
|
|
696
|
+
import { context as context2 } from "@opentelemetry/api";
|
|
400
697
|
var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
|
|
401
698
|
var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
|
|
402
699
|
var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -406,7 +703,7 @@ var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
406
703
|
ORGANIZATION_DOMAIN
|
|
407
704
|
]);
|
|
408
705
|
function runMetadataFromContext() {
|
|
409
|
-
const bag =
|
|
706
|
+
const bag = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
410
707
|
if (!bag) {
|
|
411
708
|
return void 0;
|
|
412
709
|
}
|
|
@@ -568,6 +865,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
568
865
|
}
|
|
569
866
|
})();
|
|
570
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
|
+
}
|
|
571
876
|
if (this.manualModules?.google_vertexai) {
|
|
572
877
|
const vertexModule = this.manualModules.google_vertexai;
|
|
573
878
|
void (async () => {
|
|
@@ -602,7 +907,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
602
907
|
const mcpModules = this.manualModules.mcp;
|
|
603
908
|
void (async () => {
|
|
604
909
|
try {
|
|
605
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
910
|
+
const { MCPInstrumentation } = await import("./mcp-YHBVF7QU.js");
|
|
606
911
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
607
912
|
instrumentation.manuallyInstrument(mcpModules);
|
|
608
913
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -645,9 +950,9 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
645
950
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
646
951
|
|
|
647
952
|
// src/internal/trace/session.ts
|
|
648
|
-
import { context as
|
|
953
|
+
import { context as context3, trace as trace2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
649
954
|
function setCurrentSpanCustomProperties(properties) {
|
|
650
|
-
const current =
|
|
955
|
+
const current = trace2.getActiveSpan();
|
|
651
956
|
if (!current || !current.isRecording()) {
|
|
652
957
|
return;
|
|
653
958
|
}
|
|
@@ -659,11 +964,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
659
964
|
}
|
|
660
965
|
}
|
|
661
966
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
662
|
-
const base =
|
|
967
|
+
const base = context3.active();
|
|
663
968
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
664
969
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
665
970
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
666
|
-
return
|
|
971
|
+
return context3.with(next, fn, thisArg, ...args);
|
|
667
972
|
}
|
|
668
973
|
function withProperties(properties, fn, thisArg) {
|
|
669
974
|
return function wrapped(...args) {
|
|
@@ -675,9 +980,9 @@ function withProperties(properties, fn, thisArg) {
|
|
|
675
980
|
);
|
|
676
981
|
};
|
|
677
982
|
}
|
|
678
|
-
function propagatePropertiesImperatively(properties, base =
|
|
983
|
+
function propagatePropertiesImperatively(properties, base = context3.active()) {
|
|
679
984
|
try {
|
|
680
|
-
const manager =
|
|
985
|
+
const manager = context3;
|
|
681
986
|
const mgr = manager._getContextManager?.();
|
|
682
987
|
const store = mgr?._asyncLocalStorage;
|
|
683
988
|
if (!store || typeof store.enterWith !== "function") {
|
|
@@ -779,7 +1084,7 @@ function withServiceName(name, fn, thisArg) {
|
|
|
779
1084
|
return withProperties(serviceNameProperties(name), fn, thisArg);
|
|
780
1085
|
}
|
|
781
1086
|
function resolveServiceNameFromContext() {
|
|
782
|
-
const props =
|
|
1087
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
783
1088
|
return props?.[SERVICE_NAME];
|
|
784
1089
|
}
|
|
785
1090
|
function userProperties(user) {
|
|
@@ -846,7 +1151,7 @@ function withMessageId(id, fn, thisArg) {
|
|
|
846
1151
|
return withProperties({ [MESSAGE_ID]: id }, fn, thisArg);
|
|
847
1152
|
}
|
|
848
1153
|
function inheritedMuteTools() {
|
|
849
|
-
const properties =
|
|
1154
|
+
const properties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
850
1155
|
return properties?.[MUTE_TOOLS];
|
|
851
1156
|
}
|
|
852
1157
|
function muteProperties(options) {
|
|
@@ -906,9 +1211,9 @@ var Session = class {
|
|
|
906
1211
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
907
1212
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
908
1213
|
*/
|
|
909
|
-
setInput(text,
|
|
1214
|
+
setInput(text, context7) {
|
|
910
1215
|
this.inputs.push(text);
|
|
911
|
-
this.inputContexts.push(
|
|
1216
|
+
this.inputContexts.push(context7 ?? {});
|
|
912
1217
|
this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
|
|
913
1218
|
this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
|
|
914
1219
|
}
|
|
@@ -922,9 +1227,9 @@ var Session = class {
|
|
|
922
1227
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
923
1228
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
924
1229
|
*/
|
|
925
|
-
setOutput(text,
|
|
1230
|
+
setOutput(text, context7) {
|
|
926
1231
|
this.outputs.push(text);
|
|
927
|
-
this.outputContexts.push(
|
|
1232
|
+
this.outputContexts.push(context7 ?? {});
|
|
928
1233
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
929
1234
|
this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
|
|
930
1235
|
}
|
|
@@ -1027,18 +1332,18 @@ var SessionTitle = class {
|
|
|
1027
1332
|
}
|
|
1028
1333
|
};
|
|
1029
1334
|
function getActiveSession() {
|
|
1030
|
-
return
|
|
1335
|
+
return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1031
1336
|
}
|
|
1032
1337
|
function resolveSessionIdFromContext() {
|
|
1033
1338
|
const active = getActiveSession();
|
|
1034
1339
|
if (active) {
|
|
1035
1340
|
return active.sessionId;
|
|
1036
1341
|
}
|
|
1037
|
-
const props =
|
|
1342
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1038
1343
|
return props?.[SESSION_ID];
|
|
1039
1344
|
}
|
|
1040
1345
|
function resolveMessageIdFromContext() {
|
|
1041
|
-
const props =
|
|
1346
|
+
const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1042
1347
|
return props?.[MESSAGE_ID];
|
|
1043
1348
|
}
|
|
1044
1349
|
function emitExternalLink(sessionId, url, title, linkType) {
|
|
@@ -1233,7 +1538,7 @@ function recordMetricImpl(options) {
|
|
|
1233
1538
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
1234
1539
|
const isTitle = options?.mode === "title";
|
|
1235
1540
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1236
|
-
const tracer =
|
|
1541
|
+
const tracer = trace2.getTracer("@brizz/sdk");
|
|
1237
1542
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
1238
1543
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1239
1544
|
if (extraProperties) {
|
|
@@ -1252,8 +1557,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1252
1557
|
}
|
|
1253
1558
|
}
|
|
1254
1559
|
return callWithProperties(contextProperties, () => {
|
|
1255
|
-
const sessionCtx =
|
|
1256
|
-
return
|
|
1560
|
+
const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1561
|
+
return context3.with(sessionCtx, () => {
|
|
1257
1562
|
try {
|
|
1258
1563
|
const result = callback(session);
|
|
1259
1564
|
if (result && typeof result.then === "function") {
|
|
@@ -1262,7 +1567,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1262
1567
|
return value;
|
|
1263
1568
|
}).catch((error) => {
|
|
1264
1569
|
span.recordException(error);
|
|
1265
|
-
span.setStatus({ code:
|
|
1570
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1266
1571
|
span.end();
|
|
1267
1572
|
throw error;
|
|
1268
1573
|
});
|
|
@@ -1271,7 +1576,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1271
1576
|
return result;
|
|
1272
1577
|
} catch (error) {
|
|
1273
1578
|
span.recordException(error);
|
|
1274
|
-
span.setStatus({ code:
|
|
1579
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1275
1580
|
span.end();
|
|
1276
1581
|
throw error;
|
|
1277
1582
|
}
|
|
@@ -1281,7 +1586,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1281
1586
|
}
|
|
1282
1587
|
function startSessionTitle(callback, options) {
|
|
1283
1588
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1284
|
-
const tracer =
|
|
1589
|
+
const tracer = trace2.getTracer("@brizz/sdk");
|
|
1285
1590
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1286
1591
|
if (resolvedSessionId) {
|
|
1287
1592
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -1300,7 +1605,7 @@ function startSessionTitle(callback, options) {
|
|
|
1300
1605
|
return value;
|
|
1301
1606
|
}).catch((error) => {
|
|
1302
1607
|
span.recordException(error);
|
|
1303
|
-
span.setStatus({ code:
|
|
1608
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1304
1609
|
span.end();
|
|
1305
1610
|
throw error;
|
|
1306
1611
|
});
|
|
@@ -1309,7 +1614,7 @@ function startSessionTitle(callback, options) {
|
|
|
1309
1614
|
return result;
|
|
1310
1615
|
} catch (error) {
|
|
1311
1616
|
span.recordException(error);
|
|
1312
|
-
span.setStatus({ code:
|
|
1617
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1313
1618
|
span.end();
|
|
1314
1619
|
throw error;
|
|
1315
1620
|
}
|
|
@@ -1318,7 +1623,7 @@ function startSessionTitle(callback, options) {
|
|
|
1318
1623
|
}
|
|
1319
1624
|
|
|
1320
1625
|
// src/internal/log/processors/log-processor.ts
|
|
1321
|
-
import { context as
|
|
1626
|
+
import { context as context4 } from "@opentelemetry/api";
|
|
1322
1627
|
import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
1323
1628
|
|
|
1324
1629
|
// src/internal/masking/patterns.ts
|
|
@@ -1756,7 +2061,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
|
|
|
1756
2061
|
if (maskingConfig) {
|
|
1757
2062
|
maskLog(logRecord, maskingConfig);
|
|
1758
2063
|
}
|
|
1759
|
-
const associationProperties =
|
|
2064
|
+
const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1760
2065
|
if (associationProperties) {
|
|
1761
2066
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1762
2067
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1776,7 +2081,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
1776
2081
|
if (maskingConfig) {
|
|
1777
2082
|
maskLog(logRecord, maskingConfig);
|
|
1778
2083
|
}
|
|
1779
|
-
const associationProperties =
|
|
2084
|
+
const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1780
2085
|
if (associationProperties) {
|
|
1781
2086
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1782
2087
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2254,13 +2559,13 @@ var BrizzSpanExporter = class {
|
|
|
2254
2559
|
};
|
|
2255
2560
|
|
|
2256
2561
|
// src/internal/trace/processors/span-processor.ts
|
|
2257
|
-
import { context as
|
|
2562
|
+
import { context as context5 } from "@opentelemetry/api";
|
|
2258
2563
|
import {
|
|
2259
2564
|
BatchSpanProcessor,
|
|
2260
2565
|
SimpleSpanProcessor
|
|
2261
2566
|
} from "@opentelemetry/sdk-trace-base";
|
|
2262
2567
|
function applyContextAttributes(span) {
|
|
2263
|
-
const sessionProperties =
|
|
2568
|
+
const sessionProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2264
2569
|
if (sessionProperties) {
|
|
2265
2570
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2266
2571
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2457,12 +2762,12 @@ function getSpanProcessor() {
|
|
|
2457
2762
|
|
|
2458
2763
|
// src/internal/trace/agent.ts
|
|
2459
2764
|
import { randomUUID } from "crypto";
|
|
2460
|
-
import { context as
|
|
2765
|
+
import { context as context6, propagation } from "@opentelemetry/api";
|
|
2461
2766
|
function newInstanceId() {
|
|
2462
2767
|
return randomUUID().replaceAll("-", "").slice(0, 8);
|
|
2463
2768
|
}
|
|
2464
2769
|
function activeProperties() {
|
|
2465
|
-
return
|
|
2770
|
+
return context6.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
|
|
2466
2771
|
}
|
|
2467
2772
|
function encodeToken(agent) {
|
|
2468
2773
|
const payload = {
|
|
@@ -2477,7 +2782,7 @@ function encodeToken(agent) {
|
|
|
2477
2782
|
function currentTraceparent() {
|
|
2478
2783
|
const carrier = {};
|
|
2479
2784
|
try {
|
|
2480
|
-
propagation.inject(
|
|
2785
|
+
propagation.inject(context6.active(), carrier);
|
|
2481
2786
|
} catch {
|
|
2482
2787
|
}
|
|
2483
2788
|
return carrier["traceparent"] ?? "";
|
|
@@ -2521,7 +2826,7 @@ function resolveAgent(agent) {
|
|
|
2521
2826
|
let parentId;
|
|
2522
2827
|
let name;
|
|
2523
2828
|
let sessionId = "";
|
|
2524
|
-
let parentContext =
|
|
2829
|
+
let parentContext = context6.active();
|
|
2525
2830
|
if (options.token === void 0) {
|
|
2526
2831
|
id = options.id || newInstanceId();
|
|
2527
2832
|
parentId = options.parentId || activeProperties()[AGENT_ID] || "";
|
|
@@ -2558,7 +2863,7 @@ function startAgent(agent, callback) {
|
|
|
2558
2863
|
return callback(unreadableAgent(agent));
|
|
2559
2864
|
}
|
|
2560
2865
|
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2561
|
-
return
|
|
2866
|
+
return context6.with(
|
|
2562
2867
|
parentContext,
|
|
2563
2868
|
() => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
|
|
2564
2869
|
);
|