@cuylabs/agent-microsoft-opentelemetry 6.1.0 → 6.2.1
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 +9 -0
- package/dist/{chunk-K54CB7U4.js → chunk-YDQDDNWT.js} +172 -15
- package/dist/index.d.ts +17 -1
- package/dist/index.js +5 -59
- package/dist/register.js +1 -1
- package/docs/architecture.md +8 -0
- package/docs/distro-alignment.md +5 -0
- package/examples/01-agent365-s2s.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -168,6 +168,15 @@ spans with `useA365Scopes: false`, `useDefaultOtelMiddleware: true`, or
|
|
|
168
168
|
`useGenAIOpenTelemetry: true`, but those settings should be deliberate because
|
|
169
169
|
they can duplicate tool or model telemetry.
|
|
170
170
|
|
|
171
|
+
When static identity fields such as `tenantId`, `agentId`, `agentName`,
|
|
172
|
+
`agentDescription`, `agentVersion`, `serviceName`, and `serverEndpoint` are supplied to
|
|
173
|
+
`createMicrosoftOpenTelemetryTracingConfig()` or `initMicrosoftOpenTelemetry()`,
|
|
174
|
+
the A365 scope middleware uses them as static request identity for local agents
|
|
175
|
+
and background jobs that are not already wrapped in
|
|
176
|
+
`runWithMicrosoftA365Context()`. Real channel turns should still provide the
|
|
177
|
+
ambient request context so user, conversation, channel, and export-token
|
|
178
|
+
metadata can flow with the turn.
|
|
179
|
+
|
|
171
180
|
## Source Layout
|
|
172
181
|
|
|
173
182
|
The source tree mirrors the adapter's ownership boundaries, not the full
|
|
@@ -656,12 +656,25 @@ function createMicrosoftA365ScopeMiddleware(options = {}) {
|
|
|
656
656
|
const recordInputs = options.recordInputs ?? true;
|
|
657
657
|
const recordOutputs = options.recordOutputs ?? true;
|
|
658
658
|
const emitOutputScope = options.emitOutputScope ?? true;
|
|
659
|
+
const defaultRequestContext = options.defaultRequestContext;
|
|
659
660
|
const states = /* @__PURE__ */ new Map();
|
|
660
661
|
const statesByRequestContext = /* @__PURE__ */ new WeakMap();
|
|
662
|
+
function getTraceContext(sessionId, ctx) {
|
|
663
|
+
const state = findState(states, sessionId, ctx?.turnId);
|
|
664
|
+
if (!state) {
|
|
665
|
+
return void 0;
|
|
666
|
+
}
|
|
667
|
+
const inferenceContext = latestInferenceContext(state);
|
|
668
|
+
return inferenceContext ?? state.invokeContext;
|
|
669
|
+
}
|
|
661
670
|
return {
|
|
662
671
|
name: "microsoft-a365-scopes",
|
|
663
672
|
async onChatStart(sessionId, message, ctx) {
|
|
664
|
-
const
|
|
673
|
+
const activeRequestContext = currentMicrosoftA365RequestContext();
|
|
674
|
+
const requestContext = mergeRequestContexts(
|
|
675
|
+
defaultRequestContext,
|
|
676
|
+
activeRequestContext
|
|
677
|
+
);
|
|
665
678
|
if (!requestContext || !hasA365ScopeIdentity(requestContext)) {
|
|
666
679
|
return;
|
|
667
680
|
}
|
|
@@ -697,7 +710,9 @@ function createMicrosoftA365ScopeMiddleware(options = {}) {
|
|
|
697
710
|
toolScopes: /* @__PURE__ */ new Map()
|
|
698
711
|
};
|
|
699
712
|
states.set(turnKey(sessionId, ctx?.turnId), state);
|
|
700
|
-
|
|
713
|
+
if (activeRequestContext) {
|
|
714
|
+
statesByRequestContext.set(activeRequestContext, state);
|
|
715
|
+
}
|
|
701
716
|
statesByRequestContext.set(scopedRequestContext, state);
|
|
702
717
|
},
|
|
703
718
|
model: {
|
|
@@ -831,19 +846,32 @@ function createMicrosoftA365ScopeMiddleware(options = {}) {
|
|
|
831
846
|
}
|
|
832
847
|
statesByRequestContext.delete(state.requestContext);
|
|
833
848
|
},
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
if (!state) {
|
|
837
|
-
return void 0;
|
|
838
|
-
}
|
|
839
|
-
const inferenceContext = latestInferenceContext(state);
|
|
840
|
-
return inferenceContext ?? state.invokeContext;
|
|
841
|
-
}
|
|
849
|
+
getTraceContext,
|
|
850
|
+
getOtelContext: getTraceContext
|
|
842
851
|
};
|
|
843
852
|
}
|
|
844
853
|
function hasA365ScopeIdentity(context) {
|
|
845
854
|
return Boolean(context.tenantId && context.agentId);
|
|
846
855
|
}
|
|
856
|
+
function mergeRequestContexts(defaults, active) {
|
|
857
|
+
if (!defaults && !active) {
|
|
858
|
+
return void 0;
|
|
859
|
+
}
|
|
860
|
+
const merged = {};
|
|
861
|
+
assignDefinedRequestContextValues(merged, defaults);
|
|
862
|
+
assignDefinedRequestContextValues(merged, active);
|
|
863
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
864
|
+
}
|
|
865
|
+
function assignDefinedRequestContextValues(target, source) {
|
|
866
|
+
if (!source) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
for (const [key, value] of Object.entries(source)) {
|
|
870
|
+
if (value !== void 0) {
|
|
871
|
+
target[key] = value;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
847
875
|
function safeStartScope(start) {
|
|
848
876
|
try {
|
|
849
877
|
return start();
|
|
@@ -862,7 +890,7 @@ function currentState(states, statesByRequestContext) {
|
|
|
862
890
|
return findState(states, requestContext.sessionId);
|
|
863
891
|
}
|
|
864
892
|
}
|
|
865
|
-
return latestState(states);
|
|
893
|
+
return states.size === 1 ? latestState(states) : void 0;
|
|
866
894
|
}
|
|
867
895
|
function startToolScope(state, event, recordInputs) {
|
|
868
896
|
if (!state.module.ExecuteToolScope) {
|
|
@@ -1053,25 +1081,68 @@ function createMicrosoftOpenTelemetryTracingConfig(options = {}) {
|
|
|
1053
1081
|
spanAttributes[MICROSOFT_A365_ATTRIBUTES.tenantId] = options.tenantId.trim();
|
|
1054
1082
|
}
|
|
1055
1083
|
const useA365Scopes = options.useA365Scopes ?? true;
|
|
1084
|
+
const defaultRequestContext = mergeA365RequestContexts(
|
|
1085
|
+
createStaticA365RequestContext(options),
|
|
1086
|
+
options.a365Scopes?.defaultRequestContext
|
|
1087
|
+
);
|
|
1056
1088
|
return {
|
|
1057
1089
|
...isNonEmpty(options.agentId) ? { agentId: options.agentId.trim() } : {},
|
|
1058
1090
|
...isNonEmpty(options.agentDescription) ? { agentDescription: options.agentDescription.trim() } : {},
|
|
1059
1091
|
...isNonEmpty(options.agentVersion) ? { agentVersion: options.agentVersion.trim() } : {},
|
|
1060
1092
|
...options.recordInputs !== void 0 ? { recordInputs: options.recordInputs } : {},
|
|
1061
1093
|
...options.recordOutputs !== void 0 ? { recordOutputs: options.recordOutputs } : {},
|
|
1062
|
-
emitToolSpans: options.emitToolSpans
|
|
1094
|
+
...options.emitToolSpans !== void 0 ? { emitToolSpans: options.emitToolSpans } : useA365Scopes ? { emitToolSpans: false } : {},
|
|
1063
1095
|
useGenAIOpenTelemetry: options.useGenAIOpenTelemetry ?? (useA365Scopes ? false : true),
|
|
1064
1096
|
...options.telemetryIntegrations ? { telemetryIntegrations: options.telemetryIntegrations } : {},
|
|
1065
1097
|
...options.useGlobalTelemetryIntegrations !== void 0 ? {
|
|
1066
1098
|
useGlobalTelemetryIntegrations: options.useGlobalTelemetryIntegrations
|
|
1067
1099
|
} : {},
|
|
1068
1100
|
...useA365Scopes ? {
|
|
1069
|
-
middleware: createMicrosoftA365ScopeMiddleware(
|
|
1101
|
+
middleware: createMicrosoftA365ScopeMiddleware({
|
|
1102
|
+
...options.a365Scopes,
|
|
1103
|
+
...defaultRequestContext ? { defaultRequestContext } : {}
|
|
1104
|
+
}),
|
|
1070
1105
|
useDefaultOtelMiddleware: options.useDefaultOtelMiddleware ?? false
|
|
1071
1106
|
} : options.useDefaultOtelMiddleware !== void 0 ? { useDefaultOtelMiddleware: options.useDefaultOtelMiddleware } : {},
|
|
1072
1107
|
...Object.keys(spanAttributes).length > 0 ? { spanAttributes } : {}
|
|
1073
1108
|
};
|
|
1074
1109
|
}
|
|
1110
|
+
function createStaticA365RequestContext(options) {
|
|
1111
|
+
const context = {};
|
|
1112
|
+
setIfNonEmpty(context, "tenantId", options.tenantId);
|
|
1113
|
+
setIfNonEmpty(context, "agentId", options.agentId);
|
|
1114
|
+
setIfNonEmpty(context, "agentName", options.agentName);
|
|
1115
|
+
setIfNonEmpty(context, "agentDescription", options.agentDescription);
|
|
1116
|
+
setIfNonEmpty(context, "agentVersion", options.agentVersion);
|
|
1117
|
+
setIfNonEmpty(context, "serviceName", options.serviceName);
|
|
1118
|
+
setIfNonEmpty(
|
|
1119
|
+
context,
|
|
1120
|
+
"serverAddress",
|
|
1121
|
+
options.serverEndpoint?.serverAddress
|
|
1122
|
+
);
|
|
1123
|
+
if (options.serverEndpoint?.serverPort !== void 0) {
|
|
1124
|
+
context.serverPort = options.serverEndpoint.serverPort;
|
|
1125
|
+
}
|
|
1126
|
+
return Object.keys(context).length > 0 ? context : void 0;
|
|
1127
|
+
}
|
|
1128
|
+
function setIfNonEmpty(context, key, value) {
|
|
1129
|
+
if (typeof value !== "string") {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
const trimmed = value.trim();
|
|
1133
|
+
if (trimmed) {
|
|
1134
|
+
context[key] = trimmed;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
function mergeA365RequestContexts(defaults, overrides) {
|
|
1138
|
+
if (!defaults && !overrides) {
|
|
1139
|
+
return void 0;
|
|
1140
|
+
}
|
|
1141
|
+
return {
|
|
1142
|
+
...defaults ?? {},
|
|
1143
|
+
...overrides ?? {}
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1075
1146
|
|
|
1076
1147
|
// src/runtime/instrumentation.ts
|
|
1077
1148
|
var INFRA_INSTRUMENTATION_KEYS = [
|
|
@@ -1164,6 +1235,64 @@ function mergeConfig(base, override) {
|
|
|
1164
1235
|
};
|
|
1165
1236
|
}
|
|
1166
1237
|
|
|
1238
|
+
// src/runtime/destinations.ts
|
|
1239
|
+
var TRUE_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
1240
|
+
function isMicrosoftOtlpEnvironmentEnabled(env = process.env) {
|
|
1241
|
+
return Boolean(
|
|
1242
|
+
readFirst(
|
|
1243
|
+
env,
|
|
1244
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
1245
|
+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
|
1246
|
+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT",
|
|
1247
|
+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
|
|
1248
|
+
)
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
function isAzureMonitorEnvironmentEnabled(env = process.env) {
|
|
1252
|
+
if (isTruthy(readFirst(env, "MICROSOFT_OTEL_AZURE_MONITOR_ENABLED"))) {
|
|
1253
|
+
return true;
|
|
1254
|
+
}
|
|
1255
|
+
return Boolean(readFirst(env, "APPLICATIONINSIGHTS_CONNECTION_STRING"));
|
|
1256
|
+
}
|
|
1257
|
+
function createAzureMonitorOptionsFromEnv(env = process.env) {
|
|
1258
|
+
const enabled = isAzureMonitorEnvironmentEnabled(env);
|
|
1259
|
+
const connectionString = readFirst(
|
|
1260
|
+
env,
|
|
1261
|
+
"APPLICATIONINSIGHTS_CONNECTION_STRING"
|
|
1262
|
+
);
|
|
1263
|
+
if (!enabled && !connectionString) {
|
|
1264
|
+
return void 0;
|
|
1265
|
+
}
|
|
1266
|
+
return {
|
|
1267
|
+
enabled,
|
|
1268
|
+
...connectionString ? { azureMonitorExporterOptions: { connectionString } } : {}
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
function summarizeMicrosoftOpenTelemetryDestinations(options = {}) {
|
|
1272
|
+
const env = options.env ?? process.env;
|
|
1273
|
+
const azureMonitor = options.azureMonitor === false ? false : options.azureMonitor?.enabled ?? isAzureMonitorEnvironmentEnabled(env);
|
|
1274
|
+
const agent365 = options.a365?.enabled === true && options.a365.enableObservabilityExporter === true;
|
|
1275
|
+
const otlp = isMicrosoftOtlpEnvironmentEnabled(env);
|
|
1276
|
+
return {
|
|
1277
|
+
agent365,
|
|
1278
|
+
azureMonitor,
|
|
1279
|
+
otlp,
|
|
1280
|
+
console: options.enableConsoleExporters ?? (!agent365 && !azureMonitor && !otlp)
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
function readFirst(env, ...names) {
|
|
1284
|
+
for (const name of names) {
|
|
1285
|
+
const value = env[name]?.trim();
|
|
1286
|
+
if (value) {
|
|
1287
|
+
return value;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
return void 0;
|
|
1291
|
+
}
|
|
1292
|
+
function isTruthy(value) {
|
|
1293
|
+
return TRUE_VALUES.has((value ?? "").trim().toLowerCase());
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1167
1296
|
// src/runtime/lifecycle.ts
|
|
1168
1297
|
async function initMicrosoftOpenTelemetry(options = {}) {
|
|
1169
1298
|
const module = await loadMicrosoftOpenTelemetryModule(options.runtime);
|
|
@@ -1171,7 +1300,10 @@ async function initMicrosoftOpenTelemetry(options = {}) {
|
|
|
1171
1300
|
const distroOptions = await createDistroOptions(options, resource);
|
|
1172
1301
|
module.useMicrosoftOpenTelemetry(distroOptions);
|
|
1173
1302
|
return {
|
|
1174
|
-
tracing: createMicrosoftOpenTelemetryTracingConfig(
|
|
1303
|
+
tracing: createMicrosoftOpenTelemetryTracingConfig({
|
|
1304
|
+
...options.agent,
|
|
1305
|
+
...options.resource?.serviceName && !options.agent?.serviceName ? { serviceName: options.resource.serviceName } : {}
|
|
1306
|
+
}),
|
|
1175
1307
|
shutdown: () => module.shutdownMicrosoftOpenTelemetry()
|
|
1176
1308
|
};
|
|
1177
1309
|
}
|
|
@@ -1195,11 +1327,32 @@ async function initMicrosoftOpenTelemetryFromEnv(options = {}) {
|
|
|
1195
1327
|
env: options.env
|
|
1196
1328
|
}) : void 0)
|
|
1197
1329
|
} : void 0,
|
|
1198
|
-
azureMonitor:
|
|
1330
|
+
azureMonitor: createEnvAzureMonitorOptions(
|
|
1331
|
+
options.env,
|
|
1332
|
+
env.azureMonitorEnabled,
|
|
1333
|
+
options.azureMonitor
|
|
1334
|
+
),
|
|
1199
1335
|
instrumentationProfile: options.instrumentationProfile ?? env.instrumentationProfile,
|
|
1200
1336
|
enableConsoleExporters: options.enableConsoleExporters ?? env.enableConsoleExporters
|
|
1201
1337
|
});
|
|
1202
1338
|
}
|
|
1339
|
+
function createEnvAzureMonitorOptions(sourceEnv, envEnabled, options) {
|
|
1340
|
+
if (options === false) {
|
|
1341
|
+
return false;
|
|
1342
|
+
}
|
|
1343
|
+
const envOptions = createAzureMonitorOptionsFromEnv(sourceEnv);
|
|
1344
|
+
const resolvedEnvOptions = envEnabled !== void 0 ? {
|
|
1345
|
+
...envOptions ?? {},
|
|
1346
|
+
enabled: envEnabled
|
|
1347
|
+
} : envOptions;
|
|
1348
|
+
if (!resolvedEnvOptions && !options) {
|
|
1349
|
+
return void 0;
|
|
1350
|
+
}
|
|
1351
|
+
return {
|
|
1352
|
+
...resolvedEnvOptions ?? {},
|
|
1353
|
+
...options ?? {}
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1203
1356
|
async function runWithMicrosoftA365Context(requestContext, fn, options = {}) {
|
|
1204
1357
|
const module = await loadMicrosoftOpenTelemetryModule(options);
|
|
1205
1358
|
const runWithBaggage = () => runWithMicrosoftA365RequestContext(requestContext, () => {
|
|
@@ -1369,6 +1522,10 @@ export {
|
|
|
1369
1522
|
createMicrosoftOpenTelemetryInstrumentationOptions,
|
|
1370
1523
|
normalizeInstrumentationProfile,
|
|
1371
1524
|
mergeInstrumentationOptions,
|
|
1525
|
+
isMicrosoftOtlpEnvironmentEnabled,
|
|
1526
|
+
isAzureMonitorEnvironmentEnabled,
|
|
1527
|
+
createAzureMonitorOptionsFromEnv,
|
|
1528
|
+
summarizeMicrosoftOpenTelemetryDestinations,
|
|
1372
1529
|
initMicrosoftOpenTelemetry,
|
|
1373
1530
|
initMicrosoftOpenTelemetryFromEnv,
|
|
1374
1531
|
runWithMicrosoftA365Context,
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,14 @@ type SpanAttributeValue = string | number | boolean | string[] | number[] | bool
|
|
|
11
11
|
|
|
12
12
|
type MicrosoftOpenTelemetryTracingConfigOptions = {
|
|
13
13
|
agentId?: string;
|
|
14
|
+
agentName?: string;
|
|
14
15
|
agentDescription?: string;
|
|
15
16
|
agentVersion?: string;
|
|
17
|
+
serviceName?: string;
|
|
18
|
+
serverEndpoint?: {
|
|
19
|
+
serverAddress: string;
|
|
20
|
+
serverPort?: number;
|
|
21
|
+
};
|
|
16
22
|
recordInputs?: boolean;
|
|
17
23
|
recordOutputs?: boolean;
|
|
18
24
|
/**
|
|
@@ -297,6 +303,15 @@ type MicrosoftA365RequestContext = {
|
|
|
297
303
|
extraBaggage?: Record<string, string | number | boolean | null | undefined>;
|
|
298
304
|
};
|
|
299
305
|
type MicrosoftA365ScopeMiddlewareOptions = {
|
|
306
|
+
/**
|
|
307
|
+
* Static Agent 365 request identity used when a turn is not already running
|
|
308
|
+
* inside `runWithMicrosoftA365Context()`.
|
|
309
|
+
*
|
|
310
|
+
* Ambient request context values override these defaults. This is useful for
|
|
311
|
+
* local agents or background jobs that have stable tenant/agent identity but
|
|
312
|
+
* no channel turn context.
|
|
313
|
+
*/
|
|
314
|
+
defaultRequestContext?: MicrosoftA365RequestContext;
|
|
300
315
|
/**
|
|
301
316
|
* Capture prompt/user content on invoke and inference scopes.
|
|
302
317
|
*
|
|
@@ -498,9 +513,10 @@ declare function mergeInstrumentationOptions(base: MicrosoftOpenTelemetryInstrum
|
|
|
498
513
|
|
|
499
514
|
declare function initMicrosoftOpenTelemetry(options?: MicrosoftOpenTelemetryOptions): Promise<MicrosoftOpenTelemetryHandle>;
|
|
500
515
|
declare function initMicrosoftOpenTelemetryFromEnv(options?: Omit<MicrosoftOpenTelemetryOptions, "resource" | "a365" | "azureMonitor"> & {
|
|
501
|
-
env?:
|
|
516
|
+
env?: MicrosoftOpenTelemetryEnvironment;
|
|
502
517
|
resource?: Partial<MicrosoftOpenTelemetryResourceOptions>;
|
|
503
518
|
a365?: Partial<MicrosoftOpenTelemetryA365Options>;
|
|
519
|
+
azureMonitor?: Partial<MicrosoftOpenTelemetryAzureMonitorOptions> | false;
|
|
504
520
|
}): Promise<MicrosoftOpenTelemetryHandle>;
|
|
505
521
|
declare function runWithMicrosoftA365Context<T>(requestContext: MicrosoftA365RequestContext, fn: () => T, options?: MicrosoftOpenTelemetryRuntimeOptions): Promise<Awaited<T>>;
|
|
506
522
|
declare function updateMicrosoftA365ExportToken(token: string, options?: MicrosoftOpenTelemetryRuntimeOptions): Promise<boolean>;
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
buildMicrosoftA365BaggagePairs,
|
|
8
8
|
callOptionalBooleanMethod,
|
|
9
9
|
callOptionalStringMethod,
|
|
10
|
+
createAzureMonitorOptionsFromEnv,
|
|
10
11
|
createEnvReader,
|
|
11
12
|
createMicrosoftA365S2STokenResolver,
|
|
12
13
|
createMicrosoftA365S2STokenResolverFromEnv,
|
|
@@ -17,6 +18,8 @@ import {
|
|
|
17
18
|
firstNonEmpty,
|
|
18
19
|
initMicrosoftOpenTelemetry,
|
|
19
20
|
initMicrosoftOpenTelemetryFromEnv,
|
|
21
|
+
isAzureMonitorEnvironmentEnabled,
|
|
22
|
+
isMicrosoftOtlpEnvironmentEnabled,
|
|
20
23
|
loadMicrosoftOpenTelemetryModule,
|
|
21
24
|
loadOpenTelemetryResourceModule,
|
|
22
25
|
mergeInstrumentationOptions,
|
|
@@ -28,8 +31,9 @@ import {
|
|
|
28
31
|
resolveMicrosoftOpenTelemetryNumberEnv,
|
|
29
32
|
runWithMicrosoftA365Context,
|
|
30
33
|
runWithMicrosoftA365RequestContext,
|
|
34
|
+
summarizeMicrosoftOpenTelemetryDestinations,
|
|
31
35
|
updateMicrosoftA365ExportToken
|
|
32
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-YDQDDNWT.js";
|
|
33
37
|
|
|
34
38
|
// src/a365/hosting.ts
|
|
35
39
|
async function configureMicrosoftA365Hosting(adapter, options = {}) {
|
|
@@ -280,64 +284,6 @@ function createMicrosoftA365ObservedTurnSource({
|
|
|
280
284
|
}
|
|
281
285
|
};
|
|
282
286
|
}
|
|
283
|
-
|
|
284
|
-
// src/runtime/destinations.ts
|
|
285
|
-
var TRUE_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
286
|
-
function isMicrosoftOtlpEnvironmentEnabled(env = process.env) {
|
|
287
|
-
return Boolean(
|
|
288
|
-
readFirst(
|
|
289
|
-
env,
|
|
290
|
-
"OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
291
|
-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
|
292
|
-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT",
|
|
293
|
-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
|
|
294
|
-
)
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
function isAzureMonitorEnvironmentEnabled(env = process.env) {
|
|
298
|
-
if (isTruthy(readFirst(env, "MICROSOFT_OTEL_AZURE_MONITOR_ENABLED"))) {
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
return Boolean(readFirst(env, "APPLICATIONINSIGHTS_CONNECTION_STRING"));
|
|
302
|
-
}
|
|
303
|
-
function createAzureMonitorOptionsFromEnv(env = process.env) {
|
|
304
|
-
const enabled = isAzureMonitorEnvironmentEnabled(env);
|
|
305
|
-
const connectionString = readFirst(
|
|
306
|
-
env,
|
|
307
|
-
"APPLICATIONINSIGHTS_CONNECTION_STRING"
|
|
308
|
-
);
|
|
309
|
-
if (!enabled && !connectionString) {
|
|
310
|
-
return void 0;
|
|
311
|
-
}
|
|
312
|
-
return {
|
|
313
|
-
enabled,
|
|
314
|
-
...connectionString ? { azureMonitorExporterOptions: { connectionString } } : {}
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
function summarizeMicrosoftOpenTelemetryDestinations(options = {}) {
|
|
318
|
-
const env = options.env ?? process.env;
|
|
319
|
-
const azureMonitor = options.azureMonitor === false ? false : options.azureMonitor?.enabled ?? isAzureMonitorEnvironmentEnabled(env);
|
|
320
|
-
const agent365 = options.a365?.enabled === true && options.a365.enableObservabilityExporter === true;
|
|
321
|
-
const otlp = isMicrosoftOtlpEnvironmentEnabled(env);
|
|
322
|
-
return {
|
|
323
|
-
agent365,
|
|
324
|
-
azureMonitor,
|
|
325
|
-
otlp,
|
|
326
|
-
console: options.enableConsoleExporters ?? (!agent365 && !azureMonitor && !otlp)
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function readFirst(env, ...names) {
|
|
330
|
-
for (const name of names) {
|
|
331
|
-
const value = env[name]?.trim();
|
|
332
|
-
if (value) {
|
|
333
|
-
return value;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return void 0;
|
|
337
|
-
}
|
|
338
|
-
function isTruthy(value) {
|
|
339
|
-
return TRUE_VALUES.has((value ?? "").trim().toLowerCase());
|
|
340
|
-
}
|
|
341
287
|
export {
|
|
342
288
|
MICROSOFT_A365_ATTRIBUTES,
|
|
343
289
|
MICROSOFT_A365_FMI_SCOPE,
|
package/dist/register.js
CHANGED
package/docs/architecture.md
CHANGED
|
@@ -97,6 +97,14 @@ now owns `ExecuteToolScope` creation for `agents-ts` turns. Enabling the older
|
|
|
97
97
|
generic middleware or local AI SDK GenAI telemetry at the same time can create
|
|
98
98
|
duplicate `execute_tool` records.
|
|
99
99
|
|
|
100
|
+
If the tracing config includes static `tenantId`, `agentId`, `agentName`,
|
|
101
|
+
`agentDescription`, `agentVersion`, `serviceName`, or `serverEndpoint` values,
|
|
102
|
+
the A365 scope middleware uses them when no ambient A365 request context exists.
|
|
103
|
+
This keeps local agents and background jobs observable without requiring a channel
|
|
104
|
+
turn wrapper. Channel adapters should still run each turn inside
|
|
105
|
+
`runWithMicrosoftA365Context()` so per-user and per-conversation dimensions are
|
|
106
|
+
not flattened into static process identity.
|
|
107
|
+
|
|
100
108
|
If an application has a custom execution path that should bypass the official
|
|
101
109
|
A365 scope middleware, it can opt out and use generic agent-core OTel spans:
|
|
102
110
|
|
package/docs/distro-alignment.md
CHANGED
|
@@ -125,6 +125,11 @@ Use `useA365Scopes: false` only when an application intentionally wants the
|
|
|
125
125
|
older generic agent-core OTel lifecycle instead of Microsoft's A365 product
|
|
126
126
|
scope model.
|
|
127
127
|
|
|
128
|
+
Static tracing identity from `tenantId`, `agentId`, `agentName`,
|
|
129
|
+
`agentDescription`, `agentVersion`, `serviceName`, and `serverEndpoint` is used
|
|
130
|
+
as a fallback request context for local/background turns. Ambient channel
|
|
131
|
+
request context still takes precedence.
|
|
132
|
+
|
|
128
133
|
## Optional Microsoft Framework Instrumentation
|
|
129
134
|
|
|
130
135
|
The Microsoft distro's OpenAI Agents and LangChain integrations are optional
|
|
@@ -22,6 +22,7 @@ const observability = await initMicrosoftOpenTelemetry({
|
|
|
22
22
|
},
|
|
23
23
|
instrumentationProfile: "agent-core",
|
|
24
24
|
agent: {
|
|
25
|
+
tenantId: process.env.A365_OBSERVABILITY_TENANT_ID,
|
|
25
26
|
agentId: process.env.A365_OBSERVABILITY_AGENT_ID,
|
|
26
27
|
agentDescription: "Example Agent 365 S2S agent",
|
|
27
28
|
recordInputs: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/agent-microsoft-opentelemetry",
|
|
3
|
-
"version": "6.1
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "Microsoft OpenTelemetry distro adapter for @cuylabs/agent-core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"typescript": "^5.7.0",
|
|
40
40
|
"vitest": "^4.0.18",
|
|
41
41
|
"zod": "^3.25.76 || ^4.1.8",
|
|
42
|
-
"@cuylabs/agent-core": "^6.1
|
|
42
|
+
"@cuylabs/agent-core": "^6.2.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@cuylabs/agent-core": "^6.0.0",
|