@microsoft/agents-a365-observability 0.1.0-preview.30
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 +33 -0
- package/dist/cjs/ObservabilityBuilder.d.ts +61 -0
- package/dist/cjs/ObservabilityBuilder.d.ts.map +1 -0
- package/dist/cjs/ObservabilityBuilder.js +141 -0
- package/dist/cjs/ObservabilityBuilder.js.map +1 -0
- package/dist/cjs/ObservabilityManager.d.ts +29 -0
- package/dist/cjs/ObservabilityManager.d.ts.map +1 -0
- package/dist/cjs/ObservabilityManager.js +61 -0
- package/dist/cjs/ObservabilityManager.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/tracing/constants.d.ts +83 -0
- package/dist/cjs/tracing/constants.d.ts.map +1 -0
- package/dist/cjs/tracing/constants.js +101 -0
- package/dist/cjs/tracing/constants.js.map +1 -0
- package/dist/cjs/tracing/contracts.d.ts +186 -0
- package/dist/cjs/tracing/contracts.d.ts.map +1 -0
- package/dist/cjs/tracing/contracts.js +44 -0
- package/dist/cjs/tracing/contracts.js.map +1 -0
- package/dist/cjs/tracing/exporter/Agent365Exporter.d.ts +53 -0
- package/dist/cjs/tracing/exporter/Agent365Exporter.d.ts.map +1 -0
- package/dist/cjs/tracing/exporter/Agent365Exporter.js +318 -0
- package/dist/cjs/tracing/exporter/Agent365Exporter.js.map +1 -0
- package/dist/cjs/tracing/exporter/utils.d.ts +38 -0
- package/dist/cjs/tracing/exporter/utils.d.ts.map +1 -0
- package/dist/cjs/tracing/exporter/utils.js +126 -0
- package/dist/cjs/tracing/exporter/utils.js.map +1 -0
- package/dist/cjs/tracing/middleware/BaggageBuilder.d.ts +182 -0
- package/dist/cjs/tracing/middleware/BaggageBuilder.d.ts.map +1 -0
- package/dist/cjs/tracing/middleware/BaggageBuilder.js +297 -0
- package/dist/cjs/tracing/middleware/BaggageBuilder.js.map +1 -0
- package/dist/cjs/tracing/processors/SpanProcessor.d.ts +30 -0
- package/dist/cjs/tracing/processors/SpanProcessor.d.ts.map +1 -0
- package/dist/cjs/tracing/processors/SpanProcessor.js +98 -0
- package/dist/cjs/tracing/processors/SpanProcessor.js.map +1 -0
- package/dist/cjs/tracing/processors/util.d.ts +9 -0
- package/dist/cjs/tracing/processors/util.d.ts.map +1 -0
- package/dist/cjs/tracing/processors/util.js +50 -0
- package/dist/cjs/tracing/processors/util.js.map +1 -0
- package/dist/cjs/tracing/scopes/ExecuteToolScope.d.ts +22 -0
- package/dist/cjs/tracing/scopes/ExecuteToolScope.d.ts.map +1 -0
- package/dist/cjs/tracing/scopes/ExecuteToolScope.js +51 -0
- package/dist/cjs/tracing/scopes/ExecuteToolScope.js.map +1 -0
- package/dist/cjs/tracing/scopes/InferenceScope.d.ts +47 -0
- package/dist/cjs/tracing/scopes/InferenceScope.d.ts.map +1 -0
- package/dist/cjs/tracing/scopes/InferenceScope.js +83 -0
- package/dist/cjs/tracing/scopes/InferenceScope.js.map +1 -0
- package/dist/cjs/tracing/scopes/InvokeAgentScope.d.ts +33 -0
- package/dist/cjs/tracing/scopes/InvokeAgentScope.d.ts.map +1 -0
- package/dist/cjs/tracing/scopes/InvokeAgentScope.js +94 -0
- package/dist/cjs/tracing/scopes/InvokeAgentScope.js.map +1 -0
- package/dist/cjs/tracing/scopes/OpenTelemetryScope.d.ts +57 -0
- package/dist/cjs/tracing/scopes/OpenTelemetryScope.d.ts.map +1 -0
- package/dist/cjs/tracing/scopes/OpenTelemetryScope.js +146 -0
- package/dist/cjs/tracing/scopes/OpenTelemetryScope.js.map +1 -0
- package/dist/cjs/tracing/util.d.ts +9 -0
- package/dist/cjs/tracing/util.d.ts.map +1 -0
- package/dist/cjs/tracing/util.js +28 -0
- package/dist/cjs/tracing/util.js.map +1 -0
- package/dist/cjs/utils/logging.d.ts +11 -0
- package/dist/cjs/utils/logging.d.ts.map +1 -0
- package/dist/cjs/utils/logging.js +84 -0
- package/dist/cjs/utils/logging.js.map +1 -0
- package/dist/esm/ObservabilityBuilder.d.ts +61 -0
- package/dist/esm/ObservabilityBuilder.d.ts.map +1 -0
- package/dist/esm/ObservabilityBuilder.js +137 -0
- package/dist/esm/ObservabilityBuilder.js.map +1 -0
- package/dist/esm/ObservabilityManager.d.ts +29 -0
- package/dist/esm/ObservabilityManager.d.ts.map +1 -0
- package/dist/esm/ObservabilityManager.js +57 -0
- package/dist/esm/ObservabilityManager.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/tracing/constants.d.ts +83 -0
- package/dist/esm/tracing/constants.d.ts.map +1 -0
- package/dist/esm/tracing/constants.js +97 -0
- package/dist/esm/tracing/constants.js.map +1 -0
- package/dist/esm/tracing/contracts.d.ts +186 -0
- package/dist/esm/tracing/contracts.d.ts.map +1 -0
- package/dist/esm/tracing/contracts.js +41 -0
- package/dist/esm/tracing/contracts.js.map +1 -0
- package/dist/esm/tracing/exporter/Agent365Exporter.d.ts +53 -0
- package/dist/esm/tracing/exporter/Agent365Exporter.d.ts.map +1 -0
- package/dist/esm/tracing/exporter/Agent365Exporter.js +281 -0
- package/dist/esm/tracing/exporter/Agent365Exporter.js.map +1 -0
- package/dist/esm/tracing/exporter/utils.d.ts +38 -0
- package/dist/esm/tracing/exporter/utils.d.ts.map +1 -0
- package/dist/esm/tracing/exporter/utils.js +113 -0
- package/dist/esm/tracing/exporter/utils.js.map +1 -0
- package/dist/esm/tracing/middleware/BaggageBuilder.d.ts +182 -0
- package/dist/esm/tracing/middleware/BaggageBuilder.d.ts.map +1 -0
- package/dist/esm/tracing/middleware/BaggageBuilder.js +292 -0
- package/dist/esm/tracing/middleware/BaggageBuilder.js.map +1 -0
- package/dist/esm/tracing/processors/SpanProcessor.d.ts +30 -0
- package/dist/esm/tracing/processors/SpanProcessor.d.ts.map +1 -0
- package/dist/esm/tracing/processors/SpanProcessor.js +94 -0
- package/dist/esm/tracing/processors/SpanProcessor.js.map +1 -0
- package/dist/esm/tracing/processors/util.d.ts +9 -0
- package/dist/esm/tracing/processors/util.d.ts.map +1 -0
- package/dist/esm/tracing/processors/util.js +47 -0
- package/dist/esm/tracing/processors/util.js.map +1 -0
- package/dist/esm/tracing/scopes/ExecuteToolScope.d.ts +22 -0
- package/dist/esm/tracing/scopes/ExecuteToolScope.d.ts.map +1 -0
- package/dist/esm/tracing/scopes/ExecuteToolScope.js +47 -0
- package/dist/esm/tracing/scopes/ExecuteToolScope.js.map +1 -0
- package/dist/esm/tracing/scopes/InferenceScope.d.ts +47 -0
- package/dist/esm/tracing/scopes/InferenceScope.d.ts.map +1 -0
- package/dist/esm/tracing/scopes/InferenceScope.js +79 -0
- package/dist/esm/tracing/scopes/InferenceScope.js.map +1 -0
- package/dist/esm/tracing/scopes/InvokeAgentScope.d.ts +33 -0
- package/dist/esm/tracing/scopes/InvokeAgentScope.d.ts.map +1 -0
- package/dist/esm/tracing/scopes/InvokeAgentScope.js +90 -0
- package/dist/esm/tracing/scopes/InvokeAgentScope.js.map +1 -0
- package/dist/esm/tracing/scopes/OpenTelemetryScope.d.ts +57 -0
- package/dist/esm/tracing/scopes/OpenTelemetryScope.d.ts.map +1 -0
- package/dist/esm/tracing/scopes/OpenTelemetryScope.js +139 -0
- package/dist/esm/tracing/scopes/OpenTelemetryScope.js.map +1 -0
- package/dist/esm/tracing/util.d.ts +9 -0
- package/dist/esm/tracing/util.d.ts.map +1 -0
- package/dist/esm/tracing/util.js +23 -0
- package/dist/esm/tracing/util.js.map +1 -0
- package/dist/esm/utils/logging.d.ts +11 -0
- package/dist/esm/utils/logging.d.ts.map +1 -0
- package/dist/esm/utils/logging.js +81 -0
- package/dist/esm/utils/logging.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/tracing/exporter/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAOzD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAOxD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAe/C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAWvD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EAAE,GACpB,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAuB7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAMnD;AAGD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAGnF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ------------------------------------------------------------------------------
|
|
3
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
// ------------------------------------------------------------------------------
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.hexTraceId = hexTraceId;
|
|
10
|
+
exports.hexSpanId = hexSpanId;
|
|
11
|
+
exports.asStr = asStr;
|
|
12
|
+
exports.kindName = kindName;
|
|
13
|
+
exports.statusName = statusName;
|
|
14
|
+
exports.partitionByIdentity = partitionByIdentity;
|
|
15
|
+
exports.isAgent365ExporterEnabled = isAgent365ExporterEnabled;
|
|
16
|
+
exports.parseIdentityKey = parseIdentityKey;
|
|
17
|
+
const api_1 = require("@opentelemetry/api");
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const logging_1 = __importDefault(require("../../utils/logging"));
|
|
20
|
+
/**
|
|
21
|
+
* Convert trace ID to hex string format
|
|
22
|
+
*/
|
|
23
|
+
function hexTraceId(value) {
|
|
24
|
+
if (typeof value === 'number') {
|
|
25
|
+
// Convert integer to 32 hex chars (128-bit)
|
|
26
|
+
return value.toString(16).padStart(32, '0');
|
|
27
|
+
}
|
|
28
|
+
// Handle hex string input - ensure it's 32 hex characters
|
|
29
|
+
return value.replace(/^0x/, '').padStart(32, '0');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert span ID to hex string format
|
|
33
|
+
*/
|
|
34
|
+
function hexSpanId(value) {
|
|
35
|
+
if (typeof value === 'number') {
|
|
36
|
+
// Convert integer to 16 hex chars (64-bit)
|
|
37
|
+
return value.toString(16).padStart(16, '0');
|
|
38
|
+
}
|
|
39
|
+
// Handle hex string input - ensure it's 16 hex characters
|
|
40
|
+
return value.replace(/^0x/, '').padStart(16, '0');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convert any value to string, handling null/undefined
|
|
44
|
+
*/
|
|
45
|
+
function asStr(v) {
|
|
46
|
+
if (v === null || v === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const s = String(v);
|
|
50
|
+
return s.trim() ? s : undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get span kind name from SpanKind enum
|
|
54
|
+
*/
|
|
55
|
+
function kindName(kind) {
|
|
56
|
+
switch (kind) {
|
|
57
|
+
case api_1.SpanKind.INTERNAL:
|
|
58
|
+
return 'INTERNAL';
|
|
59
|
+
case api_1.SpanKind.SERVER:
|
|
60
|
+
return 'SERVER';
|
|
61
|
+
case api_1.SpanKind.CLIENT:
|
|
62
|
+
return 'CLIENT';
|
|
63
|
+
case api_1.SpanKind.PRODUCER:
|
|
64
|
+
return 'PRODUCER';
|
|
65
|
+
case api_1.SpanKind.CONSUMER:
|
|
66
|
+
return 'CONSUMER';
|
|
67
|
+
default:
|
|
68
|
+
return 'UNSPECIFIED';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get status name from SpanStatusCode enum
|
|
73
|
+
*/
|
|
74
|
+
function statusName(code) {
|
|
75
|
+
switch (code) {
|
|
76
|
+
case api_1.SpanStatusCode.UNSET:
|
|
77
|
+
return 'UNSET';
|
|
78
|
+
case api_1.SpanStatusCode.OK:
|
|
79
|
+
return 'OK';
|
|
80
|
+
case api_1.SpanStatusCode.ERROR:
|
|
81
|
+
return 'ERROR';
|
|
82
|
+
default:
|
|
83
|
+
return 'UNSET';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Partition spans by (tenantId, agentId) identity pairs
|
|
88
|
+
*/
|
|
89
|
+
function partitionByIdentity(spans) {
|
|
90
|
+
const groups = new Map();
|
|
91
|
+
let skippedCount = 0;
|
|
92
|
+
for (const span of spans) {
|
|
93
|
+
const attrs = span.attributes || {};
|
|
94
|
+
const tenant = asStr(attrs[constants_1.OpenTelemetryConstants.TENANT_ID_KEY]);
|
|
95
|
+
const agent = asStr(attrs[constants_1.OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY]);
|
|
96
|
+
if (!tenant || !agent) {
|
|
97
|
+
skippedCount++;
|
|
98
|
+
logging_1.default.warn(`[Agent365Exporter] Skipping span without tenant or agent ID. Span name: ${span.name}`);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const key = `${tenant}:${agent}`;
|
|
102
|
+
const existing = groups.get(key) || [];
|
|
103
|
+
existing.push(span);
|
|
104
|
+
groups.set(key, existing);
|
|
105
|
+
}
|
|
106
|
+
logging_1.default.info(`[Agent365Exporter] Partitioned into ${groups.size} identity groups (${skippedCount} spans skipped)`);
|
|
107
|
+
return groups;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check if Agent 365 exporter is enabled via environment variable
|
|
111
|
+
*/
|
|
112
|
+
function isAgent365ExporterEnabled() {
|
|
113
|
+
const a365Env = process.env[constants_1.OpenTelemetryConstants.ENABLE_A365_OBSERVABILITY_EXPORTER]?.toLowerCase() || '';
|
|
114
|
+
const validValues = ['true', '1', 'yes', 'on'];
|
|
115
|
+
const enabled = validValues.includes(a365Env);
|
|
116
|
+
logging_1.default.info(`[Agent365Exporter] Agent 365 exporter enabled: ${enabled}`);
|
|
117
|
+
return enabled;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parse identity key back to tenant and agent IDs
|
|
121
|
+
*/
|
|
122
|
+
function parseIdentityKey(key) {
|
|
123
|
+
const [tenantId, agentId] = key.split(':');
|
|
124
|
+
return { tenantId, agentId };
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/tracing/exporter/utils.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,4DAA4D;AAC5D,iFAAiF;;;;;AAUjF,gCAOC;AAKD,8BAOC;AAKD,sBAMC;AAKD,4BAeC;AAKD,gCAWC;AAKD,kDAyBC;AAKD,8DAMC;AAMD,4CAGC;AA3HD,4CAA8D;AAC9D,4CAAsD;AACtD,kEAAyC;AAEzC;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAsB;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,4CAA4C;QAC5C,OA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,CAAC,IAAI,CAAC,uCAAuC,MAAM,CAAC,IAAI,qBAAqB,YAAY,iBAAiB,CAAC,CAAC;IAClH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB;IACvC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAsB,CAAC,kCAAkC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC5G,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAY,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvD,iBAAM,CAAC,IAAI,CAAC,kDAAkD,OAAO,EAAE,CAAC,CAAC;IACzE,OAAO,OAAO,CAAC;AACjB,CAAC;AAGD;;GAEG;AACH,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per request baggage builder for OpenTelemetry context propagation.
|
|
3
|
+
*
|
|
4
|
+
* This class provides a fluent API for setting baggage values that will be
|
|
5
|
+
* propagated in the OpenTelemetry context.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const scope = new BaggageBuilder()
|
|
10
|
+
* .tenantId("tenant-123")
|
|
11
|
+
* .agentId("agent-456")
|
|
12
|
+
* .correlationId("corr-789")
|
|
13
|
+
* .build();
|
|
14
|
+
*
|
|
15
|
+
* scope.enter();
|
|
16
|
+
* // Baggage is set in this context
|
|
17
|
+
* // ... do work ...
|
|
18
|
+
* scope.exit();
|
|
19
|
+
* // Baggage is restored after exiting the context
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class BaggageBuilder {
|
|
23
|
+
private pairs;
|
|
24
|
+
/**
|
|
25
|
+
* Set the operation source baggage value.
|
|
26
|
+
* @param value The operation source value
|
|
27
|
+
* @returns Self for method chaining
|
|
28
|
+
*/
|
|
29
|
+
operationSource(value: string | null | undefined): BaggageBuilder;
|
|
30
|
+
/**
|
|
31
|
+
* Set the tenant ID baggage value.
|
|
32
|
+
* @param value The tenant ID
|
|
33
|
+
* @returns Self for method chaining
|
|
34
|
+
*/
|
|
35
|
+
tenantId(value: string | null | undefined): BaggageBuilder;
|
|
36
|
+
/**
|
|
37
|
+
* Set the agent ID baggage value.
|
|
38
|
+
* @param value The agent ID
|
|
39
|
+
* @returns Self for method chaining
|
|
40
|
+
*/
|
|
41
|
+
agentId(value: string | null | undefined): BaggageBuilder;
|
|
42
|
+
/**
|
|
43
|
+
* Set the agent AUID baggage value.
|
|
44
|
+
* @param value The agent AUID
|
|
45
|
+
* @returns Self for method chaining
|
|
46
|
+
*/
|
|
47
|
+
agentAuid(value: string | null | undefined): BaggageBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Set the agent UPN baggage value.
|
|
50
|
+
* @param value The agent UPN
|
|
51
|
+
* @returns Self for method chaining
|
|
52
|
+
*/
|
|
53
|
+
agentUpn(value: string | null | undefined): BaggageBuilder;
|
|
54
|
+
/**
|
|
55
|
+
* Set the agent blueprint ID baggage value.
|
|
56
|
+
* @param value The agent blueprint ID
|
|
57
|
+
* @returns Self for method chaining
|
|
58
|
+
*/
|
|
59
|
+
agentBlueprintId(value: string | null | undefined): BaggageBuilder;
|
|
60
|
+
/**
|
|
61
|
+
* Set the correlation ID baggage value.
|
|
62
|
+
* @param value The correlation ID
|
|
63
|
+
* @returns Self for method chaining
|
|
64
|
+
*/
|
|
65
|
+
correlationId(value: string | null | undefined): BaggageBuilder;
|
|
66
|
+
/**
|
|
67
|
+
* Set the caller ID baggage value.
|
|
68
|
+
* @param value The caller ID
|
|
69
|
+
* @returns Self for method chaining
|
|
70
|
+
*/
|
|
71
|
+
callerId(value: string | null | undefined): BaggageBuilder;
|
|
72
|
+
/**
|
|
73
|
+
* Set the hiring manager ID baggage value.
|
|
74
|
+
* @param value The hiring manager ID
|
|
75
|
+
* @returns Self for method chaining
|
|
76
|
+
*/
|
|
77
|
+
hiringManagerId(value: string | null | undefined): BaggageBuilder;
|
|
78
|
+
/**
|
|
79
|
+
* Set the agent name baggage value.
|
|
80
|
+
* @param value The agent name
|
|
81
|
+
* @returns Self for method chaining
|
|
82
|
+
*/
|
|
83
|
+
agentName(value: string | null | undefined): BaggageBuilder;
|
|
84
|
+
/**
|
|
85
|
+
* Set the agent description baggage value.
|
|
86
|
+
* @param value The agent description
|
|
87
|
+
* @returns Self for method chaining
|
|
88
|
+
*/
|
|
89
|
+
agentDescription(value: string | null | undefined): BaggageBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Set the caller name baggage value.
|
|
92
|
+
* @param value The caller name
|
|
93
|
+
* @returns Self for method chaining
|
|
94
|
+
*/
|
|
95
|
+
callerName(value: string | null | undefined): BaggageBuilder;
|
|
96
|
+
/**
|
|
97
|
+
* Set the caller UPN baggage value.
|
|
98
|
+
* @param value The caller UPN
|
|
99
|
+
* @returns Self for method chaining
|
|
100
|
+
*/
|
|
101
|
+
callerUpn(value: string | null | undefined): BaggageBuilder;
|
|
102
|
+
/**
|
|
103
|
+
* Set the conversation ID baggage value.
|
|
104
|
+
* @param value The conversation ID
|
|
105
|
+
* @returns Self for method chaining
|
|
106
|
+
*/
|
|
107
|
+
conversationId(value: string | null | undefined): BaggageBuilder;
|
|
108
|
+
/**
|
|
109
|
+
* Set the conversation item link baggage value.
|
|
110
|
+
* @param value The conversation item link
|
|
111
|
+
* @returns Self for method chaining
|
|
112
|
+
*/
|
|
113
|
+
conversationItemLink(value: string | null | undefined): BaggageBuilder;
|
|
114
|
+
/**
|
|
115
|
+
* Set the execution source metadata ID (e.g., channel ID).
|
|
116
|
+
* @param value The source metadata ID
|
|
117
|
+
* @returns Self for method chaining
|
|
118
|
+
*/
|
|
119
|
+
sourceMetadataId(value: string | null | undefined): BaggageBuilder;
|
|
120
|
+
/**
|
|
121
|
+
* Set the execution source metadata name (e.g., channel name).
|
|
122
|
+
* @param value The source metadata name
|
|
123
|
+
* @returns Self for method chaining
|
|
124
|
+
*/
|
|
125
|
+
sourceMetadataName(value: string | null | undefined): BaggageBuilder;
|
|
126
|
+
/**
|
|
127
|
+
* Set the execution source metadata description (e.g., channel description).
|
|
128
|
+
* @param value The source metadata description
|
|
129
|
+
* @returns Self for method chaining
|
|
130
|
+
*/
|
|
131
|
+
sourceMetadataDescription(value: string | null | undefined): BaggageBuilder;
|
|
132
|
+
/**
|
|
133
|
+
* Set multiple baggage pairs from a dictionary or iterable.
|
|
134
|
+
* @param pairs Dictionary or iterable of key-value pairs
|
|
135
|
+
* @returns Self for method chaining
|
|
136
|
+
*/
|
|
137
|
+
setPairs(pairs: Record<string, any> | Iterable<[string, any]> | null | undefined): BaggageBuilder;
|
|
138
|
+
/**
|
|
139
|
+
* Apply the collected baggage to the current context.
|
|
140
|
+
* @returns A context manager that restores the previous baggage on exit
|
|
141
|
+
*/
|
|
142
|
+
build(): BaggageScope;
|
|
143
|
+
/**
|
|
144
|
+
* Add a baggage key/value if the value is not null or whitespace.
|
|
145
|
+
* @param key The baggage key
|
|
146
|
+
* @param value The baggage value
|
|
147
|
+
*/
|
|
148
|
+
private set;
|
|
149
|
+
/**
|
|
150
|
+
* Convenience method to begin a request baggage scope with common fields.
|
|
151
|
+
* @param tenantId The tenant ID
|
|
152
|
+
* @param agentId The agent ID
|
|
153
|
+
* @param correlationId The correlation ID
|
|
154
|
+
* @returns A context manager that restores the previous baggage on exit
|
|
155
|
+
*/
|
|
156
|
+
static setRequestContext(tenantId?: string | null, agentId?: string | null, correlationId?: string | null): BaggageScope;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Context manager for baggage scope.
|
|
160
|
+
*
|
|
161
|
+
* This class manages the lifecycle of baggage values, setting them on enter
|
|
162
|
+
* and restoring the previous context on exit.
|
|
163
|
+
*/
|
|
164
|
+
export declare class BaggageScope implements Disposable {
|
|
165
|
+
private readonly contextWithBaggage;
|
|
166
|
+
constructor(pairs: Map<string, string>);
|
|
167
|
+
/**
|
|
168
|
+
* Execute a synchronous function under this baggage scope.
|
|
169
|
+
* Automatically restores previous context afterward.
|
|
170
|
+
*/
|
|
171
|
+
run<T>(fn: () => T): T;
|
|
172
|
+
/**
|
|
173
|
+
* Dispose is a no-op because OpenTelemetry JS automatically restores
|
|
174
|
+
* the previous context after `context.with()` completes.
|
|
175
|
+
*/
|
|
176
|
+
[Symbol.dispose](): void;
|
|
177
|
+
/**
|
|
178
|
+
* Manual cleanup alternative if caller isn't using `using`.
|
|
179
|
+
*/
|
|
180
|
+
dispose(): void;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=BaggageBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaggageBuilder.d.ts","sourceRoot":"","sources":["../../../../src/tracing/middleware/BaggageBuilder.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAkC;IAE/C;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAKjE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAK1D;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAKzD;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAK3D;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,G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,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAqBjG;;;OAGG;IACH,KAAK,IAAI,YAAY;IAIrB;;;;OAIG;IACH,OAAO,CAAC,GAAG;IASX;;;;;;OAMG;IACH,MAAM,CAAC,iBAAiB,CACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,EACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EACvB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAC5B,YAAY;CAOhB;AAED;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,UAAU;IAC7C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;gBAEjC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAgBtC;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAItB;;;OAGG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;IAIxB;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ------------------------------------------------------------------------------
|
|
3
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
// ------------------------------------------------------------------------------
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BaggageScope = exports.BaggageBuilder = void 0;
|
|
7
|
+
const api_1 = require("@opentelemetry/api");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
/**
|
|
10
|
+
* Per request baggage builder for OpenTelemetry context propagation.
|
|
11
|
+
*
|
|
12
|
+
* This class provides a fluent API for setting baggage values that will be
|
|
13
|
+
* propagated in the OpenTelemetry context.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const scope = new BaggageBuilder()
|
|
18
|
+
* .tenantId("tenant-123")
|
|
19
|
+
* .agentId("agent-456")
|
|
20
|
+
* .correlationId("corr-789")
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* scope.enter();
|
|
24
|
+
* // Baggage is set in this context
|
|
25
|
+
* // ... do work ...
|
|
26
|
+
* scope.exit();
|
|
27
|
+
* // Baggage is restored after exiting the context
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
class BaggageBuilder {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.pairs = new Map();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set the operation source baggage value.
|
|
36
|
+
* @param value The operation source value
|
|
37
|
+
* @returns Self for method chaining
|
|
38
|
+
*/
|
|
39
|
+
operationSource(value) {
|
|
40
|
+
this.set(constants_1.OpenTelemetryConstants.OPERATION_SOURCE_KEY, value);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Set the tenant ID baggage value.
|
|
45
|
+
* @param value The tenant ID
|
|
46
|
+
* @returns Self for method chaining
|
|
47
|
+
*/
|
|
48
|
+
tenantId(value) {
|
|
49
|
+
this.set(constants_1.OpenTelemetryConstants.TENANT_ID_KEY, value);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set the agent ID baggage value.
|
|
54
|
+
* @param value The agent ID
|
|
55
|
+
* @returns Self for method chaining
|
|
56
|
+
*/
|
|
57
|
+
agentId(value) {
|
|
58
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY, value);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set the agent AUID baggage value.
|
|
63
|
+
* @param value The agent AUID
|
|
64
|
+
* @returns Self for method chaining
|
|
65
|
+
*/
|
|
66
|
+
agentAuid(value) {
|
|
67
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY, value);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set the agent UPN baggage value.
|
|
72
|
+
* @param value The agent UPN
|
|
73
|
+
* @returns Self for method chaining
|
|
74
|
+
*/
|
|
75
|
+
agentUpn(value) {
|
|
76
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_AGENT_UPN_KEY, value);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the agent blueprint ID baggage value.
|
|
81
|
+
* @param value The agent blueprint ID
|
|
82
|
+
* @returns Self for method chaining
|
|
83
|
+
*/
|
|
84
|
+
agentBlueprintId(value) {
|
|
85
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_AGENT_BLUEPRINT_ID_KEY, value);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set the correlation ID baggage value.
|
|
90
|
+
* @param value The correlation ID
|
|
91
|
+
* @returns Self for method chaining
|
|
92
|
+
*/
|
|
93
|
+
correlationId(value) {
|
|
94
|
+
this.set(constants_1.OpenTelemetryConstants.CORRELATION_ID_KEY, value);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Set the caller ID baggage value.
|
|
99
|
+
* @param value The caller ID
|
|
100
|
+
* @returns Self for method chaining
|
|
101
|
+
*/
|
|
102
|
+
callerId(value) {
|
|
103
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_CALLER_ID_KEY, value);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set the hiring manager ID baggage value.
|
|
108
|
+
* @param value The hiring manager ID
|
|
109
|
+
* @returns Self for method chaining
|
|
110
|
+
*/
|
|
111
|
+
hiringManagerId(value) {
|
|
112
|
+
this.set(constants_1.OpenTelemetryConstants.HIRING_MANAGER_ID_KEY, value);
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Set the agent name baggage value.
|
|
117
|
+
* @param value The agent name
|
|
118
|
+
* @returns Self for method chaining
|
|
119
|
+
*/
|
|
120
|
+
agentName(value) {
|
|
121
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, value);
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Set the agent description baggage value.
|
|
126
|
+
* @param value The agent description
|
|
127
|
+
* @returns Self for method chaining
|
|
128
|
+
*/
|
|
129
|
+
agentDescription(value) {
|
|
130
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, value);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Set the caller name baggage value.
|
|
135
|
+
* @param value The caller name
|
|
136
|
+
* @returns Self for method chaining
|
|
137
|
+
*/
|
|
138
|
+
callerName(value) {
|
|
139
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_CALLER_NAME_KEY, value);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Set the caller UPN baggage value.
|
|
144
|
+
* @param value The caller UPN
|
|
145
|
+
* @returns Self for method chaining
|
|
146
|
+
*/
|
|
147
|
+
callerUpn(value) {
|
|
148
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_CALLER_UPN_KEY, value);
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Set the conversation ID baggage value.
|
|
153
|
+
* @param value The conversation ID
|
|
154
|
+
* @returns Self for method chaining
|
|
155
|
+
*/
|
|
156
|
+
conversationId(value) {
|
|
157
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, value);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Set the conversation item link baggage value.
|
|
162
|
+
* @param value The conversation item link
|
|
163
|
+
* @returns Self for method chaining
|
|
164
|
+
*/
|
|
165
|
+
conversationItemLink(value) {
|
|
166
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ITEM_LINK_KEY, value);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Set the execution source metadata ID (e.g., channel ID).
|
|
171
|
+
* @param value The source metadata ID
|
|
172
|
+
* @returns Self for method chaining
|
|
173
|
+
*/
|
|
174
|
+
sourceMetadataId(value) {
|
|
175
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_EXECUTION_SOURCE_ID_KEY, value);
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Set the execution source metadata name (e.g., channel name).
|
|
180
|
+
* @param value The source metadata name
|
|
181
|
+
* @returns Self for method chaining
|
|
182
|
+
*/
|
|
183
|
+
sourceMetadataName(value) {
|
|
184
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_EXECUTION_SOURCE_NAME_KEY, value);
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Set the execution source metadata description (e.g., channel description).
|
|
189
|
+
* @param value The source metadata description
|
|
190
|
+
* @returns Self for method chaining
|
|
191
|
+
*/
|
|
192
|
+
sourceMetadataDescription(value) {
|
|
193
|
+
this.set(constants_1.OpenTelemetryConstants.GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY, value);
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Set multiple baggage pairs from a dictionary or iterable.
|
|
198
|
+
* @param pairs Dictionary or iterable of key-value pairs
|
|
199
|
+
* @returns Self for method chaining
|
|
200
|
+
*/
|
|
201
|
+
setPairs(pairs) {
|
|
202
|
+
if (!pairs) {
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
let entries;
|
|
206
|
+
if (Symbol.iterator in Object(pairs)) {
|
|
207
|
+
entries = pairs;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
entries = Object.entries(pairs);
|
|
211
|
+
}
|
|
212
|
+
for (const [key, value] of entries) {
|
|
213
|
+
if (value !== null && value !== undefined) {
|
|
214
|
+
this.set(key, String(value));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Apply the collected baggage to the current context.
|
|
221
|
+
* @returns A context manager that restores the previous baggage on exit
|
|
222
|
+
*/
|
|
223
|
+
build() {
|
|
224
|
+
return new BaggageScope(this.pairs);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Add a baggage key/value if the value is not null or whitespace.
|
|
228
|
+
* @param key The baggage key
|
|
229
|
+
* @param value The baggage value
|
|
230
|
+
*/
|
|
231
|
+
set(key, value) {
|
|
232
|
+
if (value !== null && value !== undefined) {
|
|
233
|
+
const trimmed = value.trim();
|
|
234
|
+
if (trimmed) {
|
|
235
|
+
this.pairs.set(key, trimmed);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Convenience method to begin a request baggage scope with common fields.
|
|
241
|
+
* @param tenantId The tenant ID
|
|
242
|
+
* @param agentId The agent ID
|
|
243
|
+
* @param correlationId The correlation ID
|
|
244
|
+
* @returns A context manager that restores the previous baggage on exit
|
|
245
|
+
*/
|
|
246
|
+
static setRequestContext(tenantId, agentId, correlationId) {
|
|
247
|
+
return new BaggageBuilder()
|
|
248
|
+
.tenantId(tenantId)
|
|
249
|
+
.agentId(agentId)
|
|
250
|
+
.correlationId(correlationId)
|
|
251
|
+
.build();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.BaggageBuilder = BaggageBuilder;
|
|
255
|
+
/**
|
|
256
|
+
* Context manager for baggage scope.
|
|
257
|
+
*
|
|
258
|
+
* This class manages the lifecycle of baggage values, setting them on enter
|
|
259
|
+
* and restoring the previous context on exit.
|
|
260
|
+
*/
|
|
261
|
+
class BaggageScope {
|
|
262
|
+
constructor(pairs) {
|
|
263
|
+
// 1. Start from current active context
|
|
264
|
+
const currentCtx = api_1.context.active();
|
|
265
|
+
// 2. Build merged baggage
|
|
266
|
+
let bag = api_1.propagation.getBaggage(currentCtx) ?? api_1.propagation.createBaggage({});
|
|
267
|
+
for (const [key, value] of pairs.entries()) {
|
|
268
|
+
if (value && value.trim()) {
|
|
269
|
+
bag = bag.setEntry(key, { value });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// 3. Create a new context that carries that baggage
|
|
273
|
+
this.contextWithBaggage = api_1.propagation.setBaggage(currentCtx, bag);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Execute a synchronous function under this baggage scope.
|
|
277
|
+
* Automatically restores previous context afterward.
|
|
278
|
+
*/
|
|
279
|
+
run(fn) {
|
|
280
|
+
return api_1.context.with(this.contextWithBaggage, fn);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Dispose is a no-op because OpenTelemetry JS automatically restores
|
|
284
|
+
* the previous context after `context.with()` completes.
|
|
285
|
+
*/
|
|
286
|
+
[Symbol.dispose]() {
|
|
287
|
+
// Nothing to detach manually; context restoration happens automatically.
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Manual cleanup alternative if caller isn't using `using`.
|
|
291
|
+
*/
|
|
292
|
+
dispose() {
|
|
293
|
+
this[Symbol.dispose]();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.BaggageScope = BaggageScope;
|
|
297
|
+
//# sourceMappingURL=BaggageBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaggageBuilder.js","sourceRoot":"","sources":["../../../../src/tracing/middleware/BaggageBuilder.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,4DAA4D;AAC5D,iFAAiF;;;AAEjF,4CAAkF;AAClF,4CAAsD;AAEtD;;;;;;;;;;;;;;;;;;;;GA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AC3E,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;CACF;AAzCD,oCAyCC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Span } from '@opentelemetry/api';
|
|
2
|
+
import { SpanProcessor as BaseSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
|
+
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
4
|
+
/**
|
|
5
|
+
* Span processor that propagates baggage key/value pairs to span attributes.
|
|
6
|
+
*
|
|
7
|
+
* This processor copies baggage entries onto spans based on the operation type.
|
|
8
|
+
* For invoke_agent operations, it applies both generic and invoke-agent-specific attributes.
|
|
9
|
+
* For other operations, it applies only generic attributes.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SpanProcessor implements BaseSpanProcessor {
|
|
12
|
+
/**
|
|
13
|
+
* Called when a span is started.
|
|
14
|
+
* Copies relevant baggage entries to span attributes.
|
|
15
|
+
*/
|
|
16
|
+
onStart(span: Span, parentContext?: Context): void;
|
|
17
|
+
/**
|
|
18
|
+
* Called when a span is ended.
|
|
19
|
+
*/
|
|
20
|
+
onEnd(_span: ReadableSpan): void;
|
|
21
|
+
/**
|
|
22
|
+
* Shutdown the processor.
|
|
23
|
+
*/
|
|
24
|
+
shutdown(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Force flush the processor.
|
|
27
|
+
*/
|
|
28
|
+
forceFlush(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=SpanProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpanProcessor.d.ts","sourceRoot":"","sources":["../../../../src/tracing/processors/SpanProcessor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAe,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAI7D;;;;;;GAMG;AACH,qBAAa,aAAc,YAAW,iBAAiB;IACrD;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI;IAkElD;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAIhC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|