@microsoft/opentelemetry 0.1.0-alpha.2 → 0.1.0-alpha.3
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/dist/commonjs/a365/configuration/A365Configuration.d.ts +42 -0
- package/dist/commonjs/a365/configuration/A365Configuration.d.ts.map +1 -0
- package/dist/commonjs/a365/configuration/A365Configuration.js +162 -0
- package/dist/commonjs/a365/configuration/A365Configuration.js.map +1 -0
- package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts +53 -0
- package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -0
- package/dist/commonjs/a365/configuration/A365ConfigurationOptions.js +5 -0
- package/dist/commonjs/a365/configuration/A365ConfigurationOptions.js.map +1 -0
- package/dist/commonjs/a365/configuration/index.d.ts +3 -0
- package/dist/commonjs/a365/configuration/index.d.ts.map +1 -0
- package/dist/commonjs/a365/configuration/index.js +9 -0
- package/dist/commonjs/a365/configuration/index.js.map +1 -0
- package/dist/commonjs/a365/constants.d.ts +76 -0
- package/dist/commonjs/a365/constants.d.ts.map +1 -0
- package/dist/commonjs/a365/constants.js +99 -0
- package/dist/commonjs/a365/constants.js.map +1 -0
- package/dist/commonjs/a365/context/tokenContext.d.ts +25 -0
- package/dist/commonjs/a365/context/tokenContext.d.ts.map +1 -0
- package/dist/commonjs/a365/context/tokenContext.js +67 -0
- package/dist/commonjs/a365/context/tokenContext.js.map +1 -0
- package/dist/commonjs/a365/context.d.ts +31 -0
- package/dist/commonjs/a365/context.d.ts.map +1 -0
- package/dist/commonjs/a365/context.js +109 -0
- package/dist/commonjs/a365/context.js.map +1 -0
- package/dist/commonjs/a365/contracts.d.ts +250 -0
- package/dist/commonjs/a365/contracts.d.ts.map +1 -0
- package/dist/commonjs/a365/contracts.js +52 -0
- package/dist/commonjs/a365/contracts.js.map +1 -0
- package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts +25 -0
- package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts.map +1 -0
- package/dist/commonjs/a365/exporter/Agent365Exporter.js +220 -0
- package/dist/commonjs/a365/exporter/Agent365Exporter.js.map +1 -0
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts +43 -0
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -0
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js +30 -0
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js.map +1 -0
- package/dist/commonjs/a365/exporter/ExporterEventNames.d.ts +9 -0
- package/dist/commonjs/a365/exporter/ExporterEventNames.d.ts.map +1 -0
- package/dist/commonjs/a365/exporter/ExporterEventNames.js +15 -0
- package/dist/commonjs/a365/exporter/ExporterEventNames.js.map +1 -0
- package/dist/commonjs/a365/exporter/index.d.ts +6 -0
- package/dist/commonjs/a365/exporter/index.d.ts.map +1 -0
- package/dist/commonjs/a365/exporter/index.js +15 -0
- package/dist/commonjs/a365/exporter/index.js.map +1 -0
- package/dist/commonjs/a365/exporter/utils.d.ts +41 -0
- package/dist/commonjs/a365/exporter/utils.d.ts.map +1 -0
- package/dist/commonjs/a365/exporter/utils.js +410 -0
- package/dist/commonjs/a365/exporter/utils.js.map +1 -0
- package/dist/commonjs/a365/index.d.ts +16 -0
- package/dist/commonjs/a365/index.d.ts.map +1 -0
- package/dist/commonjs/a365/index.js +54 -0
- package/dist/commonjs/a365/index.js.map +1 -0
- package/dist/commonjs/a365/message-utils.d.ts +42 -0
- package/dist/commonjs/a365/message-utils.d.ts.map +1 -0
- package/dist/commonjs/a365/message-utils.js +116 -0
- package/dist/commonjs/a365/message-utils.js.map +1 -0
- package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts +112 -0
- package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts.map +1 -0
- package/dist/commonjs/a365/middleware/BaggageBuilder.js +249 -0
- package/dist/commonjs/a365/middleware/BaggageBuilder.js.map +1 -0
- package/dist/commonjs/a365/middleware/index.d.ts +2 -0
- package/dist/commonjs/a365/middleware/index.d.ts.map +1 -0
- package/dist/commonjs/a365/middleware/index.js +9 -0
- package/dist/commonjs/a365/middleware/index.js.map +1 -0
- package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts +32 -0
- package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts.map +1 -0
- package/dist/commonjs/a365/processors/A365SpanProcessor.js +104 -0
- package/dist/commonjs/a365/processors/A365SpanProcessor.js.map +1 -0
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts +44 -0
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts.map +1 -0
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js +260 -0
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js.map +1 -0
- package/dist/commonjs/a365/processors/index.d.ts +5 -0
- package/dist/commonjs/a365/processors/index.d.ts.map +1 -0
- package/dist/commonjs/a365/processors/index.js +13 -0
- package/dist/commonjs/a365/processors/index.js.map +1 -0
- package/dist/commonjs/a365/processors/util.d.ts +10 -0
- package/dist/commonjs/a365/processors/util.d.ts.map +1 -0
- package/dist/commonjs/a365/processors/util.js +56 -0
- package/dist/commonjs/a365/processors/util.js.map +1 -0
- package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts +24 -0
- package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts.map +1 -0
- package/dist/commonjs/a365/scopes/ExecuteToolScope.js +60 -0
- package/dist/commonjs/a365/scopes/ExecuteToolScope.js.map +1 -0
- package/dist/commonjs/a365/scopes/InferenceScope.d.ts +29 -0
- package/dist/commonjs/a365/scopes/InferenceScope.d.ts.map +1 -0
- package/dist/commonjs/a365/scopes/InferenceScope.js +75 -0
- package/dist/commonjs/a365/scopes/InferenceScope.js.map +1 -0
- package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts +25 -0
- package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts.map +1 -0
- package/dist/commonjs/a365/scopes/InvokeAgentScope.js +84 -0
- package/dist/commonjs/a365/scopes/InvokeAgentScope.js.map +1 -0
- package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts +59 -0
- package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts.map +1 -0
- package/dist/commonjs/a365/scopes/OpenTelemetryScope.js +199 -0
- package/dist/commonjs/a365/scopes/OpenTelemetryScope.js.map +1 -0
- package/dist/commonjs/a365/scopes/OutputScope.d.ts +26 -0
- package/dist/commonjs/a365/scopes/OutputScope.d.ts.map +1 -0
- package/dist/commonjs/a365/scopes/OutputScope.js +73 -0
- package/dist/commonjs/a365/scopes/OutputScope.js.map +1 -0
- package/dist/commonjs/a365/scopes/index.d.ts +6 -0
- package/dist/commonjs/a365/scopes/index.d.ts.map +1 -0
- package/dist/commonjs/a365/scopes/index.js +16 -0
- package/dist/commonjs/a365/scopes/index.js.map +1 -0
- package/dist/commonjs/a365/utils/utils.d.ts +6 -0
- package/dist/commonjs/a365/utils/utils.d.ts.map +1 -0
- package/dist/commonjs/a365/utils/utils.js +14 -0
- package/dist/commonjs/a365/utils/utils.js.map +1 -0
- package/dist/commonjs/azureMonitor/metrics/quickpulse/types.d.ts +1 -1
- package/dist/commonjs/azureMonitor/traces/handler.d.ts.map +1 -1
- package/dist/commonjs/azureMonitor/traces/handler.js +8 -2
- package/dist/commonjs/azureMonitor/traces/handler.js.map +1 -1
- package/dist/commonjs/distro/distro.d.ts +1 -1
- package/dist/commonjs/distro/distro.d.ts.map +1 -1
- package/dist/commonjs/distro/distro.js +44 -92
- package/dist/commonjs/distro/distro.js.map +1 -1
- package/dist/commonjs/distro/types.d.ts +2 -1
- package/dist/commonjs/distro/types.d.ts.map +1 -1
- package/dist/commonjs/index.d.ts +5 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +33 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/package.json +1 -0
- package/dist/commonjs/shared/jsonConfig.d.ts +2 -1
- package/dist/commonjs/shared/jsonConfig.d.ts.map +1 -1
- package/dist/commonjs/shared/module.js +15 -11
- package/dist/commonjs/shared/module.js.map +1 -1
- package/dist/commonjs/types.d.ts +4 -30
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +1 -1
- package/dist/commonjs/types.js.map +1 -1
- package/dist/esm/a365/configuration/A365Configuration.d.ts +42 -0
- package/dist/esm/a365/configuration/A365Configuration.d.ts.map +1 -0
- package/dist/esm/a365/configuration/A365Configuration.js +158 -0
- package/dist/esm/a365/configuration/A365Configuration.js.map +1 -0
- package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts +53 -0
- package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -0
- package/dist/esm/a365/configuration/A365ConfigurationOptions.js +4 -0
- package/dist/esm/a365/configuration/A365ConfigurationOptions.js.map +1 -0
- package/dist/esm/a365/configuration/index.d.ts +3 -0
- package/dist/esm/a365/configuration/index.d.ts.map +1 -0
- package/dist/esm/a365/configuration/index.js +4 -0
- package/dist/esm/a365/configuration/index.js.map +1 -0
- package/dist/esm/a365/constants.d.ts +76 -0
- package/dist/esm/a365/constants.d.ts.map +1 -0
- package/dist/esm/a365/constants.js +95 -0
- package/dist/esm/a365/constants.js.map +1 -0
- package/dist/esm/a365/context/tokenContext.d.ts +25 -0
- package/dist/esm/a365/context/tokenContext.d.ts.map +1 -0
- package/dist/esm/a365/context/tokenContext.js +62 -0
- package/dist/esm/a365/context/tokenContext.js.map +1 -0
- package/dist/esm/a365/context.d.ts +31 -0
- package/dist/esm/a365/context.d.ts.map +1 -0
- package/dist/esm/a365/context.js +101 -0
- package/dist/esm/a365/context.js.map +1 -0
- package/dist/esm/a365/contracts.d.ts +250 -0
- package/dist/esm/a365/contracts.d.ts.map +1 -0
- package/dist/esm/a365/contracts.js +49 -0
- package/dist/esm/a365/contracts.js.map +1 -0
- package/dist/esm/a365/exporter/Agent365Exporter.d.ts +25 -0
- package/dist/esm/a365/exporter/Agent365Exporter.d.ts.map +1 -0
- package/dist/esm/a365/exporter/Agent365Exporter.js +216 -0
- package/dist/esm/a365/exporter/Agent365Exporter.js.map +1 -0
- package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts +43 -0
- package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -0
- package/dist/esm/a365/exporter/Agent365ExporterOptions.js +26 -0
- package/dist/esm/a365/exporter/Agent365ExporterOptions.js.map +1 -0
- package/dist/esm/a365/exporter/ExporterEventNames.d.ts +9 -0
- package/dist/esm/a365/exporter/ExporterEventNames.d.ts.map +1 -0
- package/dist/esm/a365/exporter/ExporterEventNames.js +12 -0
- package/dist/esm/a365/exporter/ExporterEventNames.js.map +1 -0
- package/dist/esm/a365/exporter/index.d.ts +6 -0
- package/dist/esm/a365/exporter/index.d.ts.map +1 -0
- package/dist/esm/a365/exporter/index.js +7 -0
- package/dist/esm/a365/exporter/index.js.map +1 -0
- package/dist/esm/a365/exporter/utils.d.ts +41 -0
- package/dist/esm/a365/exporter/utils.d.ts.map +1 -0
- package/dist/esm/a365/exporter/utils.js +398 -0
- package/dist/esm/a365/exporter/utils.js.map +1 -0
- package/dist/esm/a365/index.d.ts +16 -0
- package/dist/esm/a365/index.d.ts.map +1 -0
- package/dist/esm/a365/index.js +20 -0
- package/dist/esm/a365/index.js.map +1 -0
- package/dist/esm/a365/message-utils.d.ts +42 -0
- package/dist/esm/a365/message-utils.d.ts.map +1 -0
- package/dist/esm/a365/message-utils.js +107 -0
- package/dist/esm/a365/message-utils.js.map +1 -0
- package/dist/esm/a365/middleware/BaggageBuilder.d.ts +112 -0
- package/dist/esm/a365/middleware/BaggageBuilder.d.ts.map +1 -0
- package/dist/esm/a365/middleware/BaggageBuilder.js +244 -0
- package/dist/esm/a365/middleware/BaggageBuilder.js.map +1 -0
- package/dist/esm/a365/middleware/index.d.ts +2 -0
- package/dist/esm/a365/middleware/index.d.ts.map +1 -0
- package/dist/esm/a365/middleware/index.js +4 -0
- package/dist/esm/a365/middleware/index.js.map +1 -0
- package/dist/esm/a365/processors/A365SpanProcessor.d.ts +32 -0
- package/dist/esm/a365/processors/A365SpanProcessor.d.ts.map +1 -0
- package/dist/esm/a365/processors/A365SpanProcessor.js +100 -0
- package/dist/esm/a365/processors/A365SpanProcessor.js.map +1 -0
- package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts +44 -0
- package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts.map +1 -0
- package/dist/esm/a365/processors/PerRequestSpanProcessor.js +256 -0
- package/dist/esm/a365/processors/PerRequestSpanProcessor.js.map +1 -0
- package/dist/esm/a365/processors/index.d.ts +5 -0
- package/dist/esm/a365/processors/index.d.ts.map +1 -0
- package/dist/esm/a365/processors/index.js +6 -0
- package/dist/esm/a365/processors/index.js.map +1 -0
- package/dist/esm/a365/processors/util.d.ts +10 -0
- package/dist/esm/a365/processors/util.d.ts.map +1 -0
- package/dist/esm/a365/processors/util.js +53 -0
- package/dist/esm/a365/processors/util.js.map +1 -0
- package/dist/esm/a365/scopes/ExecuteToolScope.d.ts +24 -0
- package/dist/esm/a365/scopes/ExecuteToolScope.d.ts.map +1 -0
- package/dist/esm/a365/scopes/ExecuteToolScope.js +56 -0
- package/dist/esm/a365/scopes/ExecuteToolScope.js.map +1 -0
- package/dist/esm/a365/scopes/InferenceScope.d.ts +29 -0
- package/dist/esm/a365/scopes/InferenceScope.d.ts.map +1 -0
- package/dist/esm/a365/scopes/InferenceScope.js +71 -0
- package/dist/esm/a365/scopes/InferenceScope.js.map +1 -0
- package/dist/esm/a365/scopes/InvokeAgentScope.d.ts +25 -0
- package/dist/esm/a365/scopes/InvokeAgentScope.d.ts.map +1 -0
- package/dist/esm/a365/scopes/InvokeAgentScope.js +80 -0
- package/dist/esm/a365/scopes/InvokeAgentScope.js.map +1 -0
- package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts +59 -0
- package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts.map +1 -0
- package/dist/esm/a365/scopes/OpenTelemetryScope.js +195 -0
- package/dist/esm/a365/scopes/OpenTelemetryScope.js.map +1 -0
- package/dist/esm/a365/scopes/OutputScope.d.ts +26 -0
- package/dist/esm/a365/scopes/OutputScope.d.ts.map +1 -0
- package/dist/esm/a365/scopes/OutputScope.js +69 -0
- package/dist/esm/a365/scopes/OutputScope.js.map +1 -0
- package/dist/esm/a365/scopes/index.d.ts +6 -0
- package/dist/esm/a365/scopes/index.d.ts.map +1 -0
- package/dist/esm/a365/scopes/index.js +8 -0
- package/dist/esm/a365/scopes/index.js.map +1 -0
- package/dist/esm/a365/utils/utils.d.ts +6 -0
- package/dist/esm/a365/utils/utils.d.ts.map +1 -0
- package/dist/esm/a365/utils/utils.js +11 -0
- package/dist/esm/a365/utils/utils.js.map +1 -0
- package/dist/esm/azureMonitor/metrics/quickpulse/types.d.ts +1 -1
- package/dist/esm/azureMonitor/traces/handler.d.ts.map +1 -1
- package/dist/esm/azureMonitor/traces/handler.js +5 -1
- package/dist/esm/azureMonitor/traces/handler.js.map +1 -1
- package/dist/esm/distro/distro.d.ts +1 -1
- package/dist/esm/distro/distro.d.ts.map +1 -1
- package/dist/esm/distro/distro.js +44 -92
- package/dist/esm/distro/distro.js.map +1 -1
- package/dist/esm/distro/types.d.ts +2 -1
- package/dist/esm/distro/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/shared/jsonConfig.d.ts +2 -1
- package/dist/esm/shared/jsonConfig.d.ts.map +1 -1
- package/dist/esm/types.d.ts +4 -30
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.isWrappedMessages = isWrappedMessages;
|
|
6
|
+
exports.toInputMessages = toInputMessages;
|
|
7
|
+
exports.toOutputMessages = toOutputMessages;
|
|
8
|
+
exports.normalizeInputMessages = normalizeInputMessages;
|
|
9
|
+
exports.normalizeOutputMessages = normalizeOutputMessages;
|
|
10
|
+
exports.serializeMessages = serializeMessages;
|
|
11
|
+
exports.safeSerializeToJson = safeSerializeToJson;
|
|
12
|
+
const contracts_js_1 = require("./contracts.js");
|
|
13
|
+
/**
|
|
14
|
+
* Type guard that returns `true` when the input is a versioned wrapper
|
|
15
|
+
* object (`InputMessages` or `OutputMessages`).
|
|
16
|
+
*/
|
|
17
|
+
function isWrappedMessages(input) {
|
|
18
|
+
return (!Array.isArray(input) &&
|
|
19
|
+
typeof input === "object" &&
|
|
20
|
+
input !== null &&
|
|
21
|
+
"version" in input &&
|
|
22
|
+
"messages" in input);
|
|
23
|
+
}
|
|
24
|
+
/** Converts plain input strings into OTEL input messages. */
|
|
25
|
+
function toInputMessages(messages) {
|
|
26
|
+
return messages.map((content) => ({
|
|
27
|
+
role: contracts_js_1.MessageRole.USER,
|
|
28
|
+
parts: [{ type: "text", content }],
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
/** Converts plain output strings into OTEL output messages. */
|
|
32
|
+
function toOutputMessages(messages) {
|
|
33
|
+
return messages.map((content) => ({
|
|
34
|
+
role: contracts_js_1.MessageRole.ASSISTANT,
|
|
35
|
+
parts: [{ type: "text", content }],
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalizes an `InputMessagesParam` to a versioned `InputMessages` wrapper.
|
|
40
|
+
* - `string` / `string[]` → converted to `ChatMessage[]` and wrapped
|
|
41
|
+
* - `InputMessages` → returned as-is
|
|
42
|
+
*/
|
|
43
|
+
function normalizeInputMessages(param) {
|
|
44
|
+
if (typeof param === "string" || Array.isArray(param)) {
|
|
45
|
+
const arr = typeof param === "string" ? [param] : param;
|
|
46
|
+
return { version: contracts_js_1.A365_MESSAGE_SCHEMA_VERSION, messages: toInputMessages(arr) };
|
|
47
|
+
}
|
|
48
|
+
return param;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Normalizes an `OutputMessagesParam` to a versioned `OutputMessages` wrapper.
|
|
52
|
+
* - `string` / `string[]` → converted to `OutputMessage[]` and wrapped
|
|
53
|
+
* - `OutputMessages` → returned as-is
|
|
54
|
+
*/
|
|
55
|
+
function normalizeOutputMessages(param) {
|
|
56
|
+
if (typeof param === "string" || Array.isArray(param)) {
|
|
57
|
+
const arr = typeof param === "string" ? [param] : param;
|
|
58
|
+
return { version: contracts_js_1.A365_MESSAGE_SCHEMA_VERSION, messages: toOutputMessages(arr) };
|
|
59
|
+
}
|
|
60
|
+
return param;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Serializes a versioned message wrapper to JSON.
|
|
64
|
+
*
|
|
65
|
+
* The try/catch ensures telemetry recording is non-throwing even when
|
|
66
|
+
* message parts contain non-JSON-serializable values.
|
|
67
|
+
*/
|
|
68
|
+
function serializeMessages(wrapper) {
|
|
69
|
+
try {
|
|
70
|
+
return JSON.stringify(wrapper);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return JSON.stringify({
|
|
74
|
+
version: contracts_js_1.A365_MESSAGE_SCHEMA_VERSION,
|
|
75
|
+
messages: [
|
|
76
|
+
{
|
|
77
|
+
role: contracts_js_1.MessageRole.SYSTEM,
|
|
78
|
+
parts: [
|
|
79
|
+
{
|
|
80
|
+
type: "text",
|
|
81
|
+
content: `[serialization failed: ${wrapper.messages.length} ${wrapper.messages.length === 1 ? "message" : "messages"}]`,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Ensures the value is always a JSON-parseable string.
|
|
91
|
+
* - Objects are serialized via JSON.stringify.
|
|
92
|
+
* - Strings that are already valid JSON objects/arrays are passed through.
|
|
93
|
+
* - All other strings are wrapped: `{ [key]: value }`.
|
|
94
|
+
*/
|
|
95
|
+
function safeSerializeToJson(value, key) {
|
|
96
|
+
if (typeof value === "object" && value !== null) {
|
|
97
|
+
try {
|
|
98
|
+
return JSON.stringify(value);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return JSON.stringify({ error: "serialization failed" });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const str = value;
|
|
105
|
+
try {
|
|
106
|
+
const parsed = JSON.parse(str);
|
|
107
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
108
|
+
return str;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// not valid JSON — fall through to wrap
|
|
113
|
+
}
|
|
114
|
+
return JSON.stringify({ [key]: str });
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=message-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-utils.js","sourceRoot":"","sources":["../../../src/a365/message-utils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAsBlC,8CAUC;AAGD,0CAKC;AAGD,4CAKC;AAOD,wDAMC;AAOD,0DAMC;AAQD,8CAmBC;AAQD,kDAkBC;AA/GD,iDAA0E;AAE1E;;;GAGG;AACH,SAAgB,iBAAiB,CAC/B,KAA+C;IAE/C,OAAO,CACL,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,UAAU,IAAI,KAAK,CACpB,CAAC;AACJ,CAAC;AAED,6DAA6D;AAC7D,SAAgB,eAAe,CAAC,QAAkB;IAChD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAChC,IAAI,EAAE,0BAAW,CAA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-0,0 +1,112 @@
|
|
|
1
|
+
import type { Context } from "@opentelemetry/api";
|
|
2
|
+
/**
|
|
3
|
+
* Fluent builder for setting OpenTelemetry baggage values.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const scope = new BaggageBuilder()
|
|
8
|
+
* .tenantId("tenant-123")
|
|
9
|
+
* .agentId("agent-456")
|
|
10
|
+
* .build();
|
|
11
|
+
*
|
|
12
|
+
* scope.run(() => {
|
|
13
|
+
* // Baggage is active in this context
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class BaggageBuilder {
|
|
18
|
+
private pairs;
|
|
19
|
+
/** Set the operation source baggage value (e.g., ATG, ACF). */
|
|
20
|
+
operationSource(value: string | null | undefined): BaggageBuilder;
|
|
21
|
+
/** Set the tenant ID baggage value. */
|
|
22
|
+
tenantId(value: string | null | undefined): BaggageBuilder;
|
|
23
|
+
/** Set the agent ID baggage value. */
|
|
24
|
+
agentId(value: string | null | undefined): BaggageBuilder;
|
|
25
|
+
/** Set the agent AUID baggage value. */
|
|
26
|
+
agentAuid(value: string | null | undefined): BaggageBuilder;
|
|
27
|
+
/** Set the agent email baggage value. */
|
|
28
|
+
agentEmail(value: string | null | undefined): BaggageBuilder;
|
|
29
|
+
/** Set the agent blueprint ID baggage value. */
|
|
30
|
+
agentBlueprintId(value: string | null | undefined): BaggageBuilder;
|
|
31
|
+
/** Set the session ID baggage value. */
|
|
32
|
+
sessionId(value: string): BaggageBuilder;
|
|
33
|
+
/** Set the user ID baggage value. */
|
|
34
|
+
userId(value: string | null | undefined): BaggageBuilder;
|
|
35
|
+
/** Set the agent name baggage value. */
|
|
36
|
+
agentName(value: string | null | undefined): BaggageBuilder;
|
|
37
|
+
/** Set the agent description baggage value. */
|
|
38
|
+
agentDescription(value: string | null | undefined): BaggageBuilder;
|
|
39
|
+
/** Set the agent platform ID baggage value. */
|
|
40
|
+
agentPlatformId(value: string | null | undefined): BaggageBuilder;
|
|
41
|
+
/** Set the agent version baggage value. */
|
|
42
|
+
agentVersion(value: string | null | undefined): BaggageBuilder;
|
|
43
|
+
/** Set the session description baggage value. */
|
|
44
|
+
sessionDescription(value: string | null | undefined): BaggageBuilder;
|
|
45
|
+
/** Set the user name baggage value. */
|
|
46
|
+
userName(value: string | null | undefined): BaggageBuilder;
|
|
47
|
+
/** Set the user email baggage value. */
|
|
48
|
+
userEmail(value: string | null | undefined): BaggageBuilder;
|
|
49
|
+
/** Set the caller client IP baggage value. */
|
|
50
|
+
callerClientIp(value: string | null | undefined): BaggageBuilder;
|
|
51
|
+
/** Set the caller agent platform ID baggage value. */
|
|
52
|
+
callerAgentPlatformId(value: string | null | undefined): BaggageBuilder;
|
|
53
|
+
/** Set the conversation ID baggage value. */
|
|
54
|
+
conversationId(value: string | null | undefined): BaggageBuilder;
|
|
55
|
+
/** Set the conversation item link baggage value. */
|
|
56
|
+
conversationItemLink(value: string | null | undefined): BaggageBuilder;
|
|
57
|
+
/** Set the channel name (e.g., Teams, Slack). */
|
|
58
|
+
channelName(value: string | null | undefined): BaggageBuilder;
|
|
59
|
+
/** Set the channel link/URL. */
|
|
60
|
+
channelLink(value: string | null | undefined): BaggageBuilder;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the invoke agent server address and port baggage values.
|
|
63
|
+
* @param address The server address (hostname) of the target agent service.
|
|
64
|
+
* @param port Optional server port. Only recorded when different from 443.
|
|
65
|
+
*/
|
|
66
|
+
invokeAgentServer(address: string | null | undefined, port?: number): BaggageBuilder;
|
|
67
|
+
/**
|
|
68
|
+
* Set multiple baggage pairs from a dictionary or iterable.
|
|
69
|
+
* @param pairs Dictionary or iterable of key-value pairs
|
|
70
|
+
*/
|
|
71
|
+
setPairs(pairs: Record<string, any> | Iterable<[string, any]> | null | undefined): BaggageBuilder;
|
|
72
|
+
/**
|
|
73
|
+
* Apply the collected baggage to the current context.
|
|
74
|
+
* @returns A BaggageScope that can run callbacks under the baggage context
|
|
75
|
+
*/
|
|
76
|
+
build(): BaggageScope;
|
|
77
|
+
/**
|
|
78
|
+
* Add a baggage key/value if the value is not null or whitespace.
|
|
79
|
+
*/
|
|
80
|
+
private set;
|
|
81
|
+
/**
|
|
82
|
+
* Convenience method to begin a request baggage scope with common fields.
|
|
83
|
+
* @param tenantId The tenant ID
|
|
84
|
+
* @param agentId The agent ID
|
|
85
|
+
* @returns A BaggageScope with tenant and agent ID set
|
|
86
|
+
*/
|
|
87
|
+
static setRequestContext(tenantId?: string | null, agentId?: string | null): BaggageScope;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Context manager for baggage scope.
|
|
91
|
+
*
|
|
92
|
+
* Manages the lifecycle of baggage values, setting them in the OTel context
|
|
93
|
+
* and restoring the previous context when the scope ends.
|
|
94
|
+
*/
|
|
95
|
+
export declare class BaggageScope {
|
|
96
|
+
/** @internal Exposed for testing. */
|
|
97
|
+
readonly contextWithBaggage: Context;
|
|
98
|
+
constructor(pairs: Map<string, string>);
|
|
99
|
+
/**
|
|
100
|
+
* Execute a synchronous function under this baggage scope.
|
|
101
|
+
* Automatically restores previous context afterward.
|
|
102
|
+
*/
|
|
103
|
+
run<T>(fn: () => T): T;
|
|
104
|
+
/**
|
|
105
|
+
* Dispose is a no-op because OpenTelemetry JS automatically restores
|
|
106
|
+
* the previous context after `context.with()` completes.
|
|
107
|
+
*/
|
|
108
|
+
[Symbol.dispose](): void;
|
|
109
|
+
/** Manual cleanup alternative if caller isn't using `using`. */
|
|
110
|
+
dispose(): void;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=BaggageBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaggageBuilder.d.ts","sourceRoot":"","sources":["../../../../src/a365/middleware/BaggageBuilder.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;;;;;;;;;;;;;GAcG;AACH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,CAAC,kBAAkB,EAAE,OAAO,CAAC;gBAEzB,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,gEAAgE;IAChE,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.BaggageScope = exports.BaggageBuilder = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Per-request baggage builder for OpenTelemetry context propagation.
|
|
8
|
+
*
|
|
9
|
+
* Provides a fluent API for setting baggage values that will be propagated
|
|
10
|
+
* in the OpenTelemetry context and stamped onto spans by the SpanProcessor.
|
|
11
|
+
*
|
|
12
|
+
* Adapted from microsoft/Agent365-nodejs agents-a365-observability/src/tracing/middleware/BaggageBuilder.ts
|
|
13
|
+
*/
|
|
14
|
+
const api_1 = require("@opentelemetry/api");
|
|
15
|
+
const constants_js_1 = require("../constants.js");
|
|
16
|
+
/**
|
|
17
|
+
* Fluent builder for setting OpenTelemetry baggage values.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const scope = new BaggageBuilder()
|
|
22
|
+
* .tenantId("tenant-123")
|
|
23
|
+
* .agentId("agent-456")
|
|
24
|
+
* .build();
|
|
25
|
+
*
|
|
26
|
+
* scope.run(() => {
|
|
27
|
+
* // Baggage is active in this context
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
class BaggageBuilder {
|
|
32
|
+
pairs = new Map();
|
|
33
|
+
/** Set the operation source baggage value (e.g., ATG, ACF). */
|
|
34
|
+
operationSource(value) {
|
|
35
|
+
this.set(constants_js_1.OpenTelemetryConstants.SERVICE_NAME_KEY, value);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/** Set the tenant ID baggage value. */
|
|
39
|
+
tenantId(value) {
|
|
40
|
+
this.set(constants_js_1.OpenTelemetryConstants.TENANT_ID_KEY, value);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/** Set the agent ID baggage value. */
|
|
44
|
+
agentId(value) {
|
|
45
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY, value);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/** Set the agent AUID baggage value. */
|
|
49
|
+
agentAuid(value) {
|
|
50
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY, value);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/** Set the agent email baggage value. */
|
|
54
|
+
agentEmail(value) {
|
|
55
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_EMAIL_KEY, value);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/** Set the agent blueprint ID baggage value. */
|
|
59
|
+
agentBlueprintId(value) {
|
|
60
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_BLUEPRINT_ID_KEY, value);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/** Set the session ID baggage value. */
|
|
64
|
+
sessionId(value) {
|
|
65
|
+
this.set(constants_js_1.OpenTelemetryConstants.SESSION_ID_KEY, value);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/** Set the user ID baggage value. */
|
|
69
|
+
userId(value) {
|
|
70
|
+
this.set(constants_js_1.OpenTelemetryConstants.USER_ID_KEY, value);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/** Set the agent name baggage value. */
|
|
74
|
+
agentName(value) {
|
|
75
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, value);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/** Set the agent description baggage value. */
|
|
79
|
+
agentDescription(value) {
|
|
80
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, value);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/** Set the agent platform ID baggage value. */
|
|
84
|
+
agentPlatformId(value) {
|
|
85
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_PLATFORM_ID_KEY, value);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/** Set the agent version baggage value. */
|
|
89
|
+
agentVersion(value) {
|
|
90
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_VERSION_KEY, value);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/** Set the session description baggage value. */
|
|
94
|
+
sessionDescription(value) {
|
|
95
|
+
this.set(constants_js_1.OpenTelemetryConstants.SESSION_DESCRIPTION_KEY, value);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/** Set the user name baggage value. */
|
|
99
|
+
userName(value) {
|
|
100
|
+
this.set(constants_js_1.OpenTelemetryConstants.USER_NAME_KEY, value);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
/** Set the user email baggage value. */
|
|
104
|
+
userEmail(value) {
|
|
105
|
+
this.set(constants_js_1.OpenTelemetryConstants.USER_EMAIL_KEY, value);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/** Set the caller client IP baggage value. */
|
|
109
|
+
callerClientIp(value) {
|
|
110
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_CLIENT_IP_KEY, value);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/** Set the caller agent platform ID baggage value. */
|
|
114
|
+
callerAgentPlatformId(value) {
|
|
115
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_PLATFORM_ID_KEY, value);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
/** Set the conversation ID baggage value. */
|
|
119
|
+
conversationId(value) {
|
|
120
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, value);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
/** Set the conversation item link baggage value. */
|
|
124
|
+
conversationItemLink(value) {
|
|
125
|
+
this.set(constants_js_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ITEM_LINK_KEY, value);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
/** Set the channel name (e.g., Teams, Slack). */
|
|
129
|
+
channelName(value) {
|
|
130
|
+
this.set(constants_js_1.OpenTelemetryConstants.CHANNEL_NAME_KEY, value);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/** Set the channel link/URL. */
|
|
134
|
+
channelLink(value) {
|
|
135
|
+
this.set(constants_js_1.OpenTelemetryConstants.CHANNEL_LINK_KEY, value);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sets the invoke agent server address and port baggage values.
|
|
140
|
+
* @param address The server address (hostname) of the target agent service.
|
|
141
|
+
* @param port Optional server port. Only recorded when different from 443.
|
|
142
|
+
*/
|
|
143
|
+
invokeAgentServer(address, port) {
|
|
144
|
+
this.set(constants_js_1.OpenTelemetryConstants.SERVER_ADDRESS_KEY, address);
|
|
145
|
+
if (port !== undefined && port !== 443) {
|
|
146
|
+
this.set(constants_js_1.OpenTelemetryConstants.SERVER_PORT_KEY, port.toString());
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.pairs.delete(constants_js_1.OpenTelemetryConstants.SERVER_PORT_KEY);
|
|
150
|
+
}
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Set multiple baggage pairs from a dictionary or iterable.
|
|
155
|
+
* @param pairs Dictionary or iterable of key-value pairs
|
|
156
|
+
*/
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
158
|
+
setPairs(pairs) {
|
|
159
|
+
if (!pairs) {
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
163
|
+
let entries;
|
|
164
|
+
if (Symbol.iterator in Object(pairs)) {
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
166
|
+
entries = pairs;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
entries = Object.entries(pairs);
|
|
170
|
+
}
|
|
171
|
+
for (const [key, value] of entries) {
|
|
172
|
+
if (value !== null && value !== undefined) {
|
|
173
|
+
this.set(key, String(value));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Apply the collected baggage to the current context.
|
|
180
|
+
* @returns A BaggageScope that can run callbacks under the baggage context
|
|
181
|
+
*/
|
|
182
|
+
build() {
|
|
183
|
+
return new BaggageScope(this.pairs);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Add a baggage key/value if the value is not null or whitespace.
|
|
187
|
+
*/
|
|
188
|
+
set(key, value) {
|
|
189
|
+
if (value !== null && value !== undefined) {
|
|
190
|
+
const trimmed = value.trim();
|
|
191
|
+
if (trimmed) {
|
|
192
|
+
this.pairs.set(key, trimmed);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Convenience method to begin a request baggage scope with common fields.
|
|
198
|
+
* @param tenantId The tenant ID
|
|
199
|
+
* @param agentId The agent ID
|
|
200
|
+
* @returns A BaggageScope with tenant and agent ID set
|
|
201
|
+
*/
|
|
202
|
+
static setRequestContext(tenantId, agentId) {
|
|
203
|
+
return new BaggageBuilder().tenantId(tenantId).agentId(agentId).build();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.BaggageBuilder = BaggageBuilder;
|
|
207
|
+
/**
|
|
208
|
+
* Context manager for baggage scope.
|
|
209
|
+
*
|
|
210
|
+
* Manages the lifecycle of baggage values, setting them in the OTel context
|
|
211
|
+
* and restoring the previous context when the scope ends.
|
|
212
|
+
*/
|
|
213
|
+
class BaggageScope {
|
|
214
|
+
/** @internal Exposed for testing. */
|
|
215
|
+
contextWithBaggage;
|
|
216
|
+
constructor(pairs) {
|
|
217
|
+
// 1. Start from current active context
|
|
218
|
+
const currentCtx = api_1.context.active();
|
|
219
|
+
// 2. Build merged baggage
|
|
220
|
+
let bag = api_1.propagation.getBaggage(currentCtx) ?? api_1.propagation.createBaggage({});
|
|
221
|
+
for (const [key, value] of pairs.entries()) {
|
|
222
|
+
if (value && value.trim()) {
|
|
223
|
+
bag = bag.setEntry(key, { value });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// 3. Create a new context that carries that baggage
|
|
227
|
+
this.contextWithBaggage = api_1.propagation.setBaggage(currentCtx, bag);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Execute a synchronous function under this baggage scope.
|
|
231
|
+
* Automatically restores previous context afterward.
|
|
232
|
+
*/
|
|
233
|
+
run(fn) {
|
|
234
|
+
return api_1.context.with(this.contextWithBaggage, fn);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Dispose is a no-op because OpenTelemetry JS automatically restores
|
|
238
|
+
* the previous context after `context.with()` completes.
|
|
239
|
+
*/
|
|
240
|
+
[Symbol.dispose]() {
|
|
241
|
+
// Nothing to detach manually; context restoration happens automatically.
|
|
242
|
+
}
|
|
243
|
+
/** Manual cleanup alternative if caller isn't using `using`. */
|
|
244
|
+
dispose() {
|
|
245
|
+
this[Symbol.dispose]();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.BaggageScope = BaggageScope;
|
|
249
|
+
//# sourceMappingURL=BaggageBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaggageBuilder.js","sourceRoot":"","sources":["../../../../src/a365/middleware/BaggageBuilder.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC;;;;;;;GAOG;AAEH,4CAAyE;AAEzE,kDAAyD;AAEzD;;;;;;;;;;;;;;GAcG;AACH,MAAa,cAAc;IACjB,KAAK,GAAwB,IAAI,GAAG,EAAE,CAAC;IAE/C,+DAA+D;IAC/D,eAAe,CAAC,KAAgC;QAC9C,IAAI,CAAC,GAAG,CAAC,qCAAsB,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uCAAuC;IACvC,QAAQ,CAAC,KAAgC;QACvC,IAAI,CAAC,GAAG,CAAC,qCAAsB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sCAAsC;IACtC,OAAO,CAAC,KAAgC;QACtC,IAAI,CAAC,GAAG,CAAC,qCAAsB,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wCAAwC;IACxC,SAAS,CAAC,KAAgC;QACxC,IAAI,CAAC,GAAG,CAAC,qCAAsB,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yCAAyC;IACzC,UAAU,CAAC,KAAgC;QACzC,IAAI,CAAC,GAAG,CAAC,qCAAsB,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gDAAgD;IAChD,gBAAgB,CAAC,KAAgC;QAC/C,IAAI,CAAC,GAAG,CAAC,qCAAsB,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IA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zB,CAAC;CACF;AAxCD,oCAwCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/a365/middleware/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.BaggageScope = exports.BaggageBuilder = void 0;
|
|
6
|
+
var BaggageBuilder_js_1 = require("./BaggageBuilder.js");
|
|
7
|
+
Object.defineProperty(exports, "BaggageBuilder", { enumerable: true, get: function () { return BaggageBuilder_js_1.BaggageBuilder; } });
|
|
8
|
+
Object.defineProperty(exports, "BaggageScope", { enumerable: true, get: function () { return BaggageBuilder_js_1.BaggageScope; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/a365/middleware/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,yDAAmE;AAA1D,mHAAA,cAAc,OAAA;AAAE,iHAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Span processor that propagates baggage key/value pairs to span attributes.
|
|
3
|
+
*
|
|
4
|
+
* This processor copies baggage entries onto spans based on the operation type.
|
|
5
|
+
* For `invoke_agent` operations, it applies both generic and invoke-agent-specific attributes.
|
|
6
|
+
* For other operations, it applies only generic attributes.
|
|
7
|
+
*
|
|
8
|
+
* Adapted from microsoft/Agent365-nodejs agents-a365-observability/src/tracing/processors/SpanProcessor.ts
|
|
9
|
+
*/
|
|
10
|
+
import type { Context, Span } from "@opentelemetry/api";
|
|
11
|
+
import type { SpanProcessor as BaseSpanProcessor, ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
12
|
+
/**
|
|
13
|
+
* Copies relevant baggage entries to span attributes on span start.
|
|
14
|
+
*
|
|
15
|
+
* This is the "automatic" counterpart to the manual scope API — it ensures
|
|
16
|
+
* every span in the pipeline gets agent identity attributes from baggage
|
|
17
|
+
* without explicitly creating scopes.
|
|
18
|
+
*/
|
|
19
|
+
export declare class A365SpanProcessor implements BaseSpanProcessor {
|
|
20
|
+
/**
|
|
21
|
+
* Called when a span is started.
|
|
22
|
+
* Copies relevant baggage entries to span attributes.
|
|
23
|
+
*/
|
|
24
|
+
onStart(span: Span, parentContext?: Context): void;
|
|
25
|
+
/** Called when a span is ended. */
|
|
26
|
+
onEnd(_span: ReadableSpan): void;
|
|
27
|
+
/** Shutdown the processor. */
|
|
28
|
+
shutdown(): Promise<void>;
|
|
29
|
+
/** Force flush the processor. */
|
|
30
|
+
forceFlush(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=A365SpanProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A365SpanProcessor.d.ts","sourceRoot":"","sources":["../../../../src/a365/processors/A365SpanProcessor.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EACV,aAAa,IAAI,iBAAiB,EAClC,YAAY,EACb,MAAM,+BAA+B,CAAC;AAIvC;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,iBAAiB;IACzD;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI;IAyFlD,mCAAmC;IACnC,KAAK,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAIhC,8BAA8B;IACxB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,iCAAiC;IAC3B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.A365SpanProcessor = void 0;
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const constants_js_1 = require("../constants.js");
|
|
8
|
+
const util_js_1 = require("./util.js");
|
|
9
|
+
/**
|
|
10
|
+
* Copies relevant baggage entries to span attributes on span start.
|
|
11
|
+
*
|
|
12
|
+
* This is the "automatic" counterpart to the manual scope API — it ensures
|
|
13
|
+
* every span in the pipeline gets agent identity attributes from baggage
|
|
14
|
+
* without explicitly creating scopes.
|
|
15
|
+
*/
|
|
16
|
+
class A365SpanProcessor {
|
|
17
|
+
/**
|
|
18
|
+
* Called when a span is started.
|
|
19
|
+
* Copies relevant baggage entries to span attributes.
|
|
20
|
+
*/
|
|
21
|
+
onStart(span, parentContext) {
|
|
22
|
+
const ctx = parentContext;
|
|
23
|
+
if (!ctx) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Get existing span attributes
|
|
27
|
+
const existingAttrs = new Set();
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const spanRecord = span;
|
|
31
|
+
if (spanRecord.attributes) {
|
|
32
|
+
Object.keys(spanRecord.attributes).forEach((key) => existingAttrs.add(key));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Ignore errors accessing span attributes
|
|
37
|
+
}
|
|
38
|
+
// Get all baggage entries
|
|
39
|
+
const baggage = api_1.propagation.getBaggage(ctx);
|
|
40
|
+
if (!baggage) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const baggageMap = new Map();
|
|
44
|
+
baggage.getAllEntries().forEach(([key, entry]) => {
|
|
45
|
+
if (entry.value) {
|
|
46
|
+
baggageMap.set(key, entry.value);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
// Determine if this is an invoke_agent operation
|
|
50
|
+
const operationName = baggageMap.get(constants_js_1.OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY) ||
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
span.attributes?.[constants_js_1.OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY];
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
const spanName = span.name || "";
|
|
55
|
+
const isInvokeAgent = operationName === constants_js_1.OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME ||
|
|
56
|
+
spanName.startsWith(constants_js_1.OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME);
|
|
57
|
+
// Build target key set
|
|
58
|
+
const targetKeys = new Set(util_js_1.GENERIC_ATTRIBUTES);
|
|
59
|
+
if (isInvokeAgent) {
|
|
60
|
+
util_js_1.INVOKE_AGENT_ATTRIBUTES.forEach((key) => targetKeys.add(key));
|
|
61
|
+
}
|
|
62
|
+
// Set telemetry SDK attributes
|
|
63
|
+
if (!existingAttrs.has(constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_NAME_KEY)) {
|
|
64
|
+
span.setAttribute(constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_NAME_KEY, constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_NAME_VALUE);
|
|
65
|
+
}
|
|
66
|
+
if (!existingAttrs.has(constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_LANGUAGE_KEY)) {
|
|
67
|
+
span.setAttribute(constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_LANGUAGE_KEY, constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_LANGUAGE_VALUE);
|
|
68
|
+
}
|
|
69
|
+
if (!existingAttrs.has(constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_VERSION_KEY)) {
|
|
70
|
+
span.setAttribute(constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_VERSION_KEY, constants_js_1.OpenTelemetryConstants.TELEMETRY_SDK_VERSION_VALUE);
|
|
71
|
+
}
|
|
72
|
+
// Copy baggage to span attributes
|
|
73
|
+
for (const key of targetKeys) {
|
|
74
|
+
// Skip if attribute already exists
|
|
75
|
+
if (existingAttrs.has(key)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const value = baggageMap.get(key);
|
|
79
|
+
if (!value) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
span.setAttribute(key, value);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore errors setting attributes
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Called when a span is ended. */
|
|
91
|
+
onEnd(_span) {
|
|
92
|
+
// No-op for this processor
|
|
93
|
+
}
|
|
94
|
+
/** Shutdown the processor. */
|
|
95
|
+
async shutdown() {
|
|
96
|
+
// No-op for this processor
|
|
97
|
+
}
|
|
98
|
+
/** Force flush the processor. */
|
|
99
|
+
async forceFlush() {
|
|
100
|
+
// No-op for this processor
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.A365SpanProcessor = A365SpanProcessor;
|
|
104
|
+
//# sourceMappingURL=A365SpanProcessor.js.map
|