@brizz/sdk 0.1.43 → 0.1.45
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 +44 -0
- package/dist/{chunk-QUV5HYJ2.cjs → chunk-3IGBYXLR.cjs} +4 -4
- package/dist/{chunk-FORVS4QW.cjs → chunk-5WBPX342.cjs} +7 -1
- package/dist/{chunk-Y7NMZAQT.js → chunk-AOT5NJDV.js} +6 -0
- package/dist/{chunk-7FQQHF5U.js → chunk-APOYOP7D.js} +1 -1
- package/dist/{chunk-5SWAZUC5.js → chunk-BAQTZKGI.js} +2 -2
- package/dist/{chunk-WTQTF57J.cjs → chunk-CBEDIRVK.cjs} +8 -8
- package/dist/index.cjs +395 -171
- package/dist/index.js +252 -28
- package/dist/{interrupt-ERCX5RXR.js → interrupt-A6O7N72X.js} +2 -2
- package/dist/interrupt-IKOUBQGN.cjs +12 -0
- package/dist/{mcp-UJD6KF7G.cjs → mcp-CCFYA5CI.cjs} +12 -12
- package/dist/{mcp-6R6KZ5U3.js → mcp-FTYCIWL4.js} +2 -2
- package/dist/types/cjs/index.d.ts +2 -2
- package/dist/types/cjs/internal/instrumentation/langchain.d.ts +4 -0
- package/dist/types/cjs/internal/semantic-conventions.d.ts +3 -0
- package/dist/types/cjs/internal/trace/agent.d.ts +18 -0
- package/dist/types/cjs/internal/trace/index.d.ts +2 -0
- package/dist/types/cjs/internal/trace/session.d.ts +2 -1
- package/dist/types/esm/index.d.ts +2 -2
- package/dist/types/esm/internal/instrumentation/langchain.d.ts +4 -0
- package/dist/types/esm/internal/semantic-conventions.d.ts +3 -0
- package/dist/types/esm/internal/trace/agent.d.ts +18 -0
- package/dist/types/esm/internal/trace/index.d.ts +2 -0
- package/dist/types/esm/internal/trace/session.d.ts +2 -1
- package/package.json +33 -31
- package/dist/interrupt-3NXOTY4N.cjs +0 -12
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var _chunkUNLNNKZ7cjs = require('./chunk-UNLNNKZ7.cjs');
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkCBEDIRVKcjs = require('./chunk-CBEDIRVK.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -16,7 +16,7 @@ var _chunkWTQTF57Jcjs = require('./chunk-WTQTF57J.cjs');
|
|
|
16
16
|
var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunk3IGBYXLRcjs = require('./chunk-3IGBYXLR.cjs');
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
@@ -70,7 +70,10 @@ var _chunkQUV5HYJ2cjs = require('./chunk-QUV5HYJ2.cjs');
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
var _chunk5WBPX342cjs = require('./chunk-5WBPX342.cjs');
|
|
74
77
|
|
|
75
78
|
|
|
76
79
|
var _chunkOBGZSXTJcjs = require('./chunk-OBGZSXTJ.cjs');
|
|
@@ -127,7 +130,7 @@ function loadGenAIInstrumentations() {
|
|
|
127
130
|
function loadMCPInstrumentation() {
|
|
128
131
|
void (async () => {
|
|
129
132
|
try {
|
|
130
|
-
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-
|
|
133
|
+
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-CCFYA5CI.cjs")));
|
|
131
134
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
132
135
|
_instrumentation.registerInstrumentations.call(void 0, { instrumentations: [mcp] });
|
|
133
136
|
_chunkWC573FCIcjs.logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -183,7 +186,7 @@ function loadVercelAITelemetry() {
|
|
|
183
186
|
}
|
|
184
187
|
const isV7 = typeof ai.registerTelemetry === "function";
|
|
185
188
|
const integrations = [];
|
|
186
|
-
const { createInterruptIntegration } = await Promise.resolve().then(() => _interopRequireWildcard(require("./interrupt-
|
|
189
|
+
const { createInterruptIntegration } = await Promise.resolve().then(() => _interopRequireWildcard(require("./interrupt-IKOUBQGN.cjs")));
|
|
187
190
|
integrations.push(createInterruptIntegration());
|
|
188
191
|
let otelCollectorLoaded = false;
|
|
189
192
|
try {
|
|
@@ -391,6 +394,94 @@ var SDK_LANGUAGE = "typescript";
|
|
|
391
394
|
|
|
392
395
|
|
|
393
396
|
|
|
397
|
+
|
|
398
|
+
// src/internal/instrumentation/langchain.ts
|
|
399
|
+
|
|
400
|
+
var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
|
|
401
|
+
var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
|
|
402
|
+
var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
403
|
+
_chunk5WBPX342cjs.USER_EMAIL,
|
|
404
|
+
_chunk5WBPX342cjs.USER_NAME,
|
|
405
|
+
_chunk5WBPX342cjs.ORGANIZATION_NAME,
|
|
406
|
+
_chunk5WBPX342cjs.ORGANIZATION_DOMAIN
|
|
407
|
+
]);
|
|
408
|
+
function runMetadataFromContext() {
|
|
409
|
+
const bag = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
410
|
+
if (!bag) {
|
|
411
|
+
return void 0;
|
|
412
|
+
}
|
|
413
|
+
const metadata = {};
|
|
414
|
+
for (const [name, value] of Object.entries(bag)) {
|
|
415
|
+
if (!OMITTED_KEYS.has(name)) {
|
|
416
|
+
metadata[`${_chunk5WBPX342cjs.BRIZZ}.${name}`] = String(value);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
420
|
+
}
|
|
421
|
+
function patchCallbackManagerModule(module2) {
|
|
422
|
+
const callbackManager = _optionalChain([module2, 'optionalAccess', _5 => _5.CallbackManager]);
|
|
423
|
+
if (callbackManager === null || typeof callbackManager !== "function" && typeof callbackManager !== "object") {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
const statics = callbackManager;
|
|
427
|
+
if (statics[PATCHED_MARKER] === true) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
const key = "_configureSync" in statics ? "_configureSync" : "configure";
|
|
431
|
+
const original = statics[key];
|
|
432
|
+
if (typeof original !== "function") {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
const configure2 = original;
|
|
436
|
+
statics[key] = function(...args) {
|
|
437
|
+
const manager = configure2.apply(this, args);
|
|
438
|
+
try {
|
|
439
|
+
const metadata = runMetadataFromContext();
|
|
440
|
+
if (manager && metadata) {
|
|
441
|
+
manager.addMetadata(metadata);
|
|
442
|
+
}
|
|
443
|
+
} catch (e2) {
|
|
444
|
+
}
|
|
445
|
+
return manager;
|
|
446
|
+
};
|
|
447
|
+
statics[PATCHED_MARKER] = true;
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
function patchInstalledCallbackManager() {
|
|
451
|
+
void (async () => {
|
|
452
|
+
try {
|
|
453
|
+
patchCallbackManagerModule(await Promise.resolve().then(() => _interopRequireWildcard(require("@langchain/core/callbacks/manager"))));
|
|
454
|
+
} catch (error) {
|
|
455
|
+
_chunkWC573FCIcjs.logger.debug(`LangChain callback manager not patched: ${String(error)}`);
|
|
456
|
+
}
|
|
457
|
+
})();
|
|
458
|
+
}
|
|
459
|
+
function restampLangChainSpan(span) {
|
|
460
|
+
try {
|
|
461
|
+
const scope = span.instrumentationScope;
|
|
462
|
+
if (_optionalChain([scope, 'optionalAccess', _6 => _6.name]) !== SCOPE_NAME) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const attrs = span.attributes;
|
|
466
|
+
const metadata = attrs["metadata"];
|
|
467
|
+
if (typeof metadata !== "string" || !metadata.includes(`"${_chunk5WBPX342cjs.BRIZZ}.`)) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const parsed = JSON.parse(metadata);
|
|
471
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
475
|
+
if (key.startsWith(`${_chunk5WBPX342cjs.BRIZZ}.`) && value !== null && value !== void 0) {
|
|
476
|
+
attrs[key] = String(value);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
} catch (error) {
|
|
480
|
+
_chunkWC573FCIcjs.logger.debug("Skipped LangChain span re-stamp", { err: error });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/internal/instrumentation/registry.ts
|
|
394
485
|
var InstrumentationRegistry = (_class = class _InstrumentationRegistry {constructor() { _class.prototype.__init.call(this); }
|
|
395
486
|
|
|
396
487
|
static getInstance() {
|
|
@@ -423,7 +514,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
423
514
|
* @private
|
|
424
515
|
*/
|
|
425
516
|
loadManualInstrumentations(instrumentations, exceptionLogger2) {
|
|
426
|
-
if (_optionalChain([this, 'access',
|
|
517
|
+
if (_optionalChain([this, 'access', _7 => _7.manualModules, 'optionalAccess', _8 => _8.openAI])) {
|
|
427
518
|
try {
|
|
428
519
|
const openAIInst = new (0, _openinferenceinstrumentationopenai.OpenAIInstrumentation)();
|
|
429
520
|
openAIInst.manuallyInstrument(this.manualModules.openAI);
|
|
@@ -434,18 +525,18 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
434
525
|
}
|
|
435
526
|
}
|
|
436
527
|
const instrumentationConfigs = [
|
|
437
|
-
{ class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access',
|
|
438
|
-
{ class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access',
|
|
439
|
-
{ class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access',
|
|
440
|
-
{ class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access',
|
|
528
|
+
{ class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access', _9 => _9.manualModules, 'optionalAccess', _10 => _10.anthropic]) },
|
|
529
|
+
{ class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access', _11 => _11.manualModules, 'optionalAccess', _12 => _12.cohere]) },
|
|
530
|
+
{ class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access', _13 => _13.manualModules, 'optionalAccess', _14 => _14.bedrock]) },
|
|
531
|
+
{ class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access', _15 => _15.manualModules, 'optionalAccess', _16 => _16.pinecone]) },
|
|
441
532
|
{
|
|
442
533
|
class: _instrumentationllamaindex.LlamaIndexInstrumentation,
|
|
443
534
|
name: "LlamaIndex",
|
|
444
|
-
module: _optionalChain([this, 'access',
|
|
535
|
+
module: _optionalChain([this, 'access', _17 => _17.manualModules, 'optionalAccess', _18 => _18.llamaindex])
|
|
445
536
|
},
|
|
446
|
-
{ class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access',
|
|
447
|
-
{ class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access',
|
|
448
|
-
{ class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access',
|
|
537
|
+
{ class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access', _19 => _19.manualModules, 'optionalAccess', _20 => _20.chromadb]) },
|
|
538
|
+
{ class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access', _21 => _21.manualModules, 'optionalAccess', _22 => _22.qdrant]) },
|
|
539
|
+
{ class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access', _23 => _23.manualModules, 'optionalAccess', _24 => _24.together]) }
|
|
449
540
|
];
|
|
450
541
|
for (const config of instrumentationConfigs) {
|
|
451
542
|
if (!config.module) {
|
|
@@ -461,13 +552,14 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
461
552
|
instrumentations.push(instrumentation);
|
|
462
553
|
}
|
|
463
554
|
}
|
|
464
|
-
if (_optionalChain([this, 'access',
|
|
555
|
+
if (_optionalChain([this, 'access', _25 => _25.manualModules, 'optionalAccess', _26 => _26.langchain, 'optionalAccess', _27 => _27.callbackManagerModule])) {
|
|
465
556
|
const callbackManagerModule = this.manualModules.langchain.callbackManagerModule;
|
|
466
557
|
void (async () => {
|
|
467
558
|
try {
|
|
468
559
|
const { LangChainInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("@arizeai/openinference-instrumentation-langchain")));
|
|
469
560
|
const lcInst = new LangChainInstrumentation();
|
|
470
561
|
lcInst.manuallyInstrument(callbackManagerModule);
|
|
562
|
+
patchCallbackManagerModule(callbackManagerModule);
|
|
471
563
|
_chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for LangChain");
|
|
472
564
|
} catch (error) {
|
|
473
565
|
_chunkWC573FCIcjs.logger.error(
|
|
@@ -476,7 +568,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
476
568
|
}
|
|
477
569
|
})();
|
|
478
570
|
}
|
|
479
|
-
if (_optionalChain([this, 'access',
|
|
571
|
+
if (_optionalChain([this, 'access', _28 => _28.manualModules, 'optionalAccess', _29 => _29.google_vertexai])) {
|
|
480
572
|
const vertexModule = this.manualModules.google_vertexai;
|
|
481
573
|
void (async () => {
|
|
482
574
|
try {
|
|
@@ -491,7 +583,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
491
583
|
}
|
|
492
584
|
})();
|
|
493
585
|
}
|
|
494
|
-
if (_optionalChain([this, 'access',
|
|
586
|
+
if (_optionalChain([this, 'access', _30 => _30.manualModules, 'optionalAccess', _31 => _31.google_genai])) {
|
|
495
587
|
const genaiModule = this.manualModules.google_genai;
|
|
496
588
|
void (async () => {
|
|
497
589
|
try {
|
|
@@ -506,11 +598,11 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
506
598
|
}
|
|
507
599
|
})();
|
|
508
600
|
}
|
|
509
|
-
if (_optionalChain([this, 'access',
|
|
601
|
+
if (_optionalChain([this, 'access', _32 => _32.manualModules, 'optionalAccess', _33 => _33.mcp])) {
|
|
510
602
|
const mcpModules = this.manualModules.mcp;
|
|
511
603
|
void (async () => {
|
|
512
604
|
try {
|
|
513
|
-
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-
|
|
605
|
+
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-CCFYA5CI.cjs")));
|
|
514
606
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
515
607
|
instrumentation.manuallyInstrument(mcpModules);
|
|
516
608
|
_chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -561,16 +653,16 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
561
653
|
}
|
|
562
654
|
for (const [key, value] of Object.entries(properties)) {
|
|
563
655
|
try {
|
|
564
|
-
current.setAttribute(`${
|
|
565
|
-
} catch (
|
|
656
|
+
current.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${key}`, value);
|
|
657
|
+
} catch (e3) {
|
|
566
658
|
}
|
|
567
659
|
}
|
|
568
660
|
}
|
|
569
661
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
570
662
|
const base = _api.context.active();
|
|
571
|
-
const prev = base.getValue(
|
|
663
|
+
const prev = base.getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
572
664
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
573
|
-
const next = base.setValue(
|
|
665
|
+
const next = base.setValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY, merged);
|
|
574
666
|
return _api.context.with(next, fn, thisArg, ...args);
|
|
575
667
|
}
|
|
576
668
|
function withProperties(properties, fn, thisArg) {
|
|
@@ -583,34 +675,33 @@ function withProperties(properties, fn, thisArg) {
|
|
|
583
675
|
);
|
|
584
676
|
};
|
|
585
677
|
}
|
|
586
|
-
function propagatePropertiesImperatively(properties) {
|
|
678
|
+
function propagatePropertiesImperatively(properties, base = _api.context.active()) {
|
|
587
679
|
try {
|
|
588
680
|
const manager = _api.context;
|
|
589
|
-
const mgr = _optionalChain([manager, 'access',
|
|
590
|
-
const store = _optionalChain([mgr, 'optionalAccess',
|
|
681
|
+
const mgr = _optionalChain([manager, 'access', _34 => _34._getContextManager, 'optionalCall', _35 => _35()]);
|
|
682
|
+
const store = _optionalChain([mgr, 'optionalAccess', _36 => _36._asyncLocalStorage]);
|
|
591
683
|
if (!store || typeof store.enterWith !== "function") {
|
|
592
684
|
return;
|
|
593
685
|
}
|
|
594
|
-
const
|
|
595
|
-
const prev = base.getValue(_chunkFORVS4QWcjs.PROPERTIES_CONTEXT_KEY);
|
|
686
|
+
const prev = base.getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
596
687
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
597
|
-
store.enterWith(base.setValue(
|
|
598
|
-
} catch (
|
|
688
|
+
store.enterWith(base.setValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY, merged));
|
|
689
|
+
} catch (e4) {
|
|
599
690
|
}
|
|
600
691
|
}
|
|
601
692
|
function setUser(user) {
|
|
602
|
-
const properties = { [
|
|
693
|
+
const properties = { [_chunk5WBPX342cjs.USER_ID]: user.id };
|
|
603
694
|
if (user.email !== void 0) {
|
|
604
|
-
properties[
|
|
695
|
+
properties[_chunk5WBPX342cjs.USER_EMAIL] = user.email;
|
|
605
696
|
}
|
|
606
697
|
if (user.name !== void 0) {
|
|
607
|
-
properties[
|
|
698
|
+
properties[_chunk5WBPX342cjs.USER_NAME] = user.name;
|
|
608
699
|
}
|
|
609
700
|
if (user.role !== void 0) {
|
|
610
|
-
properties[
|
|
701
|
+
properties[_chunk5WBPX342cjs.USER_ROLE] = user.role;
|
|
611
702
|
}
|
|
612
703
|
if (user.plan !== void 0) {
|
|
613
|
-
properties[
|
|
704
|
+
properties[_chunk5WBPX342cjs.USER_PLAN] = user.plan;
|
|
614
705
|
}
|
|
615
706
|
if (user.traits) {
|
|
616
707
|
for (const [key, value] of Object.entries(user.traits)) {
|
|
@@ -624,15 +715,15 @@ function setUser(user) {
|
|
|
624
715
|
propagatePropertiesImperatively(properties);
|
|
625
716
|
}
|
|
626
717
|
function setOrganization(org) {
|
|
627
|
-
const properties = { [
|
|
718
|
+
const properties = { [_chunk5WBPX342cjs.ORGANIZATION_ID]: org.id };
|
|
628
719
|
if (org.name !== void 0) {
|
|
629
|
-
properties[
|
|
720
|
+
properties[_chunk5WBPX342cjs.ORGANIZATION_NAME] = org.name;
|
|
630
721
|
}
|
|
631
722
|
if (org.plan !== void 0) {
|
|
632
|
-
properties[
|
|
723
|
+
properties[_chunk5WBPX342cjs.ORGANIZATION_PLAN] = org.plan;
|
|
633
724
|
}
|
|
634
725
|
if (org.domain !== void 0) {
|
|
635
|
-
properties[
|
|
726
|
+
properties[_chunk5WBPX342cjs.ORGANIZATION_DOMAIN] = org.domain;
|
|
636
727
|
}
|
|
637
728
|
if (org.traits) {
|
|
638
729
|
for (const [key, value] of Object.entries(org.traits)) {
|
|
@@ -646,12 +737,12 @@ function setOrganization(org) {
|
|
|
646
737
|
propagatePropertiesImperatively(properties);
|
|
647
738
|
}
|
|
648
739
|
function setMessageId(id) {
|
|
649
|
-
const properties = { [
|
|
740
|
+
const properties = { [_chunk5WBPX342cjs.MESSAGE_ID]: id };
|
|
650
741
|
setCurrentSpanCustomProperties(properties);
|
|
651
742
|
propagatePropertiesImperatively(properties);
|
|
652
743
|
}
|
|
653
744
|
function setSessionId(id) {
|
|
654
|
-
const properties = { [
|
|
745
|
+
const properties = { [_chunk5WBPX342cjs.SESSION_ID]: id };
|
|
655
746
|
setCurrentSpanCustomProperties(properties);
|
|
656
747
|
propagatePropertiesImperatively(properties);
|
|
657
748
|
}
|
|
@@ -674,7 +765,7 @@ function serviceNameProperties(name) {
|
|
|
674
765
|
);
|
|
675
766
|
return {};
|
|
676
767
|
}
|
|
677
|
-
return { [
|
|
768
|
+
return { [_chunk5WBPX342cjs.SERVICE_NAME]: name };
|
|
678
769
|
}
|
|
679
770
|
function setServiceName(name) {
|
|
680
771
|
const properties = serviceNameProperties(name);
|
|
@@ -688,22 +779,22 @@ function withServiceName(name, fn, thisArg) {
|
|
|
688
779
|
return withProperties(serviceNameProperties(name), fn, thisArg);
|
|
689
780
|
}
|
|
690
781
|
function resolveServiceNameFromContext() {
|
|
691
|
-
const props = _api.context.active().getValue(
|
|
692
|
-
return _optionalChain([props, 'optionalAccess',
|
|
782
|
+
const props = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
783
|
+
return _optionalChain([props, 'optionalAccess', _37 => _37[_chunk5WBPX342cjs.SERVICE_NAME]]);
|
|
693
784
|
}
|
|
694
785
|
function userProperties(user) {
|
|
695
|
-
const properties = { [
|
|
786
|
+
const properties = { [_chunk5WBPX342cjs.USER_ID]: user.id };
|
|
696
787
|
if (user.email !== void 0) {
|
|
697
|
-
properties[
|
|
788
|
+
properties[_chunk5WBPX342cjs.USER_EMAIL] = user.email;
|
|
698
789
|
}
|
|
699
790
|
if (user.name !== void 0) {
|
|
700
|
-
properties[
|
|
791
|
+
properties[_chunk5WBPX342cjs.USER_NAME] = user.name;
|
|
701
792
|
}
|
|
702
793
|
if (user.role !== void 0) {
|
|
703
|
-
properties[
|
|
794
|
+
properties[_chunk5WBPX342cjs.USER_ROLE] = user.role;
|
|
704
795
|
}
|
|
705
796
|
if (user.plan !== void 0) {
|
|
706
|
-
properties[
|
|
797
|
+
properties[_chunk5WBPX342cjs.USER_PLAN] = user.plan;
|
|
707
798
|
}
|
|
708
799
|
if (user.traits) {
|
|
709
800
|
for (const [key, value] of Object.entries(user.traits)) {
|
|
@@ -716,15 +807,15 @@ function userProperties(user) {
|
|
|
716
807
|
return properties;
|
|
717
808
|
}
|
|
718
809
|
function organizationProperties(org) {
|
|
719
|
-
const properties = { [
|
|
810
|
+
const properties = { [_chunk5WBPX342cjs.ORGANIZATION_ID]: org.id };
|
|
720
811
|
if (org.name !== void 0) {
|
|
721
|
-
properties[
|
|
812
|
+
properties[_chunk5WBPX342cjs.ORGANIZATION_NAME] = org.name;
|
|
722
813
|
}
|
|
723
814
|
if (org.plan !== void 0) {
|
|
724
|
-
properties[
|
|
815
|
+
properties[_chunk5WBPX342cjs.ORGANIZATION_PLAN] = org.plan;
|
|
725
816
|
}
|
|
726
817
|
if (org.domain !== void 0) {
|
|
727
|
-
properties[
|
|
818
|
+
properties[_chunk5WBPX342cjs.ORGANIZATION_DOMAIN] = org.domain;
|
|
728
819
|
}
|
|
729
820
|
if (org.traits) {
|
|
730
821
|
for (const [key, value] of Object.entries(org.traits)) {
|
|
@@ -749,32 +840,32 @@ function withOrganization(org, fn, thisArg) {
|
|
|
749
840
|
return withProperties(organizationProperties(org), fn, thisArg);
|
|
750
841
|
}
|
|
751
842
|
function callWithMessageId(id, fn, thisArg, ...args) {
|
|
752
|
-
return callWithProperties({ [
|
|
843
|
+
return callWithProperties({ [_chunk5WBPX342cjs.MESSAGE_ID]: id }, fn, thisArg, ...args);
|
|
753
844
|
}
|
|
754
845
|
function withMessageId(id, fn, thisArg) {
|
|
755
|
-
return withProperties({ [
|
|
846
|
+
return withProperties({ [_chunk5WBPX342cjs.MESSAGE_ID]: id }, fn, thisArg);
|
|
756
847
|
}
|
|
757
848
|
function inheritedMuteTools() {
|
|
758
|
-
const properties = _api.context.active().getValue(
|
|
759
|
-
return _optionalChain([properties, 'optionalAccess',
|
|
849
|
+
const properties = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
850
|
+
return _optionalChain([properties, 'optionalAccess', _38 => _38[_chunk5WBPX342cjs.MUTE_TOOLS]]);
|
|
760
851
|
}
|
|
761
852
|
function muteProperties(options) {
|
|
762
853
|
const { input = true, output = true, tools = output } = options;
|
|
763
854
|
const properties = {};
|
|
764
855
|
if (input) {
|
|
765
|
-
properties[
|
|
856
|
+
properties[_chunk5WBPX342cjs.MUTE_INPUT] = "true";
|
|
766
857
|
}
|
|
767
858
|
if (output) {
|
|
768
|
-
properties[
|
|
859
|
+
properties[_chunk5WBPX342cjs.MUTE_OUTPUT] = "true";
|
|
769
860
|
}
|
|
770
861
|
if (tools !== output) {
|
|
771
|
-
properties[
|
|
862
|
+
properties[_chunk5WBPX342cjs.MUTE_TOOLS] = String(tools);
|
|
772
863
|
} else {
|
|
773
864
|
const inherited = inheritedMuteTools();
|
|
774
865
|
if (tools && inherited === "false") {
|
|
775
|
-
properties[
|
|
866
|
+
properties[_chunk5WBPX342cjs.MUTE_TOOLS] = "true";
|
|
776
867
|
} else if (options.tools === false && inherited === "true") {
|
|
777
|
-
properties[
|
|
868
|
+
properties[_chunk5WBPX342cjs.MUTE_TOOLS] = "false";
|
|
778
869
|
}
|
|
779
870
|
}
|
|
780
871
|
return properties;
|
|
@@ -786,11 +877,11 @@ function withMute(options, fn, thisArg) {
|
|
|
786
877
|
return withProperties(muteProperties(options), fn, thisArg);
|
|
787
878
|
}
|
|
788
879
|
function withSessionId(sessionId, fn, thisArg, extraProperties) {
|
|
789
|
-
const properties = { [
|
|
880
|
+
const properties = { [_chunk5WBPX342cjs.SESSION_ID]: sessionId, ...extraProperties };
|
|
790
881
|
return withProperties(properties, fn, thisArg);
|
|
791
882
|
}
|
|
792
883
|
function callWithSessionId(sessionId, fn, thisArg, ...args) {
|
|
793
|
-
return callWithProperties({ [
|
|
884
|
+
return callWithProperties({ [_chunk5WBPX342cjs.SESSION_ID]: sessionId }, fn, thisArg, ...args);
|
|
794
885
|
}
|
|
795
886
|
var Session = (_class2 = class {
|
|
796
887
|
|
|
@@ -815,11 +906,11 @@ var Session = (_class2 = class {
|
|
|
815
906
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
816
907
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
817
908
|
*/
|
|
818
|
-
setInput(text,
|
|
909
|
+
setInput(text, context6) {
|
|
819
910
|
this.inputs.push(text);
|
|
820
|
-
this.inputContexts.push(_nullishCoalesce(
|
|
821
|
-
this.span.setAttribute(
|
|
822
|
-
this.span.setAttribute(
|
|
911
|
+
this.inputContexts.push(_nullishCoalesce(context6, () => ( {})));
|
|
912
|
+
this.span.setAttribute(_chunk5WBPX342cjs.SESSION_INPUT, JSON.stringify(this.inputs));
|
|
913
|
+
this.span.setAttribute(_chunk5WBPX342cjs.SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
|
|
823
914
|
}
|
|
824
915
|
/**
|
|
825
916
|
* Append an assistant turn to session output tracking.
|
|
@@ -831,11 +922,11 @@ var Session = (_class2 = class {
|
|
|
831
922
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
832
923
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
833
924
|
*/
|
|
834
|
-
setOutput(text,
|
|
925
|
+
setOutput(text, context6) {
|
|
835
926
|
this.outputs.push(text);
|
|
836
|
-
this.outputContexts.push(_nullishCoalesce(
|
|
837
|
-
this.span.setAttribute(
|
|
838
|
-
this.span.setAttribute(
|
|
927
|
+
this.outputContexts.push(_nullishCoalesce(context6, () => ( {})));
|
|
928
|
+
this.span.setAttribute(_chunk5WBPX342cjs.SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
929
|
+
this.span.setAttribute(_chunk5WBPX342cjs.SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
|
|
839
930
|
}
|
|
840
931
|
/**
|
|
841
932
|
* Set the session title on the span.
|
|
@@ -843,7 +934,7 @@ var Session = (_class2 = class {
|
|
|
843
934
|
* @param title - The generated title string
|
|
844
935
|
*/
|
|
845
936
|
setTitle(title) {
|
|
846
|
-
this.span.setAttribute(
|
|
937
|
+
this.span.setAttribute(_chunk5WBPX342cjs.SESSION_TITLE, title);
|
|
847
938
|
}
|
|
848
939
|
/**
|
|
849
940
|
* Update custom properties on the session span.
|
|
@@ -853,7 +944,7 @@ var Session = (_class2 = class {
|
|
|
853
944
|
*/
|
|
854
945
|
updateProperties(properties) {
|
|
855
946
|
for (const [key, value] of Object.entries(properties)) {
|
|
856
|
-
this.span.setAttribute(`${
|
|
947
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${key}`, value);
|
|
857
948
|
}
|
|
858
949
|
}
|
|
859
950
|
/**
|
|
@@ -865,21 +956,21 @@ var Session = (_class2 = class {
|
|
|
865
956
|
setUser(user) {
|
|
866
957
|
if (user.traits) {
|
|
867
958
|
for (const [key, value] of Object.entries(user.traits)) {
|
|
868
|
-
this.span.setAttribute(`${
|
|
959
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.user.${key}`, value);
|
|
869
960
|
}
|
|
870
961
|
}
|
|
871
|
-
this.span.setAttribute(`${
|
|
962
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.USER_ID}`, user.id);
|
|
872
963
|
if (user.email !== void 0) {
|
|
873
|
-
this.span.setAttribute(`${
|
|
964
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.USER_EMAIL}`, user.email);
|
|
874
965
|
}
|
|
875
966
|
if (user.name !== void 0) {
|
|
876
|
-
this.span.setAttribute(`${
|
|
967
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.USER_NAME}`, user.name);
|
|
877
968
|
}
|
|
878
969
|
if (user.role !== void 0) {
|
|
879
|
-
this.span.setAttribute(`${
|
|
970
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.USER_ROLE}`, user.role);
|
|
880
971
|
}
|
|
881
972
|
if (user.plan !== void 0) {
|
|
882
|
-
this.span.setAttribute(`${
|
|
973
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.USER_PLAN}`, user.plan);
|
|
883
974
|
}
|
|
884
975
|
}
|
|
885
976
|
/**
|
|
@@ -891,18 +982,18 @@ var Session = (_class2 = class {
|
|
|
891
982
|
setOrganization(org) {
|
|
892
983
|
if (org.traits) {
|
|
893
984
|
for (const [key, value] of Object.entries(org.traits)) {
|
|
894
|
-
this.span.setAttribute(`${
|
|
985
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.organization.${key}`, value);
|
|
895
986
|
}
|
|
896
987
|
}
|
|
897
|
-
this.span.setAttribute(`${
|
|
988
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.ORGANIZATION_ID}`, org.id);
|
|
898
989
|
if (org.name !== void 0) {
|
|
899
|
-
this.span.setAttribute(`${
|
|
990
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.ORGANIZATION_NAME}`, org.name);
|
|
900
991
|
}
|
|
901
992
|
if (org.plan !== void 0) {
|
|
902
|
-
this.span.setAttribute(`${
|
|
993
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.ORGANIZATION_PLAN}`, org.plan);
|
|
903
994
|
}
|
|
904
995
|
if (org.domain !== void 0) {
|
|
905
|
-
this.span.setAttribute(`${
|
|
996
|
+
this.span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.ORGANIZATION_DOMAIN}`, org.domain);
|
|
906
997
|
}
|
|
907
998
|
}
|
|
908
999
|
/**
|
|
@@ -918,7 +1009,7 @@ var Session = (_class2 = class {
|
|
|
918
1009
|
* (free-form category, defaults to `'generic'`)
|
|
919
1010
|
*/
|
|
920
1011
|
addExternalLink(url, options) {
|
|
921
|
-
emitExternalLink(this.sessionId, url, _optionalChain([options, 'optionalAccess',
|
|
1012
|
+
emitExternalLink(this.sessionId, url, _optionalChain([options, 'optionalAccess', _39 => _39.title]), _optionalChain([options, 'optionalAccess', _40 => _40.linkType]));
|
|
922
1013
|
}
|
|
923
1014
|
}, _class2);
|
|
924
1015
|
var SessionTitle = class {
|
|
@@ -932,69 +1023,69 @@ var SessionTitle = class {
|
|
|
932
1023
|
* @param title - The generated title string
|
|
933
1024
|
*/
|
|
934
1025
|
setTitle(title) {
|
|
935
|
-
this.span.setAttribute(
|
|
1026
|
+
this.span.setAttribute(_chunk5WBPX342cjs.SESSION_TITLE, title);
|
|
936
1027
|
}
|
|
937
1028
|
};
|
|
938
1029
|
function getActiveSession() {
|
|
939
|
-
return _api.context.active().getValue(
|
|
1030
|
+
return _api.context.active().getValue(_chunk5WBPX342cjs.SESSION_OBJECT_CONTEXT_KEY);
|
|
940
1031
|
}
|
|
941
1032
|
function resolveSessionIdFromContext() {
|
|
942
1033
|
const active = getActiveSession();
|
|
943
1034
|
if (active) {
|
|
944
1035
|
return active.sessionId;
|
|
945
1036
|
}
|
|
946
|
-
const props = _api.context.active().getValue(
|
|
947
|
-
return _optionalChain([props, 'optionalAccess',
|
|
1037
|
+
const props = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
1038
|
+
return _optionalChain([props, 'optionalAccess', _41 => _41[_chunk5WBPX342cjs.SESSION_ID]]);
|
|
948
1039
|
}
|
|
949
1040
|
function resolveMessageIdFromContext() {
|
|
950
|
-
const props = _api.context.active().getValue(
|
|
951
|
-
return _optionalChain([props, 'optionalAccess',
|
|
1041
|
+
const props = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
1042
|
+
return _optionalChain([props, 'optionalAccess', _42 => _42[_chunk5WBPX342cjs.MESSAGE_ID]]);
|
|
952
1043
|
}
|
|
953
1044
|
function emitExternalLink(sessionId, url, title, linkType) {
|
|
954
1045
|
try {
|
|
955
|
-
emitEventWithSessionId(sessionId,
|
|
956
|
-
[
|
|
957
|
-
[
|
|
958
|
-
[
|
|
1046
|
+
emitEventWithSessionId(sessionId, _chunk5WBPX342cjs.EXTERNAL_LINK_EVENT_NAME, {
|
|
1047
|
+
[_chunk5WBPX342cjs.EXTERNAL_LINK_URL]: url,
|
|
1048
|
+
[_chunk5WBPX342cjs.EXTERNAL_LINK_TITLE]: _nullishCoalesce(title, () => ( "")),
|
|
1049
|
+
[_chunk5WBPX342cjs.EXTERNAL_LINK_TYPE]: _nullishCoalesce(linkType, () => ( "generic"))
|
|
959
1050
|
});
|
|
960
1051
|
} catch (error) {
|
|
961
1052
|
_chunkWC573FCIcjs.logger.warn("addExternalLink: failed to emit external link", error);
|
|
962
1053
|
}
|
|
963
1054
|
}
|
|
964
1055
|
function addExternalLink(url, options) {
|
|
965
|
-
const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1056
|
+
const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _43 => _43.sessionId]), () => ( resolveSessionIdFromContext()));
|
|
966
1057
|
if (!sessionId) {
|
|
967
1058
|
_chunkWC573FCIcjs.logger.warn(
|
|
968
1059
|
"addExternalLink called without a resolvable session id; link dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope."
|
|
969
1060
|
);
|
|
970
1061
|
return;
|
|
971
1062
|
}
|
|
972
|
-
emitExternalLink(sessionId, url, _optionalChain([options, 'optionalAccess',
|
|
1063
|
+
emitExternalLink(sessionId, url, _optionalChain([options, 'optionalAccess', _44 => _44.title]), _optionalChain([options, 'optionalAccess', _45 => _45.linkType]));
|
|
973
1064
|
}
|
|
974
1065
|
function recordFeedback(type, options) {
|
|
975
|
-
const eventAttributes = { [
|
|
976
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
977
|
-
eventAttributes[
|
|
1066
|
+
const eventAttributes = { [_chunk5WBPX342cjs.FEEDBACK_TYPE]: type };
|
|
1067
|
+
if (_optionalChain([options, 'optionalAccess', _46 => _46.score]) !== void 0) {
|
|
1068
|
+
eventAttributes[_chunk5WBPX342cjs.FEEDBACK_SCORE] = options.score;
|
|
978
1069
|
}
|
|
979
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
980
|
-
eventAttributes[
|
|
1070
|
+
if (_optionalChain([options, 'optionalAccess', _47 => _47.reason]) !== void 0) {
|
|
1071
|
+
eventAttributes[_chunk5WBPX342cjs.FEEDBACK_REASON] = options.reason;
|
|
981
1072
|
}
|
|
982
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
983
|
-
eventAttributes[
|
|
1073
|
+
if (_optionalChain([options, 'optionalAccess', _48 => _48.comment]) !== void 0) {
|
|
1074
|
+
eventAttributes[_chunk5WBPX342cjs.FEEDBACK_COMMENT] = options.comment;
|
|
984
1075
|
}
|
|
985
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
986
|
-
eventAttributes[
|
|
1076
|
+
if (_optionalChain([options, 'optionalAccess', _49 => _49.source]) !== void 0) {
|
|
1077
|
+
eventAttributes[_chunk5WBPX342cjs.FEEDBACK_SOURCE] = options.source;
|
|
987
1078
|
}
|
|
988
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1079
|
+
if (_optionalChain([options, 'optionalAccess', _50 => _50.attributes])) {
|
|
989
1080
|
for (const [key, value] of Object.entries(options.attributes)) {
|
|
990
|
-
const k = `${
|
|
1081
|
+
const k = `${_chunk5WBPX342cjs.FEEDBACK_ATTR_PREFIX}${key}`;
|
|
991
1082
|
if (eventAttributes[k] === void 0) {
|
|
992
1083
|
eventAttributes[k] = value;
|
|
993
1084
|
}
|
|
994
1085
|
}
|
|
995
1086
|
}
|
|
996
|
-
const messageId = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
997
|
-
const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1087
|
+
const messageId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.messageId]), () => ( resolveMessageIdFromContext()));
|
|
1088
|
+
const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _52 => _52.sessionId]), () => ( resolveSessionIdFromContext()));
|
|
998
1089
|
if (messageId === void 0 && sessionId === void 0) {
|
|
999
1090
|
_chunkWC573FCIcjs.logger.warn(
|
|
1000
1091
|
"recordFeedback called with no resolvable message id or session id; the feedback cannot be attributed to a message or conversation. Pass options.messageId / options.sessionId or call inside a startSession/callWithMessageId scope."
|
|
@@ -1002,16 +1093,16 @@ function recordFeedback(type, options) {
|
|
|
1002
1093
|
}
|
|
1003
1094
|
const anchor = {};
|
|
1004
1095
|
if (messageId !== void 0) {
|
|
1005
|
-
anchor[
|
|
1096
|
+
anchor[_chunk5WBPX342cjs.MESSAGE_ID] = messageId;
|
|
1006
1097
|
}
|
|
1007
1098
|
if (sessionId !== void 0) {
|
|
1008
|
-
anchor[
|
|
1099
|
+
anchor[_chunk5WBPX342cjs.SESSION_ID] = sessionId;
|
|
1009
1100
|
}
|
|
1010
1101
|
try {
|
|
1011
1102
|
if (Object.keys(anchor).length === 0) {
|
|
1012
|
-
emitEvent(
|
|
1103
|
+
emitEvent(_chunk5WBPX342cjs.FEEDBACK_EVENT_NAME, eventAttributes);
|
|
1013
1104
|
} else {
|
|
1014
|
-
callWithProperties(anchor, () => emitEvent(
|
|
1105
|
+
callWithProperties(anchor, () => emitEvent(_chunk5WBPX342cjs.FEEDBACK_EVENT_NAME, eventAttributes));
|
|
1015
1106
|
}
|
|
1016
1107
|
} catch (error) {
|
|
1017
1108
|
_chunkWC573FCIcjs.logger.warn("recordFeedback: failed to emit feedback event", error);
|
|
@@ -1025,7 +1116,7 @@ function recordMetric(options) {
|
|
|
1025
1116
|
try {
|
|
1026
1117
|
recordMetricImpl(options);
|
|
1027
1118
|
} catch (error) {
|
|
1028
|
-
_chunkWC573FCIcjs.logger.warn(`recordMetric(${JSON.stringify(_optionalChain([options, 'optionalAccess',
|
|
1119
|
+
_chunkWC573FCIcjs.logger.warn(`recordMetric(${JSON.stringify(_optionalChain([options, 'optionalAccess', _53 => _53.name]))}) failed; metric dropped.`, error);
|
|
1029
1120
|
}
|
|
1030
1121
|
}
|
|
1031
1122
|
function recordMetricImpl(options) {
|
|
@@ -1036,7 +1127,7 @@ function recordMetricImpl(options) {
|
|
|
1036
1127
|
);
|
|
1037
1128
|
return;
|
|
1038
1129
|
}
|
|
1039
|
-
if (
|
|
1130
|
+
if (_chunk5WBPX342cjs.RESERVED_METRIC_NAMES.has(name)) {
|
|
1040
1131
|
_chunkWC573FCIcjs.logger.warn(
|
|
1041
1132
|
`recordMetric called with the reserved name ${JSON.stringify(name)}; metric dropped. Brizz computes this metric itself \u2014 pick a different name.`
|
|
1042
1133
|
);
|
|
@@ -1055,17 +1146,17 @@ function recordMetricImpl(options) {
|
|
|
1055
1146
|
return;
|
|
1056
1147
|
}
|
|
1057
1148
|
const eventAttributes = {
|
|
1058
|
-
[
|
|
1059
|
-
[
|
|
1149
|
+
[_chunk5WBPX342cjs.METRIC_NAME]: name,
|
|
1150
|
+
[_chunk5WBPX342cjs.METRIC_VALUE]: numericValue
|
|
1060
1151
|
};
|
|
1061
1152
|
if (options.unit !== void 0) {
|
|
1062
|
-
eventAttributes[
|
|
1153
|
+
eventAttributes[_chunk5WBPX342cjs.METRIC_UNIT] = options.unit;
|
|
1063
1154
|
}
|
|
1064
1155
|
if (options.minValue !== void 0) {
|
|
1065
|
-
eventAttributes[
|
|
1156
|
+
eventAttributes[_chunk5WBPX342cjs.METRIC_MIN] = options.minValue;
|
|
1066
1157
|
}
|
|
1067
1158
|
if (options.maxValue !== void 0) {
|
|
1068
|
-
eventAttributes[
|
|
1159
|
+
eventAttributes[_chunk5WBPX342cjs.METRIC_MAX] = options.maxValue;
|
|
1069
1160
|
}
|
|
1070
1161
|
if (options.comment !== void 0) {
|
|
1071
1162
|
let comment = options.comment;
|
|
@@ -1075,21 +1166,21 @@ function recordMetricImpl(options) {
|
|
|
1075
1166
|
);
|
|
1076
1167
|
comment = comment.slice(0, METRIC_COMMENT_MAX_LEN);
|
|
1077
1168
|
}
|
|
1078
|
-
eventAttributes[
|
|
1169
|
+
eventAttributes[_chunk5WBPX342cjs.METRIC_COMMENT] = comment;
|
|
1079
1170
|
}
|
|
1080
1171
|
if (options.polarity !== void 0) {
|
|
1081
1172
|
const polarity = options.polarity;
|
|
1082
|
-
if (polarity ===
|
|
1083
|
-
eventAttributes[
|
|
1173
|
+
if (polarity === _chunk5WBPX342cjs.METRIC_POLARITY_POSITIVE || polarity === _chunk5WBPX342cjs.METRIC_POLARITY_NEGATIVE) {
|
|
1174
|
+
eventAttributes[_chunk5WBPX342cjs.METRIC_POLARITY] = polarity;
|
|
1084
1175
|
} else {
|
|
1085
1176
|
_chunkWC573FCIcjs.logger.warn(
|
|
1086
|
-
`recordMetric(${name}) called with an invalid polarity ${JSON.stringify(polarity)}; expected '${
|
|
1177
|
+
`recordMetric(${name}) called with an invalid polarity ${JSON.stringify(polarity)}; expected '${_chunk5WBPX342cjs.METRIC_POLARITY_POSITIVE}' or '${_chunk5WBPX342cjs.METRIC_POLARITY_NEGATIVE}'. Emitting the metric without it.`
|
|
1087
1178
|
);
|
|
1088
1179
|
}
|
|
1089
1180
|
}
|
|
1090
1181
|
if (options.timestamp !== void 0) {
|
|
1091
1182
|
if (Number.isFinite(options.timestamp.getTime())) {
|
|
1092
|
-
eventAttributes[
|
|
1183
|
+
eventAttributes[_chunk5WBPX342cjs.METRIC_TIMESTAMP] = options.timestamp.toISOString();
|
|
1093
1184
|
} else {
|
|
1094
1185
|
_chunkWC573FCIcjs.logger.warn(
|
|
1095
1186
|
`recordMetric(${name}) called with an invalid timestamp; emitting the metric without it.`
|
|
@@ -1119,7 +1210,7 @@ function recordMetricImpl(options) {
|
|
|
1119
1210
|
);
|
|
1120
1211
|
text = text.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
|
|
1121
1212
|
}
|
|
1122
|
-
eventAttributes[`${
|
|
1213
|
+
eventAttributes[`${_chunk5WBPX342cjs.METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text;
|
|
1123
1214
|
accepted += 1;
|
|
1124
1215
|
}
|
|
1125
1216
|
}
|
|
@@ -1132,28 +1223,28 @@ function recordMetricImpl(options) {
|
|
|
1132
1223
|
}
|
|
1133
1224
|
try {
|
|
1134
1225
|
callWithProperties(
|
|
1135
|
-
{ [
|
|
1136
|
-
() => emitEvent(
|
|
1226
|
+
{ [_chunk5WBPX342cjs.SESSION_ID]: sessionId },
|
|
1227
|
+
() => emitEvent(_chunk5WBPX342cjs.METRIC_EVENT_NAME, eventAttributes)
|
|
1137
1228
|
);
|
|
1138
1229
|
} catch (error) {
|
|
1139
1230
|
_chunkWC573FCIcjs.logger.warn("recordMetric: failed to emit metric event", error);
|
|
1140
1231
|
}
|
|
1141
1232
|
}
|
|
1142
1233
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
1143
|
-
const isTitle = _optionalChain([options, 'optionalAccess',
|
|
1144
|
-
const spanName = isTitle ?
|
|
1234
|
+
const isTitle = _optionalChain([options, 'optionalAccess', _54 => _54.mode]) === "title";
|
|
1235
|
+
const spanName = isTitle ? _chunk5WBPX342cjs.SESSION_TITLE_SPAN_NAME : _chunk5WBPX342cjs.SESSION_SPAN_NAME;
|
|
1145
1236
|
const tracer = _api.trace.getTracer("@brizz/sdk");
|
|
1146
1237
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
1147
|
-
span.setAttribute(`${
|
|
1238
|
+
span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.SESSION_ID}`, sessionId);
|
|
1148
1239
|
if (extraProperties) {
|
|
1149
1240
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1150
|
-
span.setAttribute(`${
|
|
1241
|
+
span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${key}`, value);
|
|
1151
1242
|
}
|
|
1152
1243
|
}
|
|
1153
1244
|
const session = new Session(sessionId, span);
|
|
1154
|
-
const contextProperties = { [
|
|
1245
|
+
const contextProperties = { [_chunk5WBPX342cjs.SESSION_ID]: sessionId };
|
|
1155
1246
|
if (isTitle) {
|
|
1156
|
-
contextProperties[
|
|
1247
|
+
contextProperties[_chunk5WBPX342cjs.SESSION_TITLE_GENERATION] = "true";
|
|
1157
1248
|
}
|
|
1158
1249
|
if (extraProperties) {
|
|
1159
1250
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
@@ -1161,7 +1252,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1161
1252
|
}
|
|
1162
1253
|
}
|
|
1163
1254
|
return callWithProperties(contextProperties, () => {
|
|
1164
|
-
const sessionCtx = _api.context.active().setValue(
|
|
1255
|
+
const sessionCtx = _api.context.active().setValue(_chunk5WBPX342cjs.SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1165
1256
|
return _api.context.with(sessionCtx, () => {
|
|
1166
1257
|
try {
|
|
1167
1258
|
const result = callback(session);
|
|
@@ -1189,16 +1280,16 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1189
1280
|
});
|
|
1190
1281
|
}
|
|
1191
1282
|
function startSessionTitle(callback, options) {
|
|
1192
|
-
const resolvedSessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1283
|
+
const resolvedSessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _55 => _55.sessionId]), () => ( _optionalChain([getActiveSession, 'call', _56 => _56(), 'optionalAccess', _57 => _57.sessionId])));
|
|
1193
1284
|
const tracer = _api.trace.getTracer("@brizz/sdk");
|
|
1194
|
-
return tracer.startActiveSpan(
|
|
1285
|
+
return tracer.startActiveSpan(_chunk5WBPX342cjs.SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1195
1286
|
if (resolvedSessionId) {
|
|
1196
|
-
span.setAttribute(`${
|
|
1287
|
+
span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${_chunk5WBPX342cjs.SESSION_ID}`, resolvedSessionId);
|
|
1197
1288
|
}
|
|
1198
1289
|
const sessionTitle = new SessionTitle(span);
|
|
1199
|
-
const properties = { [
|
|
1290
|
+
const properties = { [_chunk5WBPX342cjs.SESSION_TITLE_GENERATION]: "true" };
|
|
1200
1291
|
if (resolvedSessionId) {
|
|
1201
|
-
properties[
|
|
1292
|
+
properties[_chunk5WBPX342cjs.SESSION_ID] = resolvedSessionId;
|
|
1202
1293
|
}
|
|
1203
1294
|
return callWithProperties(properties, () => {
|
|
1204
1295
|
try {
|
|
@@ -1661,14 +1752,14 @@ var BrizzSimpleLogRecordProcessor = class extends _sdklogs.SimpleLogRecordProces
|
|
|
1661
1752
|
this.config = config;
|
|
1662
1753
|
}
|
|
1663
1754
|
onEmit(logRecord) {
|
|
1664
|
-
const maskingConfig = _optionalChain([this, 'access',
|
|
1755
|
+
const maskingConfig = _optionalChain([this, 'access', _58 => _58.config, 'access', _59 => _59.masking, 'optionalAccess', _60 => _60.eventMasking]);
|
|
1665
1756
|
if (maskingConfig) {
|
|
1666
1757
|
maskLog(logRecord, maskingConfig);
|
|
1667
1758
|
}
|
|
1668
|
-
const associationProperties = _api.context.active().getValue(
|
|
1759
|
+
const associationProperties = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
1669
1760
|
if (associationProperties) {
|
|
1670
1761
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1671
|
-
logRecord.setAttribute(`${
|
|
1762
|
+
logRecord.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${key}`, value);
|
|
1672
1763
|
}
|
|
1673
1764
|
}
|
|
1674
1765
|
super.onEmit(logRecord);
|
|
@@ -1681,14 +1772,14 @@ var BrizzBatchLogRecordProcessor = class extends _sdklogs.BatchLogRecordProcesso
|
|
|
1681
1772
|
this.config = config;
|
|
1682
1773
|
}
|
|
1683
1774
|
onEmit(logRecord) {
|
|
1684
|
-
const maskingConfig = _optionalChain([this, 'access',
|
|
1775
|
+
const maskingConfig = _optionalChain([this, 'access', _61 => _61.config, 'access', _62 => _62.masking, 'optionalAccess', _63 => _63.eventMasking]);
|
|
1685
1776
|
if (maskingConfig) {
|
|
1686
1777
|
maskLog(logRecord, maskingConfig);
|
|
1687
1778
|
}
|
|
1688
|
-
const associationProperties = _api.context.active().getValue(
|
|
1779
|
+
const associationProperties = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
1689
1780
|
if (associationProperties) {
|
|
1690
1781
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1691
|
-
logRecord.setAttribute(`${
|
|
1782
|
+
logRecord.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${key}`, value);
|
|
1692
1783
|
}
|
|
1693
1784
|
}
|
|
1694
1785
|
super.onEmit(logRecord);
|
|
@@ -1715,7 +1806,7 @@ function maskLog(logRecord, config) {
|
|
|
1715
1806
|
newAttributes[key] = value;
|
|
1716
1807
|
}
|
|
1717
1808
|
for (const [key, value] of Object.entries(logRecord.attributes)) {
|
|
1718
|
-
if (key.startsWith(
|
|
1809
|
+
if (key.startsWith(_chunk5WBPX342cjs.INTERNAL_EVENT_PREFIX)) {
|
|
1719
1810
|
newAttributes[key] = value;
|
|
1720
1811
|
}
|
|
1721
1812
|
}
|
|
@@ -1773,14 +1864,14 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
|
|
|
1773
1864
|
_chunkWC573FCIcjs.logger.debug("Creating logger provider", {
|
|
1774
1865
|
serviceName,
|
|
1775
1866
|
disableBatch: config.disableBatch,
|
|
1776
|
-
hasMasking: !!_optionalChain([config, 'access',
|
|
1867
|
+
hasMasking: !!_optionalChain([config, 'access', _64 => _64.masking, 'optionalAccess', _65 => _65.eventMasking])
|
|
1777
1868
|
});
|
|
1778
1869
|
const exporter = this.createLogExporter(config, serviceName);
|
|
1779
1870
|
const processor = config.disableBatch ? new BrizzSimpleLogRecordProcessor(exporter, config) : new BrizzBatchLogRecordProcessor(exporter, config);
|
|
1780
1871
|
const resourceAttributes = {
|
|
1781
1872
|
...config.resourceAttributes,
|
|
1782
1873
|
"service.name": serviceName,
|
|
1783
|
-
[BRIZZ_SDK_VERSION]:
|
|
1874
|
+
[BRIZZ_SDK_VERSION]: _chunkCBEDIRVKcjs.getSDKVersion.call(void 0, ),
|
|
1784
1875
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1785
1876
|
};
|
|
1786
1877
|
if (config.environment) {
|
|
@@ -2029,7 +2120,7 @@ var BrizzSpanExporter = (_class5 = class {
|
|
|
2029
2120
|
const resourceAttrs = {
|
|
2030
2121
|
...config.resourceAttributes,
|
|
2031
2122
|
"service.name": config.appName,
|
|
2032
|
-
[BRIZZ_SDK_VERSION]:
|
|
2123
|
+
[BRIZZ_SDK_VERSION]: _chunkCBEDIRVKcjs.getSDKVersion.call(void 0, ),
|
|
2033
2124
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
2034
2125
|
};
|
|
2035
2126
|
if (config.environment) {
|
|
@@ -2043,7 +2134,7 @@ var BrizzSpanExporter = (_class5 = class {
|
|
|
2043
2134
|
}
|
|
2044
2135
|
/** The service a span reports under: its scoped override, else the configured appName. */
|
|
2045
2136
|
_serviceNameOf(span) {
|
|
2046
|
-
const value = span.attributes[
|
|
2137
|
+
const value = span.attributes[_chunk5WBPX342cjs.SERVICE_NAME_ATTRIBUTE];
|
|
2047
2138
|
return typeof value === "string" && value !== "" ? value : this._defaultServiceName;
|
|
2048
2139
|
}
|
|
2049
2140
|
_resourceFor(serviceName) {
|
|
@@ -2156,8 +2247,8 @@ var BrizzSpanExporter = (_class5 = class {
|
|
|
2156
2247
|
}
|
|
2157
2248
|
async forceFlush() {
|
|
2158
2249
|
await Promise.all([
|
|
2159
|
-
_optionalChain([this, 'access',
|
|
2160
|
-
...[...this._delegates.values()].map(async (delegate) => _optionalChain([delegate, 'access',
|
|
2250
|
+
_optionalChain([this, 'access', _66 => _66._delegate, 'access', _67 => _67.forceFlush, 'optionalCall', _68 => _68()]),
|
|
2251
|
+
...[...this._delegates.values()].map(async (delegate) => _optionalChain([delegate, 'access', _69 => _69.forceFlush, 'optionalCall', _70 => _70()]))
|
|
2161
2252
|
]);
|
|
2162
2253
|
}
|
|
2163
2254
|
}, _class5);
|
|
@@ -2169,10 +2260,10 @@ var BrizzSpanExporter = (_class5 = class {
|
|
|
2169
2260
|
|
|
2170
2261
|
var _sdktracebase = require('@opentelemetry/sdk-trace-base');
|
|
2171
2262
|
function applyContextAttributes(span) {
|
|
2172
|
-
const sessionProperties = _api.context.active().getValue(
|
|
2263
|
+
const sessionProperties = _api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY);
|
|
2173
2264
|
if (sessionProperties) {
|
|
2174
2265
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2175
|
-
span.setAttribute(`${
|
|
2266
|
+
span.setAttribute(`${_chunk5WBPX342cjs.BRIZZ}.${key}`, value);
|
|
2176
2267
|
}
|
|
2177
2268
|
}
|
|
2178
2269
|
}
|
|
@@ -2193,7 +2284,8 @@ var BrizzSimpleSpanProcessor = class extends _sdktracebase.SimpleSpanProcessor {
|
|
|
2193
2284
|
super.onStart(span, parentContext);
|
|
2194
2285
|
}
|
|
2195
2286
|
onEnd(span) {
|
|
2196
|
-
|
|
2287
|
+
restampLangChainSpan(span);
|
|
2288
|
+
const maskingConfig = _optionalChain([this, 'access', _71 => _71.config, 'access', _72 => _72.masking, 'optionalAccess', _73 => _73.spanMasking]);
|
|
2197
2289
|
if (maskingConfig) {
|
|
2198
2290
|
maskReadableSpan(span, maskingConfig);
|
|
2199
2291
|
}
|
|
@@ -2211,7 +2303,8 @@ var BrizzBatchSpanProcessor = class extends _sdktracebase.BatchSpanProcessor {
|
|
|
2211
2303
|
super.onStart(span, parentContext);
|
|
2212
2304
|
}
|
|
2213
2305
|
onEnd(span) {
|
|
2214
|
-
|
|
2306
|
+
restampLangChainSpan(span);
|
|
2307
|
+
const maskingConfig = _optionalChain([this, 'access', _74 => _74.config, 'access', _75 => _75.masking, 'optionalAccess', _76 => _76.spanMasking]);
|
|
2215
2308
|
if (maskingConfig) {
|
|
2216
2309
|
maskReadableSpan(span, maskingConfig);
|
|
2217
2310
|
}
|
|
@@ -2298,7 +2391,7 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
|
|
|
2298
2391
|
}
|
|
2299
2392
|
_chunkWC573FCIcjs.logger.debug("Initializing span processor", {
|
|
2300
2393
|
disableBatch: config.disableBatch,
|
|
2301
|
-
hasMasking: !!_optionalChain([config, 'access',
|
|
2394
|
+
hasMasking: !!_optionalChain([config, 'access', _77 => _77.masking, 'optionalAccess', _78 => _78.spanMasking])
|
|
2302
2395
|
});
|
|
2303
2396
|
const spanProcessor = config.disableBatch ? new BrizzSimpleSpanProcessor(this.spanExporter, config) : new BrizzBatchSpanProcessor(this.spanExporter, config);
|
|
2304
2397
|
_chunkWC573FCIcjs.logger.debug("Span processor initialized successfully");
|
|
@@ -2362,6 +2455,133 @@ function getSpanProcessor() {
|
|
|
2362
2455
|
return TracingModule.getInstance().getSpanProcessor();
|
|
2363
2456
|
}
|
|
2364
2457
|
|
|
2458
|
+
// src/internal/trace/agent.ts
|
|
2459
|
+
var _crypto = require('crypto');
|
|
2460
|
+
|
|
2461
|
+
function newInstanceId() {
|
|
2462
|
+
return _crypto.randomUUID.call(void 0, ).replaceAll("-", "").slice(0, 8);
|
|
2463
|
+
}
|
|
2464
|
+
function activeProperties() {
|
|
2465
|
+
return _nullishCoalesce(_api.context.active().getValue(_chunk5WBPX342cjs.PROPERTIES_CONTEXT_KEY), () => ( {}));
|
|
2466
|
+
}
|
|
2467
|
+
function encodeToken(agent) {
|
|
2468
|
+
const payload = {
|
|
2469
|
+
id: agent.id,
|
|
2470
|
+
parentId: agent.parentId,
|
|
2471
|
+
name: agent.name,
|
|
2472
|
+
traceparent: agent.traceparent,
|
|
2473
|
+
sessionId: agent.sessionId
|
|
2474
|
+
};
|
|
2475
|
+
return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
2476
|
+
}
|
|
2477
|
+
function currentTraceparent() {
|
|
2478
|
+
const carrier = {};
|
|
2479
|
+
try {
|
|
2480
|
+
_api.propagation.inject(_api.context.active(), carrier);
|
|
2481
|
+
} catch (e5) {
|
|
2482
|
+
}
|
|
2483
|
+
return _nullishCoalesce(carrier["traceparent"], () => ( ""));
|
|
2484
|
+
}
|
|
2485
|
+
function agentHandle(id, parentId, name) {
|
|
2486
|
+
const opened = {
|
|
2487
|
+
id,
|
|
2488
|
+
parentId,
|
|
2489
|
+
name,
|
|
2490
|
+
traceparent: currentTraceparent(),
|
|
2491
|
+
sessionId: _nullishCoalesce(activeProperties()[_chunk5WBPX342cjs.SESSION_ID], () => ( ""))
|
|
2492
|
+
};
|
|
2493
|
+
return {
|
|
2494
|
+
...opened,
|
|
2495
|
+
get token() {
|
|
2496
|
+
return encodeToken(opened);
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
function decodeToken(token) {
|
|
2501
|
+
try {
|
|
2502
|
+
const payload = JSON.parse(Buffer.from(token, "base64url").toString("utf8"));
|
|
2503
|
+
return payload.id ? payload : void 0;
|
|
2504
|
+
} catch (e6) {
|
|
2505
|
+
return void 0;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
function unreadableAgent(agent) {
|
|
2509
|
+
return {
|
|
2510
|
+
id: "",
|
|
2511
|
+
parentId: "",
|
|
2512
|
+
name: "",
|
|
2513
|
+
traceparent: "",
|
|
2514
|
+
sessionId: "",
|
|
2515
|
+
token: typeof agent === "string" ? "" : _nullishCoalesce(agent.token, () => ( ""))
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
function resolveAgent(agent) {
|
|
2519
|
+
const options = typeof agent === "string" ? { name: agent } : agent;
|
|
2520
|
+
let id;
|
|
2521
|
+
let parentId;
|
|
2522
|
+
let name;
|
|
2523
|
+
let sessionId = "";
|
|
2524
|
+
let parentContext = _api.context.active();
|
|
2525
|
+
if (options.token === void 0) {
|
|
2526
|
+
id = options.id || newInstanceId();
|
|
2527
|
+
parentId = options.parentId || activeProperties()[_chunk5WBPX342cjs.AGENT_ID] || "";
|
|
2528
|
+
name = _nullishCoalesce(options.name, () => ( ""));
|
|
2529
|
+
} else {
|
|
2530
|
+
const decoded = decodeToken(options.token);
|
|
2531
|
+
if (!decoded) {
|
|
2532
|
+
_chunkWC573FCIcjs.logger.warn("Brizz: ignoring an unreadable agent token");
|
|
2533
|
+
return void 0;
|
|
2534
|
+
}
|
|
2535
|
+
id = decoded.id;
|
|
2536
|
+
parentId = decoded.parentId;
|
|
2537
|
+
name = decoded.name;
|
|
2538
|
+
sessionId = decoded.sessionId;
|
|
2539
|
+
if (decoded.traceparent) {
|
|
2540
|
+
try {
|
|
2541
|
+
parentContext = _api.propagation.extract(parentContext, { traceparent: decoded.traceparent });
|
|
2542
|
+
} catch (e7) {
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
const properties = { [_chunk5WBPX342cjs.AGENT_ID]: id, [_chunk5WBPX342cjs.AGENT_NAME]: name };
|
|
2547
|
+
if (parentId) {
|
|
2548
|
+
properties[_chunk5WBPX342cjs.AGENT_PARENT_ID] = parentId;
|
|
2549
|
+
}
|
|
2550
|
+
if (sessionId) {
|
|
2551
|
+
properties[_chunk5WBPX342cjs.SESSION_ID] = sessionId;
|
|
2552
|
+
}
|
|
2553
|
+
return { id, parentId, name, properties, parentContext };
|
|
2554
|
+
}
|
|
2555
|
+
function startAgent(agent, callback) {
|
|
2556
|
+
const resolved = resolveAgent(agent);
|
|
2557
|
+
if (!resolved) {
|
|
2558
|
+
return callback(unreadableAgent(agent));
|
|
2559
|
+
}
|
|
2560
|
+
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2561
|
+
return _api.context.with(
|
|
2562
|
+
parentContext,
|
|
2563
|
+
() => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
function withAgent(agent, fn, thisArg) {
|
|
2567
|
+
return function wrapped(...args) {
|
|
2568
|
+
return startAgent(
|
|
2569
|
+
agent,
|
|
2570
|
+
() => fn.apply(thisArg !== void 0 ? thisArg : this, args)
|
|
2571
|
+
);
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
function setAgent(agent) {
|
|
2575
|
+
const resolved = resolveAgent(agent);
|
|
2576
|
+
if (!resolved) {
|
|
2577
|
+
return unreadableAgent(agent);
|
|
2578
|
+
}
|
|
2579
|
+
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2580
|
+
setCurrentSpanCustomProperties(properties);
|
|
2581
|
+
propagatePropertiesImperatively(properties, parentContext);
|
|
2582
|
+
return agentHandle(id, parentId, name);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2365
2585
|
// src/internal/sdk.ts
|
|
2366
2586
|
function resolveMcpSessionTracking(configured) {
|
|
2367
2587
|
const fromEnv = process.env["BRIZZ_MCP_SESSION_TRACKING"];
|
|
@@ -2391,7 +2611,8 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
|
|
|
2391
2611
|
*/
|
|
2392
2612
|
setupInstrumentation(options) {
|
|
2393
2613
|
const registry = InstrumentationRegistry.getInstance();
|
|
2394
|
-
|
|
2614
|
+
_chunkCBEDIRVKcjs.configure.call(void 0, resolveMcpSessionTracking(options.mcpSessionTracking));
|
|
2615
|
+
patchInstalledCallbackManager();
|
|
2395
2616
|
if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
|
|
2396
2617
|
registry.setManualModules(options.instrumentModules);
|
|
2397
2618
|
}
|
|
@@ -2414,7 +2635,7 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
|
|
|
2414
2635
|
const resourceAttributes = {
|
|
2415
2636
|
...resolvedConfig.resourceAttributes,
|
|
2416
2637
|
"service.name": resolvedConfig.appName,
|
|
2417
|
-
[BRIZZ_SDK_VERSION]:
|
|
2638
|
+
[BRIZZ_SDK_VERSION]: _chunkCBEDIRVKcjs.getSDKVersion.call(void 0, ),
|
|
2418
2639
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
2419
2640
|
};
|
|
2420
2641
|
if (resolvedConfig.environment) {
|
|
@@ -2426,7 +2647,7 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
|
|
|
2426
2647
|
const resource = _resources2.defaultResource.call(void 0, ).merge(_resources2.detectResources.call(void 0, { detectors: [_resources2.envDetector, _resources2.hostDetector, _resources2.processDetector] })).merge(_resources2.resourceFromAttributes.call(void 0, resourceAttributes));
|
|
2427
2648
|
this._tracerProvider = new (0, _sdktracenode.NodeTracerProvider)({
|
|
2428
2649
|
resource,
|
|
2429
|
-
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new (0,
|
|
2650
|
+
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new (0, _chunk3IGBYXLRcjs.InterruptPropagator)(), getSpanProcessor()]
|
|
2430
2651
|
});
|
|
2431
2652
|
this._tracerProvider.register();
|
|
2432
2653
|
this._meterProvider = new (0, _sdkmetrics.MeterProvider)({ resource, readers: [getMetricsReader()] });
|
|
@@ -2484,19 +2705,19 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
|
|
|
2484
2705
|
try {
|
|
2485
2706
|
const tracingModule = TracingModule.getInstance();
|
|
2486
2707
|
await tracingModule.shutdown();
|
|
2487
|
-
} catch (
|
|
2708
|
+
} catch (e8) {
|
|
2488
2709
|
_chunkWC573FCIcjs.logger.debug("Tracing module already shut down or not initialized");
|
|
2489
2710
|
}
|
|
2490
2711
|
try {
|
|
2491
2712
|
const metricsModule = MetricsModule.getInstance();
|
|
2492
2713
|
metricsModule.shutdown();
|
|
2493
|
-
} catch (
|
|
2714
|
+
} catch (e9) {
|
|
2494
2715
|
_chunkWC573FCIcjs.logger.debug("Metrics module already shut down or not initialized");
|
|
2495
2716
|
}
|
|
2496
2717
|
try {
|
|
2497
2718
|
const loggingModule = LoggingModule.getInstance();
|
|
2498
2719
|
await loggingModule.shutdown();
|
|
2499
|
-
} catch (
|
|
2720
|
+
} catch (e10) {
|
|
2500
2721
|
_chunkWC573FCIcjs.logger.debug("Logging module already shut down or not initialized");
|
|
2501
2722
|
}
|
|
2502
2723
|
_chunkWC573FCIcjs.logger.info("All telemetry modules shut down successfully");
|
|
@@ -2562,10 +2783,10 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
|
|
|
2562
2783
|
}
|
|
2563
2784
|
try {
|
|
2564
2785
|
await this.shutdownModules();
|
|
2565
|
-
await _optionalChain([this, 'access',
|
|
2566
|
-
await _optionalChain([this, 'access',
|
|
2567
|
-
await _optionalChain([this, 'access',
|
|
2568
|
-
await _optionalChain([this, 'access',
|
|
2786
|
+
await _optionalChain([this, 'access', _79 => _79._tracerProvider, 'optionalAccess', _80 => _80.forceFlush, 'call', _81 => _81()]);
|
|
2787
|
+
await _optionalChain([this, 'access', _82 => _82._tracerProvider, 'optionalAccess', _83 => _83.shutdown, 'call', _84 => _84()]);
|
|
2788
|
+
await _optionalChain([this, 'access', _85 => _85._meterProvider, 'optionalAccess', _86 => _86.forceFlush, 'call', _87 => _87()]);
|
|
2789
|
+
await _optionalChain([this, 'access', _88 => _88._meterProvider, 'optionalAccess', _89 => _89.shutdown, 'call', _90 => _90()]);
|
|
2569
2790
|
this._initialized = false;
|
|
2570
2791
|
this._tracerProvider = null;
|
|
2571
2792
|
this._meterProvider = null;
|
|
@@ -2629,4 +2850,7 @@ var Brizz = new _Brizz();
|
|
|
2629
2850
|
|
|
2630
2851
|
|
|
2631
2852
|
|
|
2632
|
-
|
|
2853
|
+
|
|
2854
|
+
|
|
2855
|
+
|
|
2856
|
+
exports.Brizz = Brizz; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.LogLevel = _chunkWC573FCIcjs.LogLevel; exports.Session = Session; exports.SessionTitle = SessionTitle; exports.SeverityNumber = _apilogs.SeverityNumber; exports.addExternalLink = addExternalLink; exports.callWithMessageId = callWithMessageId; exports.callWithMute = callWithMute; exports.callWithOrganization = callWithOrganization; exports.callWithProperties = callWithProperties; exports.callWithServiceName = callWithServiceName; exports.callWithSessionId = callWithSessionId; exports.callWithUser = callWithUser; exports.emitEvent = emitEvent; exports.emitEventWithSessionId = emitEventWithSessionId; exports.getActiveSession = getActiveSession; exports.getLogLevel = _chunkWC573FCIcjs.getLogLevel; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.logger = _chunkWC573FCIcjs.logger; exports.maskAttributes = maskAttributes; exports.maskValue = maskValue; exports.recordFeedback = recordFeedback; exports.recordMetric = recordMetric; exports.setAgent = setAgent; exports.setCurrentSpanCustomProperties = setCurrentSpanCustomProperties; exports.setLogLevel = _chunkWC573FCIcjs.setLogLevel; exports.setMessageId = setMessageId; exports.setOrganization = setOrganization; exports.setServiceName = setServiceName; exports.setSessionId = setSessionId; exports.setUser = setUser; exports.startAgent = startAgent; exports.startSession = startSession; exports.startSessionTitle = startSessionTitle; exports.withAgent = withAgent; exports.withMessageId = withMessageId; exports.withMute = withMute; exports.withOrganization = withOrganization; exports.withProperties = withProperties; exports.withServiceName = withServiceName; exports.withSessionId = withSessionId; exports.withUser = withUser;
|