@microsoft/opentelemetry 0.1.0-alpha.4 → 0.1.0-alpha.5
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 +99 -7
- package/dist/commonjs/a365/configuration/A365Configuration.d.ts +12 -9
- package/dist/commonjs/a365/configuration/A365Configuration.d.ts.map +1 -1
- package/dist/commonjs/a365/configuration/A365Configuration.js +12 -33
- package/dist/commonjs/a365/configuration/A365Configuration.js.map +1 -1
- package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts +14 -8
- package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -1
- package/dist/commonjs/a365/configuration/index.d.ts +1 -0
- package/dist/commonjs/a365/configuration/index.d.ts.map +1 -1
- package/dist/commonjs/a365/constants.d.ts +1 -2
- package/dist/commonjs/a365/constants.d.ts.map +1 -1
- package/dist/commonjs/a365/constants.js +0 -1
- package/dist/commonjs/a365/constants.js.map +1 -1
- package/dist/commonjs/a365/context/tokenContext.js +6 -6
- package/dist/commonjs/a365/context/tokenContext.js.map +1 -1
- package/dist/commonjs/a365/context.js +2 -2
- package/dist/commonjs/a365/context.js.map +1 -1
- package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts.map +1 -1
- package/dist/commonjs/a365/exporter/Agent365Exporter.js +3 -3
- package/dist/commonjs/a365/exporter/Agent365Exporter.js.map +1 -1
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts +4 -1
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -1
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js +2 -0
- package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js.map +1 -1
- package/dist/commonjs/a365/index.d.ts +3 -3
- package/dist/commonjs/a365/index.d.ts.map +1 -1
- package/dist/commonjs/a365/index.js +4 -2
- package/dist/commonjs/a365/index.js.map +1 -1
- package/dist/commonjs/a365/logging.d.ts +16 -0
- package/dist/commonjs/a365/logging.d.ts.map +1 -0
- package/dist/commonjs/a365/logging.js +81 -0
- package/dist/commonjs/a365/logging.js.map +1 -0
- package/dist/commonjs/a365/processors/index.d.ts +0 -2
- package/dist/commonjs/a365/processors/index.d.ts.map +1 -1
- package/dist/commonjs/a365/processors/index.js +1 -3
- package/dist/commonjs/a365/processors/index.js.map +1 -1
- package/dist/commonjs/azureMonitor/traces/handler.d.ts.map +1 -1
- package/dist/commonjs/azureMonitor/traces/handler.js +0 -10
- package/dist/commonjs/azureMonitor/traces/handler.js.map +1 -1
- package/dist/commonjs/distro/distro.d.ts.map +1 -1
- package/dist/commonjs/distro/distro.js +87 -6
- package/dist/commonjs/distro/distro.js.map +1 -1
- package/dist/commonjs/distro/instrumentations.d.ts +2 -2
- package/dist/commonjs/distro/instrumentations.d.ts.map +1 -1
- package/dist/commonjs/distro/instrumentations.js +2 -6
- package/dist/commonjs/distro/instrumentations.js.map +1 -1
- package/dist/commonjs/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.d.ts +1 -17
- package/dist/commonjs/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.d.ts.map +1 -1
- package/dist/commonjs/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.js +1 -1
- package/dist/commonjs/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.js.map +1 -1
- package/dist/commonjs/index.d.ts +3 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +44 -43
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/shared/config.d.ts +0 -1
- package/dist/commonjs/shared/config.d.ts.map +1 -1
- package/dist/commonjs/shared/config.js +2 -39
- package/dist/commonjs/shared/config.js.map +1 -1
- package/dist/commonjs/types.d.ts +7 -9
- 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 +12 -9
- package/dist/esm/a365/configuration/A365Configuration.d.ts.map +1 -1
- package/dist/esm/a365/configuration/A365Configuration.js +12 -33
- package/dist/esm/a365/configuration/A365Configuration.js.map +1 -1
- package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts +14 -8
- package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -1
- package/dist/esm/a365/configuration/index.d.ts +1 -0
- package/dist/esm/a365/configuration/index.d.ts.map +1 -1
- package/dist/esm/a365/constants.d.ts +1 -2
- package/dist/esm/a365/constants.d.ts.map +1 -1
- package/dist/esm/a365/constants.js +0 -1
- package/dist/esm/a365/constants.js.map +1 -1
- package/dist/esm/a365/context/tokenContext.js +6 -6
- package/dist/esm/a365/context/tokenContext.js.map +1 -1
- package/dist/esm/a365/context.js +2 -2
- package/dist/esm/a365/context.js.map +1 -1
- package/dist/esm/a365/exporter/Agent365Exporter.d.ts.map +1 -1
- package/dist/esm/a365/exporter/Agent365Exporter.js +3 -3
- package/dist/esm/a365/exporter/Agent365Exporter.js.map +1 -1
- package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts +4 -1
- package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -1
- package/dist/esm/a365/exporter/Agent365ExporterOptions.js +2 -0
- package/dist/esm/a365/exporter/Agent365ExporterOptions.js.map +1 -1
- package/dist/esm/a365/index.d.ts +3 -3
- package/dist/esm/a365/index.d.ts.map +1 -1
- package/dist/esm/a365/index.js +2 -1
- package/dist/esm/a365/index.js.map +1 -1
- package/dist/esm/a365/logging.d.ts +16 -0
- package/dist/esm/a365/logging.d.ts.map +1 -0
- package/dist/esm/a365/logging.js +76 -0
- package/dist/esm/a365/logging.js.map +1 -0
- package/dist/esm/a365/processors/index.d.ts +0 -2
- package/dist/esm/a365/processors/index.d.ts.map +1 -1
- package/dist/esm/a365/processors/index.js +0 -1
- package/dist/esm/a365/processors/index.js.map +1 -1
- package/dist/esm/azureMonitor/traces/handler.d.ts.map +1 -1
- package/dist/esm/azureMonitor/traces/handler.js +0 -8
- package/dist/esm/azureMonitor/traces/handler.js.map +1 -1
- package/dist/esm/distro/distro.d.ts.map +1 -1
- package/dist/esm/distro/distro.js +55 -7
- package/dist/esm/distro/distro.js.map +1 -1
- package/dist/esm/distro/instrumentations.d.ts +2 -2
- package/dist/esm/distro/instrumentations.d.ts.map +1 -1
- package/dist/esm/distro/instrumentations.js +2 -6
- package/dist/esm/distro/instrumentations.js.map +1 -1
- package/dist/esm/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.d.ts +1 -17
- package/dist/esm/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.d.ts.map +1 -1
- package/dist/esm/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.js +1 -1
- package/dist/esm/genai/instrumentations/openai/openAIAgentsTraceInstrumentor.js.map +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/shared/config.d.ts +0 -1
- package/dist/esm/shared/config.d.ts.map +1 -1
- package/dist/esm/shared/config.js +2 -39
- package/dist/esm/shared/config.js.map +1 -1
- package/dist/esm/types.d.ts +7 -9
- 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 +4 -2
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts +0 -44
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts.map +0 -1
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js +0 -260
- package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js.map +0 -1
- package/dist/commonjs/shared/jsonConfig.d.ts +0 -35
- package/dist/commonjs/shared/jsonConfig.d.ts.map +0 -1
- package/dist/commonjs/shared/jsonConfig.js +0 -122
- package/dist/commonjs/shared/jsonConfig.js.map +0 -1
- package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts +0 -44
- package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts.map +0 -1
- package/dist/esm/a365/processors/PerRequestSpanProcessor.js +0 -256
- package/dist/esm/a365/processors/PerRequestSpanProcessor.js.map +0 -1
- package/dist/esm/shared/jsonConfig.d.ts +0 -35
- package/dist/esm/shared/jsonConfig.d.ts.map +0 -1
- package/dist/esm/shared/jsonConfig.js +0 -115
- package/dist/esm/shared/jsonConfig.js.map +0 -1
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Context, Span } from "@opentelemetry/api";
|
|
2
|
-
import type { ReadableSpan, SpanProcessor, SpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
3
|
-
/**
|
|
4
|
-
* Configuration options for the PerRequestSpanProcessor.
|
|
5
|
-
*/
|
|
6
|
-
export interface PerRequestSpanProcessorOptions {
|
|
7
|
-
maxBufferedTraces?: number;
|
|
8
|
-
maxSpansPerTrace?: number;
|
|
9
|
-
maxConcurrentExports?: number;
|
|
10
|
-
flushGraceMs?: number;
|
|
11
|
-
maxTraceAgeMs?: number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Buffers spans per trace and exports them together once the trace completes.
|
|
15
|
-
*
|
|
16
|
-
* This processor supports per-request token resolution by exporting under
|
|
17
|
-
* the original request Context so that getExportToken() can read the token
|
|
18
|
-
* from the active OpenTelemetry Context at export time.
|
|
19
|
-
*/
|
|
20
|
-
export declare class PerRequestSpanProcessor implements SpanProcessor {
|
|
21
|
-
private readonly exporter;
|
|
22
|
-
private traces;
|
|
23
|
-
private sweepTimer?;
|
|
24
|
-
private isSweeping;
|
|
25
|
-
private readonly maxBufferedTraces;
|
|
26
|
-
private readonly maxSpansPerTrace;
|
|
27
|
-
private readonly maxConcurrentExports;
|
|
28
|
-
private readonly flushGraceMs;
|
|
29
|
-
private readonly maxTraceAgeMs;
|
|
30
|
-
private inFlightExports;
|
|
31
|
-
private exportWaiters;
|
|
32
|
-
constructor(exporter: SpanExporter, options?: PerRequestSpanProcessorOptions);
|
|
33
|
-
onStart(span: Span, ctx: Context): void;
|
|
34
|
-
onEnd(span: ReadableSpan): void;
|
|
35
|
-
forceFlush(): Promise<void>;
|
|
36
|
-
shutdown(): Promise<void>;
|
|
37
|
-
private ensureSweepTimer;
|
|
38
|
-
private stopSweepTimerIfIdle;
|
|
39
|
-
private sweep;
|
|
40
|
-
private flushTrace;
|
|
41
|
-
private acquireExportSlot;
|
|
42
|
-
private releaseExportSlot;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=PerRequestSpanProcessor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PerRequestSpanProcessor.d.ts","sourceRoot":"","sources":["../../../../src/a365/processors/PerRequestSpanProcessor.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AA+B/F;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAeD;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAezD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAd3B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,UAAU,CAAC,CAAiC;IACpD,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAEvC,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,aAAa,CAAyB;gBAG3B,QAAQ,EAAE,YAAY,EACvC,OAAO,CAAC,EAAE,8BAA8B;IAwB1C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IA0CvC,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAwCzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,oBAAoB;YAOd,KAAK;YAkCL,UAAU;YA8DV,iBAAiB;IAe/B,OAAO,CAAC,iBAAiB;CAM1B"}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
/**
|
|
4
|
-
* Buffers spans per trace and exports once the request completes.
|
|
5
|
-
* Token is not stored; we export under the saved request Context so that
|
|
6
|
-
* getExportToken() can read the token from the active OpenTelemetry Context at export time.
|
|
7
|
-
*
|
|
8
|
-
* Adapted from microsoft/Agent365-nodejs agents-a365-observability/src/tracing/PerRequestSpanProcessor.ts
|
|
9
|
-
*/
|
|
10
|
-
import { context, trace } from "@opentelemetry/api";
|
|
11
|
-
import { Logger } from "../../shared/logging/index.js";
|
|
12
|
-
const logger = Logger.getInstance();
|
|
13
|
-
function isRootSpan(span) {
|
|
14
|
-
return !span.parentSpanContext;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Check whether this span is a root span by examining the parent context.
|
|
18
|
-
* In onStart, the SDK passes a live Span (not ReadableSpan), so we check
|
|
19
|
-
* whether the parent context already contains a span.
|
|
20
|
-
*/
|
|
21
|
-
function isRootSpanFromContext(ctx) {
|
|
22
|
-
const parentSpan = trace.getSpan(ctx);
|
|
23
|
-
return !parentSpan;
|
|
24
|
-
}
|
|
25
|
-
// Default values
|
|
26
|
-
const DEFAULT_MAX_BUFFERED_TRACES = 1000;
|
|
27
|
-
const DEFAULT_MAX_SPANS_PER_TRACE = 5000;
|
|
28
|
-
const DEFAULT_MAX_CONCURRENT_EXPORTS = 20;
|
|
29
|
-
const DEFAULT_FLUSH_GRACE_MS = 250;
|
|
30
|
-
const DEFAULT_MAX_TRACE_AGE_MS = 1800000; // 30 minutes
|
|
31
|
-
function parseEnvInt(envVar, defaultValue) {
|
|
32
|
-
if (envVar === undefined || envVar === "")
|
|
33
|
-
return defaultValue;
|
|
34
|
-
const parsed = parseInt(envVar, 10);
|
|
35
|
-
return Number.isNaN(parsed) ? defaultValue : parsed;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Buffers spans per trace and exports them together once the trace completes.
|
|
39
|
-
*
|
|
40
|
-
* This processor supports per-request token resolution by exporting under
|
|
41
|
-
* the original request Context so that getExportToken() can read the token
|
|
42
|
-
* from the active OpenTelemetry Context at export time.
|
|
43
|
-
*/
|
|
44
|
-
export class PerRequestSpanProcessor {
|
|
45
|
-
exporter;
|
|
46
|
-
traces = new Map();
|
|
47
|
-
sweepTimer;
|
|
48
|
-
isSweeping = false;
|
|
49
|
-
maxBufferedTraces;
|
|
50
|
-
maxSpansPerTrace;
|
|
51
|
-
maxConcurrentExports;
|
|
52
|
-
flushGraceMs;
|
|
53
|
-
maxTraceAgeMs;
|
|
54
|
-
inFlightExports = 0;
|
|
55
|
-
exportWaiters = [];
|
|
56
|
-
constructor(exporter, options) {
|
|
57
|
-
this.exporter = exporter;
|
|
58
|
-
this.maxBufferedTraces = parseEnvInt(process.env.A365_PER_REQUEST_MAX_TRACES, options?.maxBufferedTraces ?? DEFAULT_MAX_BUFFERED_TRACES);
|
|
59
|
-
this.maxSpansPerTrace = parseEnvInt(process.env.A365_PER_REQUEST_MAX_SPANS_PER_TRACE, options?.maxSpansPerTrace ?? DEFAULT_MAX_SPANS_PER_TRACE);
|
|
60
|
-
this.maxConcurrentExports = parseEnvInt(process.env.A365_PER_REQUEST_MAX_CONCURRENT_EXPORTS, options?.maxConcurrentExports ?? DEFAULT_MAX_CONCURRENT_EXPORTS);
|
|
61
|
-
this.flushGraceMs = parseEnvInt(process.env.A365_PER_REQUEST_FLUSH_GRACE_MS, options?.flushGraceMs ?? DEFAULT_FLUSH_GRACE_MS);
|
|
62
|
-
this.maxTraceAgeMs = parseEnvInt(process.env.A365_PER_REQUEST_MAX_TRACE_AGE_MS, options?.maxTraceAgeMs ?? DEFAULT_MAX_TRACE_AGE_MS);
|
|
63
|
-
}
|
|
64
|
-
onStart(span, ctx) {
|
|
65
|
-
const traceId = span.spanContext().traceId;
|
|
66
|
-
let buf = this.traces.get(traceId);
|
|
67
|
-
if (!buf) {
|
|
68
|
-
if (this.traces.size >= this.maxBufferedTraces) {
|
|
69
|
-
logger.warn(`[PerRequestSpanProcessor] Dropping new trace due to maxBufferedTraces=${this.maxBufferedTraces} traceId=${traceId}`);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
buf = {
|
|
73
|
-
spans: [],
|
|
74
|
-
openCount: 0,
|
|
75
|
-
rootEnded: false,
|
|
76
|
-
rootCtx: undefined,
|
|
77
|
-
startedAtMs: Date.now(),
|
|
78
|
-
droppedSpans: 0,
|
|
79
|
-
};
|
|
80
|
-
this.traces.set(traceId, buf);
|
|
81
|
-
this.ensureSweepTimer();
|
|
82
|
-
logger.debug(`[PerRequestSpanProcessor] Trace started traceId=${traceId} maxTraceAgeMs=${this.maxTraceAgeMs}`);
|
|
83
|
-
}
|
|
84
|
-
buf.openCount += 1;
|
|
85
|
-
const root = isRootSpanFromContext(ctx);
|
|
86
|
-
logger.debug(`[PerRequestSpanProcessor] Span start traceId=${traceId} spanId=${span.spanContext().spanId}` +
|
|
87
|
-
` root=${root} openCount=${buf.openCount}`);
|
|
88
|
-
// Capture a context to export under.
|
|
89
|
-
if (root) {
|
|
90
|
-
buf.rootCtx = ctx;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
buf.rootCtx ??= ctx;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
onEnd(span) {
|
|
97
|
-
const traceId = span.spanContext().traceId;
|
|
98
|
-
const buf = this.traces.get(traceId);
|
|
99
|
-
if (!buf)
|
|
100
|
-
return;
|
|
101
|
-
if (buf.spans.length >= this.maxSpansPerTrace) {
|
|
102
|
-
buf.droppedSpans += 1;
|
|
103
|
-
if (buf.droppedSpans === 1 || buf.droppedSpans % 100 === 0) {
|
|
104
|
-
logger.warn(`[PerRequestSpanProcessor] Dropping ended span due to maxSpansPerTrace=${this.maxSpansPerTrace} ` +
|
|
105
|
-
`traceId=${traceId} droppedSpans=${buf.droppedSpans}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
buf.spans.push(span);
|
|
110
|
-
}
|
|
111
|
-
buf.openCount -= 1;
|
|
112
|
-
if (buf.openCount < 0) {
|
|
113
|
-
logger.warn(`[PerRequestSpanProcessor] openCount underflow traceId=${traceId} spanId=${span.spanContext().spanId} resettingToZero`);
|
|
114
|
-
buf.openCount = 0;
|
|
115
|
-
}
|
|
116
|
-
logger.debug(`[PerRequestSpanProcessor] Span end name=${span.name} traceId=${traceId} spanId=${span.spanContext().spanId}` +
|
|
117
|
-
` root=${isRootSpan(span)} openCount=${buf.openCount} rootEnded=${buf.rootEnded}`);
|
|
118
|
-
if (isRootSpan(span)) {
|
|
119
|
-
buf.rootEnded = true;
|
|
120
|
-
buf.rootEndedAtMs = Date.now();
|
|
121
|
-
if (buf.openCount === 0) {
|
|
122
|
-
this.flushTrace(traceId, "trace_completed");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else if (buf.rootEnded && buf.openCount === 0) {
|
|
126
|
-
this.flushTrace(traceId, "trace_completed");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async forceFlush() {
|
|
130
|
-
await Promise.all([...this.traces.keys()].map((id) => this.flushTrace(id, "force_flush")));
|
|
131
|
-
}
|
|
132
|
-
async shutdown() {
|
|
133
|
-
await this.forceFlush();
|
|
134
|
-
this.stopSweepTimerIfIdle();
|
|
135
|
-
await this.exporter.shutdown?.();
|
|
136
|
-
}
|
|
137
|
-
ensureSweepTimer() {
|
|
138
|
-
if (this.sweepTimer)
|
|
139
|
-
return;
|
|
140
|
-
const intervalMs = Math.max(10, Math.min(this.flushGraceMs, 250));
|
|
141
|
-
this.sweepTimer = setInterval(() => {
|
|
142
|
-
void this.sweep();
|
|
143
|
-
}, intervalMs);
|
|
144
|
-
if (typeof this.sweepTimer === "object" && "unref" in this.sweepTimer) {
|
|
145
|
-
this.sweepTimer.unref();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
stopSweepTimerIfIdle() {
|
|
149
|
-
if (this.traces.size !== 0)
|
|
150
|
-
return;
|
|
151
|
-
if (!this.sweepTimer)
|
|
152
|
-
return;
|
|
153
|
-
clearInterval(this.sweepTimer);
|
|
154
|
-
this.sweepTimer = undefined;
|
|
155
|
-
}
|
|
156
|
-
async sweep() {
|
|
157
|
-
if (this.isSweeping)
|
|
158
|
-
return;
|
|
159
|
-
this.isSweeping = true;
|
|
160
|
-
try {
|
|
161
|
-
if (this.traces.size === 0) {
|
|
162
|
-
this.stopSweepTimerIfIdle();
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const now = Date.now();
|
|
166
|
-
const toFlush = [];
|
|
167
|
-
for (const [traceId, trace] of this.traces.entries()) {
|
|
168
|
-
// 1) Max age safety flush
|
|
169
|
-
if (now - trace.startedAtMs >= this.maxTraceAgeMs) {
|
|
170
|
-
toFlush.push({ traceId, reason: "max_trace_age" });
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
// 2) Root ended grace window flush
|
|
174
|
-
if (trace.rootEnded && trace.openCount > 0 && trace.rootEndedAtMs) {
|
|
175
|
-
if (now - trace.rootEndedAtMs >= this.flushGraceMs) {
|
|
176
|
-
toFlush.push({ traceId, reason: "root_ended_grace" });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
await Promise.all(toFlush.map((x) => this.flushTrace(x.traceId, x.reason)));
|
|
181
|
-
this.stopSweepTimerIfIdle();
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
this.isSweeping = false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async flushTrace(traceId, reason) {
|
|
188
|
-
const trace = this.traces.get(traceId);
|
|
189
|
-
if (!trace)
|
|
190
|
-
return;
|
|
191
|
-
this.traces.delete(traceId);
|
|
192
|
-
this.stopSweepTimerIfIdle();
|
|
193
|
-
const spans = trace.spans;
|
|
194
|
-
if (spans.length === 0)
|
|
195
|
-
return;
|
|
196
|
-
logger.debug(`[PerRequestSpanProcessor] Flushing trace traceId=${traceId} reason=${reason} spans=${spans.length} rootEnded=${trace.rootEnded}`);
|
|
197
|
-
if (!trace.rootCtx) {
|
|
198
|
-
logger.error(`[PerRequestSpanProcessor] Missing rootCtx for trace ${traceId}, cannot export spans`);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
await this.acquireExportSlot();
|
|
202
|
-
try {
|
|
203
|
-
await new Promise((resolve) => {
|
|
204
|
-
try {
|
|
205
|
-
context.with(trace.rootCtx, () => {
|
|
206
|
-
try {
|
|
207
|
-
this.exporter.export(spans, (result) => {
|
|
208
|
-
if (result.code !== 0) {
|
|
209
|
-
logger.error(`[PerRequestSpanProcessor] Export failed traceId=${traceId} reason=${reason} code=${result.code}`, result.error);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
logger.debug(`[PerRequestSpanProcessor] Export succeeded traceId=${traceId} reason=${reason} spans=${spans.length}`);
|
|
213
|
-
}
|
|
214
|
-
resolve();
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
catch (err) {
|
|
218
|
-
logger.error(`[PerRequestSpanProcessor] Export threw traceId=${traceId} reason=${reason} spans=${spans.length}`, err);
|
|
219
|
-
resolve();
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
catch (err) {
|
|
224
|
-
logger.error(`[PerRequestSpanProcessor] context.with threw traceId=${traceId} reason=${reason}`, err);
|
|
225
|
-
resolve();
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
finally {
|
|
230
|
-
this.releaseExportSlot();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async acquireExportSlot() {
|
|
234
|
-
if (this.maxConcurrentExports <= 0)
|
|
235
|
-
return;
|
|
236
|
-
if (this.inFlightExports < this.maxConcurrentExports) {
|
|
237
|
-
this.inFlightExports += 1;
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
await new Promise((resolve) => {
|
|
241
|
-
this.exportWaiters.push(() => {
|
|
242
|
-
this.inFlightExports += 1;
|
|
243
|
-
resolve();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
releaseExportSlot() {
|
|
248
|
-
if (this.maxConcurrentExports <= 0)
|
|
249
|
-
return;
|
|
250
|
-
this.inFlightExports = Math.max(0, this.inFlightExports - 1);
|
|
251
|
-
const next = this.exportWaiters.shift();
|
|
252
|
-
if (next)
|
|
253
|
-
next();
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
//# sourceMappingURL=PerRequestSpanProcessor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PerRequestSpanProcessor.js","sourceRoot":"","sources":["../../../../src/a365/processors/PerRequestSpanProcessor.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAEvD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;AAEpC,SAAS,UAAU,CAAC,IAA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ACV,wDAAwD,OAAO,WAAW,MAAM,EAAE,EAClF,GAAG,CACJ,CAAC;oBACF,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,IAAI,IAAI,CAAC,oBAAoB,IAAI,CAAC;YAAE,OAAO;QAC3C,IAAI,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACrD,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC3B,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;gBAC1B,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,oBAAoB,IAAI,CAAC;YAAE,OAAO;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QACxC,IAAI,IAAI;YAAE,IAAI,EAAE,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from "../types.js";
|
|
2
|
-
import type { A365Options } from "../a365/index.js";
|
|
3
|
-
import type { MicrosoftOpenTelemetryOptions } from "../types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Azure Monitor OpenTelemetry Client Configuration through JSON File.
|
|
6
|
-
*
|
|
7
|
-
* Implements {@link MicrosoftOpenTelemetryOptions}.
|
|
8
|
-
* Azure Monitor-specific fields are grouped under `azureMonitor`.
|
|
9
|
-
* The JSON file format remains flat for backward compatibility; the constructor
|
|
10
|
-
* maps the flat structure to the nested shape.
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export declare class JsonConfig implements MicrosoftOpenTelemetryOptions {
|
|
14
|
-
/** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
|
|
15
|
-
samplingRatio?: number;
|
|
16
|
-
/** The maximum number of spans to sample per second. */
|
|
17
|
-
tracesPerSecond?: number;
|
|
18
|
-
/**
|
|
19
|
-
* OpenTelemetry Instrumentations configuration included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)
|
|
20
|
-
*/
|
|
21
|
-
instrumentationOptions?: InstrumentationOptions;
|
|
22
|
-
/** Azure Monitor scoped options */
|
|
23
|
-
azureMonitor?: AzureMonitorOpenTelemetryOptions;
|
|
24
|
-
/** A365 scoped options */
|
|
25
|
-
a365?: A365Options;
|
|
26
|
-
private static _instance;
|
|
27
|
-
private _tempDir;
|
|
28
|
-
/** Get Singleton instance */
|
|
29
|
-
static getInstance(): JsonConfig;
|
|
30
|
-
/**
|
|
31
|
-
* Initializes a new instance of the JsonConfig class.
|
|
32
|
-
*/
|
|
33
|
-
constructor();
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=jsonConfig.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonConfig.d.ts","sourceRoot":"","sources":["../../../src/shared/jsonConfig.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAEhC,sBAAsB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AA2BjE;;;;;;;;GAQG;AACH,qBAAa,UAAW,YAAW,6BAA6B;IAC9D,mFAAmF;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;IAC9B,wDAAwD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IAChC;;OAEG;IACI,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IACvD,mCAAmC;IAC5B,YAAY,CAAC,EAAE,gCAAgC,CAAC;IACvD,0BAA0B;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IAE1B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAa;IAErC,OAAO,CAAC,QAAQ,CAAS;IAEzB,6BAA6B;WACf,WAAW,IAAI,UAAU;IAOvC;;OAEG;;CA0DJ"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { Logger } from "./logging/index.js";
|
|
6
|
-
import { dirName } from "./module.js";
|
|
7
|
-
/**
|
|
8
|
-
* Walk up from a starting directory until a directory containing package.json is found.
|
|
9
|
-
* Falls back to the starting directory if no package.json is located.
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
function findPackageRoot(startDir) {
|
|
13
|
-
let current = path.resolve(startDir);
|
|
14
|
-
while (true) {
|
|
15
|
-
if (fs.existsSync(path.join(current, "package.json"))) {
|
|
16
|
-
return current;
|
|
17
|
-
}
|
|
18
|
-
const parent = path.dirname(current);
|
|
19
|
-
if (parent === current) {
|
|
20
|
-
// Reached filesystem root without finding package.json
|
|
21
|
-
return startDir;
|
|
22
|
-
}
|
|
23
|
-
current = parent;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const ENV_CONFIGURATION_FILE = "APPLICATIONINSIGHTS_CONFIGURATION_FILE";
|
|
27
|
-
const ENV_CONTENT = "APPLICATIONINSIGHTS_CONFIGURATION_CONTENT";
|
|
28
|
-
/**
|
|
29
|
-
* Azure Monitor OpenTelemetry Client Configuration through JSON File.
|
|
30
|
-
*
|
|
31
|
-
* Implements {@link MicrosoftOpenTelemetryOptions}.
|
|
32
|
-
* Azure Monitor-specific fields are grouped under `azureMonitor`.
|
|
33
|
-
* The JSON file format remains flat for backward compatibility; the constructor
|
|
34
|
-
* maps the flat structure to the nested shape.
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export class JsonConfig {
|
|
38
|
-
/** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
|
|
39
|
-
samplingRatio;
|
|
40
|
-
/** The maximum number of spans to sample per second. */
|
|
41
|
-
tracesPerSecond;
|
|
42
|
-
/**
|
|
43
|
-
* OpenTelemetry Instrumentations configuration included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)
|
|
44
|
-
*/
|
|
45
|
-
instrumentationOptions;
|
|
46
|
-
/** Azure Monitor scoped options */
|
|
47
|
-
azureMonitor;
|
|
48
|
-
/** A365 scoped options */
|
|
49
|
-
a365;
|
|
50
|
-
static _instance;
|
|
51
|
-
_tempDir;
|
|
52
|
-
/** Get Singleton instance */
|
|
53
|
-
static getInstance() {
|
|
54
|
-
if (!JsonConfig._instance) {
|
|
55
|
-
JsonConfig._instance = new JsonConfig();
|
|
56
|
-
}
|
|
57
|
-
return JsonConfig._instance;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Initializes a new instance of the JsonConfig class.
|
|
61
|
-
*/
|
|
62
|
-
constructor() {
|
|
63
|
-
let jsonString = "";
|
|
64
|
-
this._tempDir = "";
|
|
65
|
-
const contentJsonConfig = process.env[ENV_CONTENT];
|
|
66
|
-
// JSON string added directly in env variable
|
|
67
|
-
if (contentJsonConfig) {
|
|
68
|
-
jsonString = contentJsonConfig;
|
|
69
|
-
}
|
|
70
|
-
// JSON file
|
|
71
|
-
else {
|
|
72
|
-
const configFileName = "applicationinsights.json";
|
|
73
|
-
const rootPath = findPackageRoot(dirName());
|
|
74
|
-
this._tempDir = path.join(rootPath, configFileName); // default
|
|
75
|
-
const configFile = process.env[ENV_CONFIGURATION_FILE];
|
|
76
|
-
if (configFile) {
|
|
77
|
-
if (path.isAbsolute(configFile)) {
|
|
78
|
-
this._tempDir = configFile;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this._tempDir = path.join(rootPath, configFile); // Relative path to applicationinsights folder
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
jsonString = fs.readFileSync(this._tempDir, "utf8");
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
Logger.getInstance().info("Failed to read JSON config file: ", err);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
const jsonConfig = JSON.parse(jsonString);
|
|
93
|
-
// Global options
|
|
94
|
-
this.samplingRatio = jsonConfig.samplingRatio;
|
|
95
|
-
this.tracesPerSecond = jsonConfig.tracesPerSecond;
|
|
96
|
-
this.instrumentationOptions = jsonConfig.instrumentationOptions;
|
|
97
|
-
// Azure Monitor-scoped options (flat JSON → nested structure)
|
|
98
|
-
this.azureMonitor = {
|
|
99
|
-
azureMonitorExporterOptions: jsonConfig.azureMonitorExporterOptions,
|
|
100
|
-
browserSdkLoaderOptions: jsonConfig.browserSdkLoaderOptions,
|
|
101
|
-
enableLiveMetrics: jsonConfig.enableLiveMetrics,
|
|
102
|
-
enableStandardMetrics: jsonConfig.enableStandardMetrics,
|
|
103
|
-
enableTraceBasedSamplingForLogs: jsonConfig.enableTraceBasedSamplingForLogs,
|
|
104
|
-
};
|
|
105
|
-
// A365-scoped options
|
|
106
|
-
if (jsonConfig.a365 && typeof jsonConfig.a365 === "object") {
|
|
107
|
-
this.a365 = jsonConfig.a365;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
Logger.getInstance().info("Missing or invalid JSON config file: ", err);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingUR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