@azure/monitor-opentelemetry-exporter 1.0.0-beta.32 → 1.0.0-beta.33
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/Declarations/Constants.d.ts +5 -0
- package/dist/commonjs/Declarations/Constants.d.ts.map +1 -1
- package/dist/commonjs/Declarations/Constants.js +6 -1
- package/dist/commonjs/Declarations/Constants.js.map +1 -1
- package/dist/commonjs/export/base.js +25 -14
- package/dist/commonjs/export/base.js.map +1 -1
- package/dist/commonjs/export/log.js +5 -4
- package/dist/commonjs/export/log.js.map +1 -1
- package/dist/commonjs/export/metric.js +5 -4
- package/dist/commonjs/export/metric.js.map +1 -1
- package/dist/commonjs/export/statsbeat/customerStatsbeat.d.ts +125 -0
- package/dist/commonjs/export/statsbeat/customerStatsbeat.d.ts.map +1 -0
- package/dist/commonjs/export/statsbeat/customerStatsbeat.js +480 -0
- package/dist/commonjs/export/statsbeat/customerStatsbeat.js.map +1 -0
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js +35 -11
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js +52 -21
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatExporter.d.ts +7 -0
- package/dist/commonjs/export/statsbeat/statsbeatExporter.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatExporter.js +25 -5
- package/dist/commonjs/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatMetrics.js +6 -8
- package/dist/commonjs/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/types.d.ts +52 -0
- package/dist/commonjs/export/statsbeat/types.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/types.js +75 -1
- package/dist/commonjs/export/statsbeat/types.js.map +1 -1
- package/dist/commonjs/export/trace.js +6 -5
- package/dist/commonjs/export/trace.js.map +1 -1
- package/dist/commonjs/generated/applicationInsightsClient.js +9 -4
- package/dist/commonjs/generated/applicationInsightsClient.js.map +1 -1
- package/dist/commonjs/generated/models/mappers.js +145 -68
- package/dist/commonjs/generated/models/mappers.js.map +1 -1
- package/dist/commonjs/index.d.ts +2 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +5 -3
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/platform/nodejs/baseSender.d.ts +1 -0
- package/dist/commonjs/platform/nodejs/baseSender.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/baseSender.js +74 -28
- package/dist/commonjs/platform/nodejs/baseSender.js.map +1 -1
- package/dist/commonjs/platform/nodejs/context/context.d.ts +0 -1
- package/dist/commonjs/platform/nodejs/context/context.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/context/context.js +4 -8
- package/dist/commonjs/platform/nodejs/context/context.js.map +1 -1
- package/dist/commonjs/platform/nodejs/httpSender.js +11 -4
- package/dist/commonjs/platform/nodejs/httpSender.js.map +1 -1
- package/dist/commonjs/platform/nodejs/index.d.ts +1 -0
- package/dist/commonjs/platform/nodejs/index.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/index.js +1 -0
- package/dist/commonjs/platform/nodejs/index.js.map +1 -1
- package/dist/commonjs/platform/nodejs/persist/fileAccessControl.js +7 -7
- package/dist/commonjs/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.d.ts +9 -1
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.d.ts.map +1 -1
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.js +37 -16
- package/dist/commonjs/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist/commonjs/{sampling.d.ts → sampling/percentageSampler.d.ts} +2 -3
- package/dist/commonjs/sampling/percentageSampler.d.ts.map +1 -0
- package/dist/commonjs/{sampling.js → sampling/percentageSampler.js} +6 -39
- package/dist/commonjs/sampling/percentageSampler.js.map +1 -0
- package/dist/commonjs/sampling/rateLimitedSampler.d.ts +58 -0
- package/dist/commonjs/sampling/rateLimitedSampler.d.ts.map +1 -0
- package/dist/commonjs/sampling/rateLimitedSampler.js +118 -0
- package/dist/commonjs/sampling/rateLimitedSampler.js.map +1 -0
- package/dist/commonjs/sampling/samplingUtils.d.ts +17 -0
- package/dist/commonjs/sampling/samplingUtils.d.ts.map +1 -0
- package/dist/commonjs/sampling/samplingUtils.js +94 -0
- package/dist/commonjs/sampling/samplingUtils.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/utils/common.js +2 -3
- package/dist/commonjs/utils/common.js.map +1 -1
- package/dist/commonjs/utils/connectionStringParser.js +3 -3
- package/dist/commonjs/utils/connectionStringParser.js.map +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.d.ts +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.js +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.js.map +1 -1
- package/dist/commonjs/utils/eventhub.js +5 -2
- package/dist/commonjs/utils/eventhub.js.map +1 -1
- package/dist/commonjs/utils/logUtils.js +10 -9
- package/dist/commonjs/utils/logUtils.js.map +1 -1
- package/dist/commonjs/utils/metricUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/metricUtils.js +6 -6
- package/dist/commonjs/utils/metricUtils.js.map +1 -1
- package/dist/commonjs/utils/spanUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/spanUtils.js +13 -11
- package/dist/commonjs/utils/spanUtils.js.map +1 -1
- package/dist/esm/Declarations/Constants.d.ts +5 -0
- package/dist/esm/Declarations/Constants.d.ts.map +1 -1
- package/dist/esm/Declarations/Constants.js +5 -0
- package/dist/esm/Declarations/Constants.js.map +1 -1
- package/dist/esm/export/base.js +25 -14
- package/dist/esm/export/base.js.map +1 -1
- package/dist/esm/export/log.js +5 -4
- package/dist/esm/export/log.js.map +1 -1
- package/dist/esm/export/metric.js +5 -4
- package/dist/esm/export/metric.js.map +1 -1
- package/dist/esm/export/statsbeat/customerStatsbeat.d.ts +125 -0
- package/dist/esm/export/statsbeat/customerStatsbeat.d.ts.map +1 -0
- package/dist/esm/export/statsbeat/customerStatsbeat.js +475 -0
- package/dist/esm/export/statsbeat/customerStatsbeat.js.map +1 -0
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js +35 -11
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js +52 -21
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatExporter.d.ts +7 -0
- package/dist/esm/export/statsbeat/statsbeatExporter.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatExporter.js +25 -5
- package/dist/esm/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatMetrics.js +6 -8
- package/dist/esm/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/types.d.ts +52 -0
- package/dist/esm/export/statsbeat/types.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/types.js +73 -0
- package/dist/esm/export/statsbeat/types.js.map +1 -1
- package/dist/esm/export/trace.js +6 -5
- package/dist/esm/export/trace.js.map +1 -1
- package/dist/esm/generated/applicationInsightsClient.js +9 -4
- package/dist/esm/generated/applicationInsightsClient.js.map +1 -1
- package/dist/esm/generated/models/mappers.js +145 -68
- package/dist/esm/generated/models/mappers.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- 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/platform/nodejs/baseSender.d.ts +1 -0
- package/dist/esm/platform/nodejs/baseSender.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/baseSender.js +76 -30
- package/dist/esm/platform/nodejs/baseSender.js.map +1 -1
- package/dist/esm/platform/nodejs/context/context.d.ts +0 -1
- package/dist/esm/platform/nodejs/context/context.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/context/context.js +4 -8
- package/dist/esm/platform/nodejs/context/context.js.map +1 -1
- package/dist/esm/platform/nodejs/httpSender.js +11 -4
- package/dist/esm/platform/nodejs/httpSender.js.map +1 -1
- package/dist/esm/platform/nodejs/index.d.ts +1 -0
- package/dist/esm/platform/nodejs/index.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/index.js +1 -0
- package/dist/esm/platform/nodejs/index.js.map +1 -1
- package/dist/esm/platform/nodejs/persist/fileAccessControl.js +7 -7
- package/dist/esm/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.d.ts +9 -1
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.d.ts.map +1 -1
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.js +37 -16
- package/dist/esm/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist/esm/{sampling.d.ts → sampling/percentageSampler.d.ts} +2 -3
- package/dist/esm/sampling/percentageSampler.d.ts.map +1 -0
- package/dist/esm/{sampling.js → sampling/percentageSampler.js} +6 -39
- package/dist/esm/sampling/percentageSampler.js.map +1 -0
- package/dist/esm/sampling/rateLimitedSampler.d.ts +58 -0
- package/dist/esm/sampling/rateLimitedSampler.d.ts.map +1 -0
- package/dist/esm/sampling/rateLimitedSampler.js +114 -0
- package/dist/esm/sampling/rateLimitedSampler.js.map +1 -0
- package/dist/esm/sampling/samplingUtils.d.ts +17 -0
- package/dist/esm/sampling/samplingUtils.d.ts.map +1 -0
- package/dist/esm/sampling/samplingUtils.js +89 -0
- package/dist/esm/sampling/samplingUtils.js.map +1 -0
- package/dist/esm/utils/common.js +2 -3
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/connectionStringParser.js +3 -3
- package/dist/esm/utils/connectionStringParser.js.map +1 -1
- package/dist/esm/utils/constants/applicationinsights.d.ts +1 -1
- package/dist/esm/utils/constants/applicationinsights.js +1 -1
- package/dist/esm/utils/constants/applicationinsights.js.map +1 -1
- package/dist/esm/utils/eventhub.js +5 -2
- package/dist/esm/utils/eventhub.js.map +1 -1
- package/dist/esm/utils/logUtils.js +10 -9
- package/dist/esm/utils/logUtils.js.map +1 -1
- package/dist/esm/utils/metricUtils.d.ts.map +1 -1
- package/dist/esm/utils/metricUtils.js +6 -6
- package/dist/esm/utils/metricUtils.js.map +1 -1
- package/dist/esm/utils/spanUtils.d.ts.map +1 -1
- package/dist/esm/utils/spanUtils.js +13 -11
- package/dist/esm/utils/spanUtils.js.map +1 -1
- package/package.json +6 -6
- package/dist/commonjs/sampling.d.ts.map +0 -1
- package/dist/commonjs/sampling.js.map +0 -1
- package/dist/esm/sampling.d.ts.map +0 -1
- package/dist/esm/sampling.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Link, Attributes, SpanKind, Context } from "@opentelemetry/api";
|
|
2
|
+
import type { Sampler, SamplingResult } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
/**
|
|
4
|
+
* RateLimitedSampler is responsible for the following:
|
|
5
|
+
* - Implements a rate-limiting sampling strategy based on a specified number of requests per second.
|
|
6
|
+
* - Dynamically adjusts the sampling rate based on the time elapsed since the last sample.
|
|
7
|
+
* - Provides a sampling rate that can be used to determine whether a span should be recorded.
|
|
8
|
+
* @param requestsPerSecond -
|
|
9
|
+
*/
|
|
10
|
+
export declare class RateLimitedSampler implements Sampler {
|
|
11
|
+
private readonly nanoTimeSupplier;
|
|
12
|
+
private readonly inverseAdaptationTimeNanos;
|
|
13
|
+
private readonly targetSpansPerNanosecondLimit;
|
|
14
|
+
private state;
|
|
15
|
+
private readonly roundToNearest;
|
|
16
|
+
private readonly tracesPerSecond;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a new instance of the RateLimitedSampler class.
|
|
19
|
+
* @param tracesPerSecond - The maximum number of traces to sample per second.
|
|
20
|
+
* @throws Error if tracesPerSecond is negative.
|
|
21
|
+
*/
|
|
22
|
+
constructor(tracesPerSecond: number);
|
|
23
|
+
/**
|
|
24
|
+
* Updates the state of the sampler based on the current time.
|
|
25
|
+
* This method calculates the effective window count and nanos based on the time elapsed since the last sample.
|
|
26
|
+
* @param oldState - The previous state of the sampler.
|
|
27
|
+
* @param currentNanoTime - The current time in nanoseconds.
|
|
28
|
+
* @returns The updated state of the sampler.
|
|
29
|
+
*/
|
|
30
|
+
private updateState;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the current sample rate based on the effective window count and nanos.
|
|
33
|
+
* This method calculates the sampling probability and returns it as a percentage.
|
|
34
|
+
* If `roundToNearest` is true, it rounds down the sampling percentage to the nearest whole number.
|
|
35
|
+
* @returns The current sample rate as a percentage.
|
|
36
|
+
*/
|
|
37
|
+
getSampleRate(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether span needs to be created and tracked.
|
|
40
|
+
*
|
|
41
|
+
* @param context - Parent Context which may contain a span.
|
|
42
|
+
* @param traceId - traceId of the span to be created. It can be different from the
|
|
43
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
44
|
+
* span to be created starts a new trace.
|
|
45
|
+
* @param spanName - Name of the span to be created.
|
|
46
|
+
* @param spanKind - Kind of the span to be created.
|
|
47
|
+
* @param attributes - Initial set of SpanAttributes for the Span being constructed.
|
|
48
|
+
* @param links - Collection of links that will be associated with the Span to
|
|
49
|
+
* be created. Typically useful for batch operations.
|
|
50
|
+
* @returns a {@link SamplingResult}.
|
|
51
|
+
*/
|
|
52
|
+
shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes, links: Link[]): SamplingResult;
|
|
53
|
+
/**
|
|
54
|
+
* Return Sampler description
|
|
55
|
+
*/
|
|
56
|
+
toString(): string;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=rateLimitedSampler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimitedSampler.d.ts","sourceRoot":"","sources":["../../../src/sampling/rateLimitedSampler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAU7E;;;;;;GAMG;AACH,qBAAa,kBAAmB,YAAW,OAAO;IAChD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAe;IAChD,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAS;IACpD,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAS;IACvD,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC;;;;OAIG;gBACS,eAAe,EAAE,MAAM;IAkBnC;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAsBnB;;;;;OAKG;IACI,aAAa,IAAI,MAAM;IAe9B;;;;;;;;;;;;;OAaG;IACI,YAAY,CACjB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EAEf,QAAQ,EAAE,MAAM,EAEhB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EAEtB,KAAK,EAAE,IAAI,EAAE,GACZ,cAAc;IAOjB;;OAEG;IACI,QAAQ,IAAI,MAAM;CAG1B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { SamplingDecision } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import { roundDownToNearest, shouldSample } from "./samplingUtils.js";
|
|
3
|
+
/**
|
|
4
|
+
* RateLimitedSampler is responsible for the following:
|
|
5
|
+
* - Implements a rate-limiting sampling strategy based on a specified number of requests per second.
|
|
6
|
+
* - Dynamically adjusts the sampling rate based on the time elapsed since the last sample.
|
|
7
|
+
* - Provides a sampling rate that can be used to determine whether a span should be recorded.
|
|
8
|
+
* @param requestsPerSecond -
|
|
9
|
+
*/
|
|
10
|
+
export class RateLimitedSampler {
|
|
11
|
+
nanoTimeSupplier;
|
|
12
|
+
inverseAdaptationTimeNanos;
|
|
13
|
+
targetSpansPerNanosecondLimit;
|
|
14
|
+
state;
|
|
15
|
+
roundToNearest;
|
|
16
|
+
tracesPerSecond;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a new instance of the RateLimitedSampler class.
|
|
19
|
+
* @param tracesPerSecond - The maximum number of traces to sample per second.
|
|
20
|
+
* @throws Error if tracesPerSecond is negative.
|
|
21
|
+
*/
|
|
22
|
+
constructor(tracesPerSecond) {
|
|
23
|
+
this.tracesPerSecond = tracesPerSecond;
|
|
24
|
+
if (this.tracesPerSecond < 0.0) {
|
|
25
|
+
throw new Error("Limit for sampled traces per second must be nonnegative");
|
|
26
|
+
}
|
|
27
|
+
const adaptationTimeSeconds = 0.1;
|
|
28
|
+
this.nanoTimeSupplier = () => Number(process.hrtime.bigint());
|
|
29
|
+
this.inverseAdaptationTimeNanos = 1e-9 / adaptationTimeSeconds;
|
|
30
|
+
this.targetSpansPerNanosecondLimit = 1e-9 * this.tracesPerSecond;
|
|
31
|
+
const now = this.nanoTimeSupplier();
|
|
32
|
+
this.state = {
|
|
33
|
+
effectiveWindowCount: 0,
|
|
34
|
+
effectiveWindowNanos: 0,
|
|
35
|
+
lastNanoTime: now,
|
|
36
|
+
};
|
|
37
|
+
this.roundToNearest = true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Updates the state of the sampler based on the current time.
|
|
41
|
+
* This method calculates the effective window count and nanos based on the time elapsed since the last sample.
|
|
42
|
+
* @param oldState - The previous state of the sampler.
|
|
43
|
+
* @param currentNanoTime - The current time in nanoseconds.
|
|
44
|
+
* @returns The updated state of the sampler.
|
|
45
|
+
*/
|
|
46
|
+
updateState(oldState, currentNanoTime) {
|
|
47
|
+
if (currentNanoTime <= oldState.lastNanoTime) {
|
|
48
|
+
return {
|
|
49
|
+
effectiveWindowCount: oldState.effectiveWindowCount + 1,
|
|
50
|
+
effectiveWindowNanos: oldState.effectiveWindowNanos,
|
|
51
|
+
lastNanoTime: oldState.lastNanoTime,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const nanoTimeDelta = currentNanoTime - oldState.lastNanoTime;
|
|
55
|
+
const decayFactor = Math.exp(-nanoTimeDelta * this.inverseAdaptationTimeNanos);
|
|
56
|
+
const currentEffectiveWindowCount = oldState.effectiveWindowCount * decayFactor + 1;
|
|
57
|
+
const currentEffectiveWindowNanos = oldState.effectiveWindowNanos * decayFactor + nanoTimeDelta;
|
|
58
|
+
return {
|
|
59
|
+
effectiveWindowCount: currentEffectiveWindowCount,
|
|
60
|
+
effectiveWindowNanos: currentEffectiveWindowNanos,
|
|
61
|
+
lastNanoTime: currentNanoTime,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets the current sample rate based on the effective window count and nanos.
|
|
66
|
+
* This method calculates the sampling probability and returns it as a percentage.
|
|
67
|
+
* If `roundToNearest` is true, it rounds down the sampling percentage to the nearest whole number.
|
|
68
|
+
* @returns The current sample rate as a percentage.
|
|
69
|
+
*/
|
|
70
|
+
getSampleRate() {
|
|
71
|
+
const currentNanoTime = this.nanoTimeSupplier();
|
|
72
|
+
this.state = this.updateState(this.state, currentNanoTime);
|
|
73
|
+
const samplingProbability = (this.state.effectiveWindowNanos * this.targetSpansPerNanosecondLimit) /
|
|
74
|
+
this.state.effectiveWindowCount;
|
|
75
|
+
let samplingPercentage = 100 * Math.min(samplingProbability, 1);
|
|
76
|
+
if (this.roundToNearest) {
|
|
77
|
+
samplingPercentage = roundDownToNearest(samplingPercentage);
|
|
78
|
+
}
|
|
79
|
+
return samplingPercentage;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks whether span needs to be created and tracked.
|
|
83
|
+
*
|
|
84
|
+
* @param context - Parent Context which may contain a span.
|
|
85
|
+
* @param traceId - traceId of the span to be created. It can be different from the
|
|
86
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
87
|
+
* span to be created starts a new trace.
|
|
88
|
+
* @param spanName - Name of the span to be created.
|
|
89
|
+
* @param spanKind - Kind of the span to be created.
|
|
90
|
+
* @param attributes - Initial set of SpanAttributes for the Span being constructed.
|
|
91
|
+
* @param links - Collection of links that will be associated with the Span to
|
|
92
|
+
* be created. Typically useful for batch operations.
|
|
93
|
+
* @returns a {@link SamplingResult}.
|
|
94
|
+
*/
|
|
95
|
+
shouldSample(context, traceId,
|
|
96
|
+
// @ts-expect-error unused argument
|
|
97
|
+
spanName,
|
|
98
|
+
// @ts-expect-error unused argument
|
|
99
|
+
spanKind, attributes,
|
|
100
|
+
// @ts-expect-error unused argument
|
|
101
|
+
links) {
|
|
102
|
+
const sampleRate = this.getSampleRate();
|
|
103
|
+
return shouldSample(sampleRate, context, traceId, attributes)
|
|
104
|
+
? { decision: SamplingDecision.RECORD_AND_SAMPLED, attributes: attributes }
|
|
105
|
+
: { decision: SamplingDecision.NOT_RECORD, attributes: attributes };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Return Sampler description
|
|
109
|
+
*/
|
|
110
|
+
toString() {
|
|
111
|
+
return `RateLimitedSampler{${this.tracesPerSecond}}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=rateLimitedSampler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimitedSampler.js","sourceRoot":"","sources":["../../../src/sampling/rateLimitedSampler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAQtE;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;I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AAE,UAAU,EAAE;YAC3E,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;IACxE,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,OAAO,sBAAsB,IAAI,CAAC,eAAe,GAAG,CAAC;IACvD,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { Link, Attributes, SpanKind, Context } from \"@opentelemetry/api\";\nimport type { Sampler, SamplingResult } from \"@opentelemetry/sdk-trace-base\";\nimport { SamplingDecision } from \"@opentelemetry/sdk-trace-base\";\nimport { roundDownToNearest, shouldSample } from \"./samplingUtils.js\";\n\ntype RateLimitedSamplerState = {\n effectiveWindowCount: number;\n effectiveWindowNanos: number;\n lastNanoTime: number;\n};\n\n/**\n * RateLimitedSampler is responsible for the following:\n * - Implements a rate-limiting sampling strategy based on a specified number of requests per second.\n * - Dynamically adjusts the sampling rate based on the time elapsed since the last sample.\n * - Provides a sampling rate that can be used to determine whether a span should be recorded.\n * @param requestsPerSecond -\n */\nexport class RateLimitedSampler implements Sampler {\n private readonly nanoTimeSupplier: () => number;\n private readonly inverseAdaptationTimeNanos: number;\n private readonly targetSpansPerNanosecondLimit: number;\n private state: RateLimitedSamplerState;\n private readonly roundToNearest: boolean;\n private readonly tracesPerSecond: number;\n\n /**\n * Initializes a new instance of the RateLimitedSampler class.\n * @param tracesPerSecond - The maximum number of traces to sample per second.\n * @throws Error if tracesPerSecond is negative.\n */\n constructor(tracesPerSecond: number) {\n this.tracesPerSecond = tracesPerSecond;\n if (this.tracesPerSecond < 0.0) {\n throw new Error(\"Limit for sampled traces per second must be nonnegative\");\n }\n const adaptationTimeSeconds = 0.1;\n this.nanoTimeSupplier = () => Number(process.hrtime.bigint());\n this.inverseAdaptationTimeNanos = 1e-9 / adaptationTimeSeconds;\n this.targetSpansPerNanosecondLimit = 1e-9 * this.tracesPerSecond;\n const now = this.nanoTimeSupplier();\n this.state = {\n effectiveWindowCount: 0,\n effectiveWindowNanos: 0,\n lastNanoTime: now,\n };\n this.roundToNearest = true;\n }\n\n /**\n * Updates the state of the sampler based on the current time.\n * This method calculates the effective window count and nanos based on the time elapsed since the last sample.\n * @param oldState - The previous state of the sampler.\n * @param currentNanoTime - The current time in nanoseconds.\n * @returns The updated state of the sampler.\n */\n private updateState(\n oldState: RateLimitedSamplerState,\n currentNanoTime: number,\n ): RateLimitedSamplerState {\n if (currentNanoTime <= oldState.lastNanoTime) {\n return {\n effectiveWindowCount: oldState.effectiveWindowCount + 1,\n effectiveWindowNanos: oldState.effectiveWindowNanos,\n lastNanoTime: oldState.lastNanoTime,\n };\n }\n const nanoTimeDelta = currentNanoTime - oldState.lastNanoTime;\n const decayFactor = Math.exp(-nanoTimeDelta * this.inverseAdaptationTimeNanos);\n const currentEffectiveWindowCount = oldState.effectiveWindowCount * decayFactor + 1;\n const currentEffectiveWindowNanos = oldState.effectiveWindowNanos * decayFactor + nanoTimeDelta;\n return {\n effectiveWindowCount: currentEffectiveWindowCount,\n effectiveWindowNanos: currentEffectiveWindowNanos,\n lastNanoTime: currentNanoTime,\n };\n }\n\n /**\n * Gets the current sample rate based on the effective window count and nanos.\n * This method calculates the sampling probability and returns it as a percentage.\n * If `roundToNearest` is true, it rounds down the sampling percentage to the nearest whole number.\n * @returns The current sample rate as a percentage.\n */\n public getSampleRate(): number {\n const currentNanoTime = this.nanoTimeSupplier();\n this.state = this.updateState(this.state, currentNanoTime);\n\n const samplingProbability =\n (this.state.effectiveWindowNanos * this.targetSpansPerNanosecondLimit) /\n this.state.effectiveWindowCount;\n let samplingPercentage = 100 * Math.min(samplingProbability, 1);\n\n if (this.roundToNearest) {\n samplingPercentage = roundDownToNearest(samplingPercentage);\n }\n return samplingPercentage;\n }\n\n /**\n * Checks whether span needs to be created and tracked.\n *\n * @param context - Parent Context which may contain a span.\n * @param traceId - traceId of the span to be created. It can be different from the\n * traceId in the {@link SpanContext}. Typically in situations when the\n * span to be created starts a new trace.\n * @param spanName - Name of the span to be created.\n * @param spanKind - Kind of the span to be created.\n * @param attributes - Initial set of SpanAttributes for the Span being constructed.\n * @param links - Collection of links that will be associated with the Span to\n * be created. Typically useful for batch operations.\n * @returns a {@link SamplingResult}.\n */\n public shouldSample(\n context: Context,\n traceId: string,\n // @ts-expect-error unused argument\n spanName: string,\n // @ts-expect-error unused argument\n spanKind: SpanKind,\n attributes: Attributes,\n // @ts-expect-error unused argument\n links: Link[],\n ): SamplingResult {\n const sampleRate = this.getSampleRate();\n return shouldSample(sampleRate, context, traceId, attributes)\n ? { decision: SamplingDecision.RECORD_AND_SAMPLED, attributes: attributes }\n : { decision: SamplingDecision.NOT_RECORD, attributes: attributes };\n }\n\n /**\n * Return Sampler description\n */\n public toString(): string {\n return `RateLimitedSampler{${this.tracesPerSecond}}`;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Attributes, Context } from "@opentelemetry/api";
|
|
2
|
+
/**
|
|
3
|
+
* Computes a deterministic hash code from a string input (typically a trace ID)
|
|
4
|
+
* and returns a value between 0 and 100 for sampling decisions.
|
|
5
|
+
*
|
|
6
|
+
* This function replicates the C# hash algorithm used in Application Insights
|
|
7
|
+
* to ensure consistent sampling decisions across different SDKs and languages.
|
|
8
|
+
* The same trace ID will always produce the same hash value, enabling
|
|
9
|
+
* distributed sampling where all spans in a trace are sampled consistently.
|
|
10
|
+
*
|
|
11
|
+
* @param input - The input string to hash (usually a trace ID)
|
|
12
|
+
* @returns A number between 0 and 100 representing the hash-based sampling score
|
|
13
|
+
*/
|
|
14
|
+
export declare function getSamplingHashCode(input: string): number;
|
|
15
|
+
export declare function roundDownToNearest(samplingPercentage: number): number;
|
|
16
|
+
export declare function shouldSample(samplePercentage: number, context: Context, traceId: string, attributes: Attributes): boolean;
|
|
17
|
+
//# sourceMappingURL=samplingUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"samplingUtils.d.ts","sourceRoot":"","sources":["../../../src/sampling/samplingUtils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAyBzD;AAED,wBAAgB,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAMrE;AAED,wBAAgB,YAAY,CAC1B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,UAAU,GACrB,OAAO,CA2CT"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { trace, TraceFlags } from "@opentelemetry/api";
|
|
4
|
+
import { AzureMonitorSampleRate } from "../utils/constants/applicationinsights.js";
|
|
5
|
+
/**
|
|
6
|
+
* Computes a deterministic hash code from a string input (typically a trace ID)
|
|
7
|
+
* and returns a value between 0 and 100 for sampling decisions.
|
|
8
|
+
*
|
|
9
|
+
* This function replicates the C# hash algorithm used in Application Insights
|
|
10
|
+
* to ensure consistent sampling decisions across different SDKs and languages.
|
|
11
|
+
* The same trace ID will always produce the same hash value, enabling
|
|
12
|
+
* distributed sampling where all spans in a trace are sampled consistently.
|
|
13
|
+
*
|
|
14
|
+
* @param input - The input string to hash (usually a trace ID)
|
|
15
|
+
* @returns A number between 0 and 100 representing the hash-based sampling score
|
|
16
|
+
*/
|
|
17
|
+
export function getSamplingHashCode(input) {
|
|
18
|
+
const csharpMin = -2147483648;
|
|
19
|
+
const csharpMax = 2147483647;
|
|
20
|
+
let hash = 5381;
|
|
21
|
+
if (!input) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
// Ensure input is at least 8 characters long by repeating it
|
|
25
|
+
let processedInput = input;
|
|
26
|
+
while (processedInput.length < 8) {
|
|
27
|
+
processedInput = processedInput + processedInput;
|
|
28
|
+
}
|
|
29
|
+
// Compute hash using a variation of djb2 algorithm with C# integer overflow simulation
|
|
30
|
+
// This uses hash * 33 + c (where hash << 5 + hash equals hash * 33)
|
|
31
|
+
for (let i = 0; i < processedInput.length; i++) {
|
|
32
|
+
// JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)
|
|
33
|
+
hash = ((((hash << 5) + hash) | 0) + processedInput.charCodeAt(i)) | 0;
|
|
34
|
+
}
|
|
35
|
+
// Normalize hash to positive value and convert to 0-100 range
|
|
36
|
+
hash = hash <= csharpMin ? csharpMax : Math.abs(hash);
|
|
37
|
+
return (hash / csharpMax) * 100;
|
|
38
|
+
}
|
|
39
|
+
export function roundDownToNearest(samplingPercentage) {
|
|
40
|
+
if (samplingPercentage === 0) {
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
const itemCount = 100 / samplingPercentage;
|
|
44
|
+
return 100.0 / Math.ceil(itemCount);
|
|
45
|
+
}
|
|
46
|
+
export function shouldSample(samplePercentage, context, traceId, attributes) {
|
|
47
|
+
let sampleRate = samplePercentage;
|
|
48
|
+
let isSampled = undefined;
|
|
49
|
+
if (sampleRate === 100) {
|
|
50
|
+
isSampled = true;
|
|
51
|
+
}
|
|
52
|
+
else if (sampleRate === 0) {
|
|
53
|
+
isSampled = false;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Try to get the parent sampling result first
|
|
57
|
+
const parentSpan = trace.getSpan(context);
|
|
58
|
+
const parentSpanContext = parentSpan?.spanContext();
|
|
59
|
+
if (parentSpanContext &&
|
|
60
|
+
trace.isSpanContextValid(parentSpanContext) &&
|
|
61
|
+
!parentSpanContext.isRemote) {
|
|
62
|
+
if ((parentSpanContext.traceFlags & TraceFlags.SAMPLED) === TraceFlags.SAMPLED) {
|
|
63
|
+
isSampled = true;
|
|
64
|
+
}
|
|
65
|
+
else if ((parentSpanContext.traceFlags & TraceFlags.NONE) === TraceFlags.NONE) {
|
|
66
|
+
isSampled = false;
|
|
67
|
+
}
|
|
68
|
+
// If the parent span is valid and not remote, we can use its sample rate
|
|
69
|
+
const parentSampleRate = Number(parentSpan.attributes?.[AzureMonitorSampleRate]);
|
|
70
|
+
if (!isNaN(parentSampleRate)) {
|
|
71
|
+
sampleRate = Number(parentSampleRate);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Only add sample rate attribute if it's not 100
|
|
76
|
+
if (sampleRate !== 100) {
|
|
77
|
+
// Add sample rate as span attribute
|
|
78
|
+
attributes = attributes || {};
|
|
79
|
+
attributes[AzureMonitorSampleRate] = sampleRate;
|
|
80
|
+
}
|
|
81
|
+
if (isSampled === undefined) {
|
|
82
|
+
const samplingHashCode = getSamplingHashCode(traceId);
|
|
83
|
+
return samplingHashCode < sampleRate;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return isSampled;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=samplingUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"samplingUtils.js","sourceRoot":"","sources":["../../../src/sampling/samplingUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAEnF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,MAAM,SAAS,GAAG,CAAC,UAAU,CAAC;IAC9B,MAAM,SAAS,GAAG,UAAU,CAAC;IAC7B,IAAI,IAAI,GAAG,IAAI,CAAC;IAEhB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,CAAC;IACX,CAAC;IAED,6DAA6D;IAC7D,IAAI,cAAc,GAAG,KAAK,CAAC;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\n\nimport type { Attributes, Context } from \"@opentelemetry/api\";\nimport { trace, TraceFlags } from \"@opentelemetry/api\";\nimport { AzureMonitorSampleRate } from \"../utils/constants/applicationinsights.js\";\n\n/**\n * Computes a deterministic hash code from a string input (typically a trace ID)\n * and returns a value between 0 and 100 for sampling decisions.\n *\n * This function replicates the C# hash algorithm used in Application Insights\n * to ensure consistent sampling decisions across different SDKs and languages.\n * The same trace ID will always produce the same hash value, enabling\n * distributed sampling where all spans in a trace are sampled consistently.\n *\n * @param input - The input string to hash (usually a trace ID)\n * @returns A number between 0 and 100 representing the hash-based sampling score\n */\nexport function getSamplingHashCode(input: string): number {\n const csharpMin = -2147483648;\n const csharpMax = 2147483647;\n let hash = 5381;\n\n if (!input) {\n return 0;\n }\n\n // Ensure input is at least 8 characters long by repeating it\n let processedInput = input;\n while (processedInput.length < 8) {\n processedInput = processedInput + processedInput;\n }\n\n // Compute hash using a variation of djb2 algorithm with C# integer overflow simulation\n // This uses hash * 33 + c (where hash << 5 + hash equals hash * 33)\n for (let i = 0; i < processedInput.length; i++) {\n // JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)\n hash = ((((hash << 5) + hash) | 0) + processedInput.charCodeAt(i)) | 0;\n }\n\n // Normalize hash to positive value and convert to 0-100 range\n hash = hash <= csharpMin ? csharpMax : Math.abs(hash);\n return (hash / csharpMax) * 100;\n}\n\nexport function roundDownToNearest(samplingPercentage: number): number {\n if (samplingPercentage === 0) {\n return 0;\n }\n const itemCount = 100 / samplingPercentage;\n return 100.0 / Math.ceil(itemCount);\n}\n\nexport function shouldSample(\n samplePercentage: number,\n context: Context,\n traceId: string,\n attributes: Attributes,\n): boolean {\n let sampleRate = samplePercentage;\n let isSampled = undefined;\n\n if (sampleRate === 100) {\n isSampled = true;\n } else if (sampleRate === 0) {\n isSampled = false;\n } else {\n // Try to get the parent sampling result first\n const parentSpan = trace.getSpan(context);\n const parentSpanContext = parentSpan?.spanContext();\n if (\n parentSpanContext &&\n trace.isSpanContextValid(parentSpanContext) &&\n !parentSpanContext.isRemote\n ) {\n if ((parentSpanContext.traceFlags & TraceFlags.SAMPLED) === TraceFlags.SAMPLED) {\n isSampled = true;\n } else if ((parentSpanContext.traceFlags & TraceFlags.NONE) === TraceFlags.NONE) {\n isSampled = false;\n }\n // If the parent span is valid and not remote, we can use its sample rate\n const parentSampleRate = Number((parentSpan as any).attributes?.[AzureMonitorSampleRate]);\n if (!isNaN(parentSampleRate)) {\n sampleRate = Number(parentSampleRate);\n }\n }\n }\n\n // Only add sample rate attribute if it's not 100\n if (sampleRate !== 100) {\n // Add sample rate as span attribute\n attributes = attributes || {};\n attributes[AzureMonitorSampleRate] = sampleRate;\n }\n\n if (isSampled === undefined) {\n const samplingHashCode = getSamplingHashCode(traceId);\n return samplingHashCode < sampleRate;\n } else {\n return isSampled;\n }\n}\n"]}
|
package/dist/esm/utils/common.js
CHANGED
|
@@ -13,7 +13,7 @@ export function hrTimeToDate(hrTime) {
|
|
|
13
13
|
}
|
|
14
14
|
export function createTagsFromResource(resource) {
|
|
15
15
|
const context = getInstance();
|
|
16
|
-
const tags =
|
|
16
|
+
const tags = { ...context.tags };
|
|
17
17
|
if (resource && resource.attributes) {
|
|
18
18
|
tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);
|
|
19
19
|
tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);
|
|
@@ -235,8 +235,7 @@ export function serializeAttribute(value) {
|
|
|
235
235
|
return String(value);
|
|
236
236
|
}
|
|
237
237
|
export function shouldCreateResourceMetric() {
|
|
238
|
-
|
|
239
|
-
return !(((_a = process.env[ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "true");
|
|
238
|
+
return !(process.env[ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED]?.toLowerCase() === "true");
|
|
240
239
|
}
|
|
241
240
|
export function isSyntheticSource(attributes) {
|
|
242
241
|
return !!attributes[experimentalOpenTelemetryValues.SYNTHETIC_TYPE];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,2BAA2B,EAC3B,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,gCAAgC,EAChC,wBAAwB,EACxB,4BAA4B,EAC5B,8BAA8B,EAC9B,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAa,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,0CAA0C,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EACd,SAAS,GACV,MAAM,gBAAgB,CAAC;AAExB,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAkB;IACvD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B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AC,KAAK,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IACD,qCAAqC;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,0BAA0B;;IACxC,OAAO,CAAC,CAAC,CAAA,MAAA,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,0CAAE,WAAW,EAAE,MAAK,MAAM,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,UAAsB;IACtD,OAAO,CAAC,CAAC,UAAU,CAAC,+BAA+B,CAAC,cAAc,CAAC,CAAC;AACtE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport os from \"node:os\";\nimport {\n SEMRESATTRS_DEVICE_ID,\n SEMRESATTRS_DEVICE_MODEL_NAME,\n SEMRESATTRS_SERVICE_VERSION,\n SEMRESATTRS_K8S_POD_NAME,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n DBSYSTEMVALUES_DB2,\n DBSYSTEMVALUES_DERBY,\n DBSYSTEMVALUES_MARIADB,\n DBSYSTEMVALUES_MSSQL,\n DBSYSTEMVALUES_ORACLE,\n DBSYSTEMVALUES_SQLITE,\n DBSYSTEMVALUES_OTHER_SQL,\n DBSYSTEMVALUES_HSQLDB,\n SEMATTRS_PEER_SERVICE,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_SERVICE_NAMESPACE,\n SEMRESATTRS_K8S_DEPLOYMENT_NAME,\n SEMRESATTRS_K8S_REPLICASET_NAME,\n SEMRESATTRS_K8S_STATEFULSET_NAME,\n SEMRESATTRS_K8S_JOB_NAME,\n SEMRESATTRS_K8S_CRONJOB_NAME,\n SEMRESATTRS_K8S_DAEMONSET_NAME,\n ATTR_TELEMETRY_SDK_VERSION,\n ATTR_TELEMETRY_SDK_LANGUAGE,\n ATTR_TELEMETRY_SDK_NAME,\n DBSYSTEMVALUES_H2,\n} from \"@opentelemetry/semantic-conventions\";\nimport { experimentalOpenTelemetryValues, type Tags } from \"../types.js\";\nimport { getInstance } from \"../platform/index.js\";\nimport type { TelemetryItem as Envelope, MetricsData } from \"../generated/index.js\";\nimport { KnownContextTagKeys } from \"../generated/index.js\";\nimport type { Resource } from \"@opentelemetry/resources\";\nimport type { Attributes, HrTime } from \"@opentelemetry/api\";\nimport { hrTimeToNanoseconds } from \"@opentelemetry/core\";\nimport type { AnyValue } from \"@opentelemetry/api-logs\";\nimport { ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED } from \"../Declarations/Constants.js\";\nimport {\n getHttpHost,\n getHttpMethod,\n getHttpScheme,\n getHttpTarget,\n getHttpUrl,\n getNetPeerName,\n getNetPeerPort,\n getPeerIp,\n} from \"./spanUtils.js\";\n\nexport function hrTimeToDate(hrTime: HrTime): Date {\n return new Date(hrTimeToNanoseconds(hrTime) / 1000000);\n}\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);\n tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);\n if (resource.attributes[SEMRESATTRS_DEVICE_ID]) {\n tags[KnownContextTagKeys.AiDeviceId] = String(resource.attributes[SEMRESATTRS_DEVICE_ID]);\n }\n if (resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME]) {\n tags[KnownContextTagKeys.AiDeviceModel] = String(\n resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME],\n );\n }\n if (resource.attributes[SEMRESATTRS_SERVICE_VERSION]) {\n tags[KnownContextTagKeys.AiApplicationVer] = String(\n resource.attributes[SEMRESATTRS_SERVICE_VERSION],\n );\n }\n }\n return tags;\n}\n\nfunction getCloudRole(resource: Resource): string {\n let cloudRole = \"\";\n // Service attributes\n const serviceName = resource.attributes[SEMRESATTRS_SERVICE_NAME];\n const serviceNamespace = resource.attributes[SEMRESATTRS_SERVICE_NAMESPACE];\n if (serviceName) {\n // Custom Service name provided by customer is highest precedence\n if (!String(serviceName).startsWith(\"unknown_service\")) {\n if (serviceNamespace) {\n return `${serviceNamespace}.${serviceName}`;\n } else {\n return String(serviceName);\n }\n } else {\n // Service attributes will be only used if K8S attributes are not present\n if (serviceNamespace) {\n cloudRole = `${serviceNamespace}.${serviceName}`;\n } else {\n cloudRole = String(serviceName);\n }\n }\n }\n // Kubernetes attributes should take precedence\n const kubernetesDeploymentName = resource.attributes[SEMRESATTRS_K8S_DEPLOYMENT_NAME];\n if (kubernetesDeploymentName) {\n return String(kubernetesDeploymentName);\n }\n const kuberneteReplicasetName = resource.attributes[SEMRESATTRS_K8S_REPLICASET_NAME];\n if (kuberneteReplicasetName) {\n return String(kuberneteReplicasetName);\n }\n const kubernetesStatefulSetName = resource.attributes[SEMRESATTRS_K8S_STATEFULSET_NAME];\n if (kubernetesStatefulSetName) {\n return String(kubernetesStatefulSetName);\n }\n const kubernetesJobName = resource.attributes[SEMRESATTRS_K8S_JOB_NAME];\n if (kubernetesJobName) {\n return String(kubernetesJobName);\n }\n const kubernetesCronjobName = resource.attributes[SEMRESATTRS_K8S_CRONJOB_NAME];\n if (kubernetesCronjobName) {\n return String(kubernetesCronjobName);\n }\n const kubernetesDaemonsetName = resource.attributes[SEMRESATTRS_K8S_DAEMONSET_NAME];\n if (kubernetesDaemonsetName) {\n return String(kubernetesDaemonsetName);\n }\n return cloudRole;\n}\n\nfunction getCloudRoleInstance(resource: Resource): string {\n // Kubernetes attributes should take precedence\n const kubernetesPodName = resource.attributes[SEMRESATTRS_K8S_POD_NAME];\n if (kubernetesPodName) {\n return String(kubernetesPodName);\n }\n // Service attributes\n const serviceInstanceId = resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n return String(serviceInstanceId);\n }\n // Default\n return os && os.hostname();\n}\n\nexport function isSqlDB(dbSystem: string): boolean {\n return (\n dbSystem === DBSYSTEMVALUES_DB2 ||\n dbSystem === DBSYSTEMVALUES_DERBY ||\n dbSystem === DBSYSTEMVALUES_MARIADB ||\n dbSystem === DBSYSTEMVALUES_MSSQL ||\n dbSystem === DBSYSTEMVALUES_ORACLE ||\n dbSystem === DBSYSTEMVALUES_SQLITE ||\n dbSystem === DBSYSTEMVALUES_OTHER_SQL ||\n dbSystem === DBSYSTEMVALUES_HSQLDB ||\n dbSystem === DBSYSTEMVALUES_H2\n );\n}\n\nexport function getUrl(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const httpMethod = getHttpMethod(attributes);\n if (httpMethod) {\n const httpUrl = getHttpUrl(attributes);\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = getHttpScheme(attributes);\n const httpTarget = getHttpTarget(attributes);\n if (httpScheme && httpTarget) {\n const httpHost = getHttpHost(attributes);\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = getNetPeerPort(attributes);\n if (netPeerPort) {\n const netPeerName = getNetPeerName(attributes);\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = getPeerIp(attributes);\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nexport function getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SEMATTRS_PEER_SERVICE];\n const httpHost = getHttpHost(attributes);\n const httpUrl = getHttpUrl(attributes);\n const netPeerName = getNetPeerName(attributes);\n const netPeerIp = getPeerIp(attributes);\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nexport function createResourceMetricEnvelope(\n resource: Resource,\n instrumentationKey: string,\n): Envelope | undefined {\n if (resource && resource.attributes) {\n const tags = createTagsFromResource(resource);\n const resourceAttributes: { [propertyName: string]: string } = {};\n for (const key of Object.keys(resource.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key === ATTR_TELEMETRY_SDK_VERSION ||\n key === ATTR_TELEMETRY_SDK_LANGUAGE ||\n key === ATTR_TELEMETRY_SDK_NAME\n )\n ) {\n resourceAttributes[key] = resource.attributes[key] as string;\n }\n }\n // Only send event when resource attributes are available\n if (Object.keys(resourceAttributes).length > 0) {\n const baseData: MetricsData = {\n version: 2,\n metrics: [{ name: \"_OTELRESOURCE_\", value: 1 }],\n properties: resourceAttributes,\n };\n const envelope: Envelope = {\n name: \"Microsoft.ApplicationInsights.Metric\",\n time: new Date(),\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: baseData,\n },\n tags: tags,\n };\n return envelope;\n }\n }\n return;\n}\n\nexport function serializeAttribute(value: AnyValue): string {\n if (typeof value === \"object\") {\n if (value instanceof Error) {\n try {\n return JSON.stringify(value, Object.getOwnPropertyNames(value));\n } catch (err: unknown) {\n // Failed to serialize, return string cast\n return String(value);\n }\n } else if (value instanceof Uint8Array) {\n return String(value);\n } else {\n try {\n return JSON.stringify(value);\n } catch (err: unknown) {\n // Failed to serialize, return string cast\n return String(value);\n }\n }\n }\n // Return scalar and undefined values\n return String(value);\n}\n\nexport function shouldCreateResourceMetric(): boolean {\n return !(process.env[ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED]?.toLowerCase() === \"true\");\n}\n\nexport function isSyntheticSource(attributes: Attributes): boolean {\n return !!attributes[experimentalOpenTelemetryValues.SYNTHETIC_TYPE];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,SAAS,CAAC;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AAC,0CAA0C,CAAC,EAAE,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,UAAsB;IACtD,OAAO,CAAC,CAAC,UAAU,CAAC,+BAA+B,CAAC,cAAc,CAAC,CAAC;AACtE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport os from \"node:os\";\nimport {\n SEMRESATTRS_DEVICE_ID,\n SEMRESATTRS_DEVICE_MODEL_NAME,\n SEMRESATTRS_SERVICE_VERSION,\n SEMRESATTRS_K8S_POD_NAME,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n DBSYSTEMVALUES_DB2,\n DBSYSTEMVALUES_DERBY,\n DBSYSTEMVALUES_MARIADB,\n DBSYSTEMVALUES_MSSQL,\n DBSYSTEMVALUES_ORACLE,\n DBSYSTEMVALUES_SQLITE,\n DBSYSTEMVALUES_OTHER_SQL,\n DBSYSTEMVALUES_HSQLDB,\n SEMATTRS_PEER_SERVICE,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_SERVICE_NAMESPACE,\n SEMRESATTRS_K8S_DEPLOYMENT_NAME,\n SEMRESATTRS_K8S_REPLICASET_NAME,\n SEMRESATTRS_K8S_STATEFULSET_NAME,\n SEMRESATTRS_K8S_JOB_NAME,\n SEMRESATTRS_K8S_CRONJOB_NAME,\n SEMRESATTRS_K8S_DAEMONSET_NAME,\n ATTR_TELEMETRY_SDK_VERSION,\n ATTR_TELEMETRY_SDK_LANGUAGE,\n ATTR_TELEMETRY_SDK_NAME,\n DBSYSTEMVALUES_H2,\n} from \"@opentelemetry/semantic-conventions\";\nimport { experimentalOpenTelemetryValues, type Tags } from \"../types.js\";\nimport { getInstance } from \"../platform/index.js\";\nimport type { TelemetryItem as Envelope, MetricsData } from \"../generated/index.js\";\nimport { KnownContextTagKeys } from \"../generated/index.js\";\nimport type { Resource } from \"@opentelemetry/resources\";\nimport type { Attributes, HrTime } from \"@opentelemetry/api\";\nimport { hrTimeToNanoseconds } from \"@opentelemetry/core\";\nimport type { AnyValue } from \"@opentelemetry/api-logs\";\nimport { ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED } from \"../Declarations/Constants.js\";\nimport {\n getHttpHost,\n getHttpMethod,\n getHttpScheme,\n getHttpTarget,\n getHttpUrl,\n getNetPeerName,\n getNetPeerPort,\n getPeerIp,\n} from \"./spanUtils.js\";\n\nexport function hrTimeToDate(hrTime: HrTime): Date {\n return new Date(hrTimeToNanoseconds(hrTime) / 1000000);\n}\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);\n tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);\n if (resource.attributes[SEMRESATTRS_DEVICE_ID]) {\n tags[KnownContextTagKeys.AiDeviceId] = String(resource.attributes[SEMRESATTRS_DEVICE_ID]);\n }\n if (resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME]) {\n tags[KnownContextTagKeys.AiDeviceModel] = String(\n resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME],\n );\n }\n if (resource.attributes[SEMRESATTRS_SERVICE_VERSION]) {\n tags[KnownContextTagKeys.AiApplicationVer] = String(\n resource.attributes[SEMRESATTRS_SERVICE_VERSION],\n );\n }\n }\n return tags;\n}\n\nfunction getCloudRole(resource: Resource): string {\n let cloudRole = \"\";\n // Service attributes\n const serviceName = resource.attributes[SEMRESATTRS_SERVICE_NAME];\n const serviceNamespace = resource.attributes[SEMRESATTRS_SERVICE_NAMESPACE];\n if (serviceName) {\n // Custom Service name provided by customer is highest precedence\n if (!String(serviceName).startsWith(\"unknown_service\")) {\n if (serviceNamespace) {\n return `${serviceNamespace}.${serviceName}`;\n } else {\n return String(serviceName);\n }\n } else {\n // Service attributes will be only used if K8S attributes are not present\n if (serviceNamespace) {\n cloudRole = `${serviceNamespace}.${serviceName}`;\n } else {\n cloudRole = String(serviceName);\n }\n }\n }\n // Kubernetes attributes should take precedence\n const kubernetesDeploymentName = resource.attributes[SEMRESATTRS_K8S_DEPLOYMENT_NAME];\n if (kubernetesDeploymentName) {\n return String(kubernetesDeploymentName);\n }\n const kuberneteReplicasetName = resource.attributes[SEMRESATTRS_K8S_REPLICASET_NAME];\n if (kuberneteReplicasetName) {\n return String(kuberneteReplicasetName);\n }\n const kubernetesStatefulSetName = resource.attributes[SEMRESATTRS_K8S_STATEFULSET_NAME];\n if (kubernetesStatefulSetName) {\n return String(kubernetesStatefulSetName);\n }\n const kubernetesJobName = resource.attributes[SEMRESATTRS_K8S_JOB_NAME];\n if (kubernetesJobName) {\n return String(kubernetesJobName);\n }\n const kubernetesCronjobName = resource.attributes[SEMRESATTRS_K8S_CRONJOB_NAME];\n if (kubernetesCronjobName) {\n return String(kubernetesCronjobName);\n }\n const kubernetesDaemonsetName = resource.attributes[SEMRESATTRS_K8S_DAEMONSET_NAME];\n if (kubernetesDaemonsetName) {\n return String(kubernetesDaemonsetName);\n }\n return cloudRole;\n}\n\nfunction getCloudRoleInstance(resource: Resource): string {\n // Kubernetes attributes should take precedence\n const kubernetesPodName = resource.attributes[SEMRESATTRS_K8S_POD_NAME];\n if (kubernetesPodName) {\n return String(kubernetesPodName);\n }\n // Service attributes\n const serviceInstanceId = resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n return String(serviceInstanceId);\n }\n // Default\n return os && os.hostname();\n}\n\nexport function isSqlDB(dbSystem: string): boolean {\n return (\n dbSystem === DBSYSTEMVALUES_DB2 ||\n dbSystem === DBSYSTEMVALUES_DERBY ||\n dbSystem === DBSYSTEMVALUES_MARIADB ||\n dbSystem === DBSYSTEMVALUES_MSSQL ||\n dbSystem === DBSYSTEMVALUES_ORACLE ||\n dbSystem === DBSYSTEMVALUES_SQLITE ||\n dbSystem === DBSYSTEMVALUES_OTHER_SQL ||\n dbSystem === DBSYSTEMVALUES_HSQLDB ||\n dbSystem === DBSYSTEMVALUES_H2\n );\n}\n\nexport function getUrl(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const httpMethod = getHttpMethod(attributes);\n if (httpMethod) {\n const httpUrl = getHttpUrl(attributes);\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = getHttpScheme(attributes);\n const httpTarget = getHttpTarget(attributes);\n if (httpScheme && httpTarget) {\n const httpHost = getHttpHost(attributes);\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = getNetPeerPort(attributes);\n if (netPeerPort) {\n const netPeerName = getNetPeerName(attributes);\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = getPeerIp(attributes);\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nexport function getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SEMATTRS_PEER_SERVICE];\n const httpHost = getHttpHost(attributes);\n const httpUrl = getHttpUrl(attributes);\n const netPeerName = getNetPeerName(attributes);\n const netPeerIp = getPeerIp(attributes);\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nexport function createResourceMetricEnvelope(\n resource: Resource,\n instrumentationKey: string,\n): Envelope | undefined {\n if (resource && resource.attributes) {\n const tags = createTagsFromResource(resource);\n const resourceAttributes: { [propertyName: string]: string } = {};\n for (const key of Object.keys(resource.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key === ATTR_TELEMETRY_SDK_VERSION ||\n key === ATTR_TELEMETRY_SDK_LANGUAGE ||\n key === ATTR_TELEMETRY_SDK_NAME\n )\n ) {\n resourceAttributes[key] = resource.attributes[key] as string;\n }\n }\n // Only send event when resource attributes are available\n if (Object.keys(resourceAttributes).length > 0) {\n const baseData: MetricsData = {\n version: 2,\n metrics: [{ name: \"_OTELRESOURCE_\", value: 1 }],\n properties: resourceAttributes,\n };\n const envelope: Envelope = {\n name: \"Microsoft.ApplicationInsights.Metric\",\n time: new Date(),\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: baseData,\n },\n tags: tags,\n };\n return envelope;\n }\n }\n return;\n}\n\nexport function serializeAttribute(value: AnyValue): string {\n if (typeof value === \"object\") {\n if (value instanceof Error) {\n try {\n return JSON.stringify(value, Object.getOwnPropertyNames(value));\n } catch (err: unknown) {\n // Failed to serialize, return string cast\n return String(value);\n }\n } else if (value instanceof Uint8Array) {\n return String(value);\n } else {\n try {\n return JSON.stringify(value);\n } catch (err: unknown) {\n // Failed to serialize, return string cast\n return String(value);\n }\n }\n }\n // Return scalar and undefined values\n return String(value);\n}\n\nexport function shouldCreateResourceMetric(): boolean {\n return !(process.env[ENV_OPENTELEMETRY_RESOURCE_METRIC_DISABLED]?.toLowerCase() === \"true\");\n}\n\nexport function isSyntheticSource(attributes: Attributes): boolean {\n return !!attributes[experimentalOpenTelemetryValues.SYNTHETIC_TYPE];\n}\n"]}
|
|
@@ -7,6 +7,8 @@ import * as Constants from "../Declarations/Constants.js";
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export class ConnectionStringParser {
|
|
10
|
+
static FIELDS_SEPARATOR = ";";
|
|
11
|
+
static FIELD_KEY_VALUE_SEPARATOR = "=";
|
|
10
12
|
static parse(connectionString) {
|
|
11
13
|
if (!connectionString) {
|
|
12
14
|
return {};
|
|
@@ -19,7 +21,7 @@ export class ConnectionStringParser {
|
|
|
19
21
|
// only save fields with valid formats
|
|
20
22
|
const key = kvParts[0].toLowerCase();
|
|
21
23
|
const value = kvParts[1];
|
|
22
|
-
return
|
|
24
|
+
return { ...fields, [key]: value };
|
|
23
25
|
}
|
|
24
26
|
diag.error("Connection string key-value pair is invalid: Entire connection string will be discarded");
|
|
25
27
|
isValid = false;
|
|
@@ -73,6 +75,4 @@ export class ConnectionStringParser {
|
|
|
73
75
|
return regexp.test(iKey);
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
|
-
ConnectionStringParser.FIELDS_SEPARATOR = ";";
|
|
77
|
-
ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR = "=";
|
|
78
78
|
//# sourceMappingURL=connectionStringParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,sBAAsB;
|
|
1
|
+
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IACzB,MAAM,CAAU,gBAAgB,GAAG,GAAG,CAAC;IAEvC,MAAM,CAAU,yBAAyB,GAAG,GAAG,CAAC;IAEjD,MAAM,CAAC,KAAK,CAAC,gBAAyB;QAC3C,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,KAAK,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;QA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MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YAC/C,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,UAAU,GAAG,gEAAgE,CAAC;QACpF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { diag } from \"@opentelemetry/api\";\nimport type { ConnectionString, ConnectionStringKey } from \"../Declarations/Contracts/index.js\";\nimport * as Constants from \"../Declarations/Constants.js\";\n\n/**\n * ConnectionString parser.\n * @internal\n */\nexport class ConnectionStringParser {\n private static readonly FIELDS_SEPARATOR = \";\";\n\n private static readonly FIELD_KEY_VALUE_SEPARATOR = \"=\";\n\n public static parse(connectionString?: string): ConnectionString {\n if (!connectionString) {\n return {};\n }\n\n const kvPairs = connectionString.split(ConnectionStringParser.FIELDS_SEPARATOR);\n let isValid = true;\n\n const result: ConnectionString = kvPairs.reduce((fields: ConnectionString, kv: string) => {\n const kvParts = kv.split(ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR);\n\n if (kvParts.length === 2) {\n // only save fields with valid formats\n const key = kvParts[0].toLowerCase() as ConnectionStringKey;\n const value = kvParts[1];\n return { ...fields, [key]: value };\n }\n diag.error(\n \"Connection string key-value pair is invalid: Entire connection string will be discarded\",\n );\n isValid = false;\n return fields;\n }, {});\n\n if (isValid && Object.keys(result).length > 0) {\n // this is a valid connection string, so parse the results\n\n if (result.endpointsuffix) {\n // use endpoint suffix where overrides are not provided\n const locationPrefix = result.location ? `${result.location}.` : \"\";\n result.ingestionendpoint =\n result.ingestionendpoint || `https://${locationPrefix}dc.${result.endpointsuffix}`;\n result.liveendpoint =\n result.liveendpoint || `https://${locationPrefix}live.${result.endpointsuffix}`;\n }\n\n result.ingestionendpoint = result.ingestionendpoint\n ? ConnectionStringParser.sanitizeUrl(result.ingestionendpoint)\n : Constants.DEFAULT_BREEZE_ENDPOINT;\n result.liveendpoint = result.liveendpoint\n ? ConnectionStringParser.sanitizeUrl(result.liveendpoint)\n : Constants.DEFAULT_LIVEMETRICS_ENDPOINT;\n if (result.authorization && result.authorization.toLowerCase() !== \"ikey\") {\n diag.warn(\n `Connection String contains an unsupported 'Authorization' value. Defaulting to 'Authorization=ikey'`,\n );\n }\n } else {\n diag.error(\"An invalid connection string was passed in. There may be telemetry loss\");\n }\n\n return result;\n }\n\n public static sanitizeUrl(url: string): string {\n let newUrl = url.trim();\n if (newUrl.indexOf(\"https://\") < 0) {\n // Try to update http to https\n newUrl = newUrl.replace(\"http://\", \"https://\");\n }\n // Remove final slash if present\n if (newUrl[newUrl.length - 1] === \"/\") {\n newUrl = newUrl.slice(0, -1);\n }\n return newUrl;\n }\n\n public static validateInstrumentationKey(iKey: string): boolean {\n if (iKey.startsWith(\"InstrumentationKey=\")) {\n const startIndex = iKey.indexOf(\"InstrumentationKey=\") + \"InstrumentationKey=\".length;\n const endIndex = iKey.indexOf(\";\", startIndex);\n iKey = iKey.substring(startIndex, endIndex);\n }\n const UUID_Regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$\";\n const regexp = new RegExp(UUID_Regex);\n return regexp.test(iKey);\n }\n}\n"]}
|
|
@@ -17,7 +17,7 @@ export declare const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
17
17
|
* AzureMonitorTraceExporter version.
|
|
18
18
|
* @internal
|
|
19
19
|
*/
|
|
20
|
-
export declare const packageVersion = "1.0.0-beta.
|
|
20
|
+
export declare const packageVersion = "1.0.0-beta.33";
|
|
21
21
|
export declare enum DependencyTypes {
|
|
22
22
|
InProc = "InProc",
|
|
23
23
|
QueueMessage = "Queue Message",
|
|
@@ -19,7 +19,7 @@ export const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
19
19
|
* AzureMonitorTraceExporter version.
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
export const packageVersion = "1.0.0-beta.
|
|
22
|
+
export const packageVersion = "1.0.0-beta.33";
|
|
23
23
|
export var DependencyTypes;
|
|
24
24
|
(function (DependencyTypes) {
|
|
25
25
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,sCAAmB,CAAA;AACrB,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAC1D,MAAM,CAAC,MAAM,kCAAkC,GAAG,6BAA6B,CAAC;AAEhF,MAAM,CAAC,MAAM,8BAA8B,GAAG,uCAAuC,CAAC;AACtF,MAAM,CAAC,MAAM,gCAAgC,GAAG,yCAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,+BAA+B,GAAG,wCAAwC,CAAC;AACxF,MAAM,CAAC,MAAM,mCAAmC,GAAG,4CAA4C,CAAC;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,kCAAkC,GAAG,aAAa,CAAC;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,eAAe,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,uCAAuC,GAAG,kBAAkB,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * AI MS Links.\n * @internal\n */\nexport const MS_LINKS = \"_MS.links\";\n/**\n * AI enqueued time attribute.\n * @internal\n */\nexport const ENQUEUED_TIME = \"enqueuedTime\";\n/**\n * AI time since enqueued attribute.\n * @internal\n */\nexport const TIME_SINCE_ENQUEUED = \"timeSinceEnqueued\";\n/**\n * AzureMonitorTraceExporter version.\n * @internal\n */\nexport const packageVersion = \"1.0.0-beta.
|
|
1
|
+
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,sCAAmB,CAAA;AACrB,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAC1D,MAAM,CAAC,MAAM,kCAAkC,GAAG,6BAA6B,CAAC;AAEhF,MAAM,CAAC,MAAM,8BAA8B,GAAG,uCAAuC,CAAC;AACtF,MAAM,CAAC,MAAM,gCAAgC,GAAG,yCAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,+BAA+B,GAAG,wCAAwC,CAAC;AACxF,MAAM,CAAC,MAAM,mCAAmC,GAAG,4CAA4C,CAAC;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,kCAAkC,GAAG,aAAa,CAAC;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,eAAe,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,uCAAuC,GAAG,kBAAkB,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * AI MS Links.\n * @internal\n */\nexport const MS_LINKS = \"_MS.links\";\n/**\n * AI enqueued time attribute.\n * @internal\n */\nexport const ENQUEUED_TIME = \"enqueuedTime\";\n/**\n * AI time since enqueued attribute.\n * @internal\n */\nexport const TIME_SINCE_ENQUEUED = \"timeSinceEnqueued\";\n/**\n * AzureMonitorTraceExporter version.\n * @internal\n */\nexport const packageVersion = \"1.0.0-beta.33\";\n\nexport enum DependencyTypes {\n InProc = \"InProc\",\n QueueMessage = \"Queue Message\",\n Sql = \"SQL\",\n Http = \"Http\",\n Grpc = \"GRPC\",\n Wcf = \"WCF Service\",\n}\n\nexport const AzureMonitorSampleRate = \"microsoft.sample_rate\";\nexport const ApplicationInsightsBaseType = \"_MS.baseType\";\nexport const ApplicationInsightsCustomEventName = \"microsoft.custom_event.name\";\n\nexport const ApplicationInsightsMessageName = \"Microsoft.ApplicationInsights.Message\";\nexport const ApplicationInsightsExceptionName = \"Microsoft.ApplicationInsights.Exception\";\nexport const ApplicationInsightsPageViewName = \"Microsoft.ApplicationInsights.PageView\";\nexport const ApplicationInsightsAvailabilityName = \"Microsoft.ApplicationInsights.Availability\";\nexport const ApplicationInsightsEventName = \"Microsoft.ApplicationInsights.Event\";\n\nexport const ApplicationInsightsMessageBaseType = \"MessageData\";\nexport const ApplicationInsightsExceptionBaseType = \"ExceptionData\";\nexport const ApplicationInsightsPageViewBaseType = \"PageViewData\";\nexport const ApplicationInsightsAvailabilityBaseType = \"AvailabilityData\";\nexport const ApplicationInsightsEventBaseType = \"EventData\";\n"]}
|
|
@@ -13,7 +13,7 @@ const getTimeSinceEnqueued = (span) => {
|
|
|
13
13
|
let sumEnqueueDiffs = 0;
|
|
14
14
|
const startTimeMs = hrTimeToMilliseconds(span.startTime);
|
|
15
15
|
span.links.forEach(({ attributes }) => {
|
|
16
|
-
const enqueuedTime = attributes
|
|
16
|
+
const enqueuedTime = attributes?.[ENQUEUED_TIME];
|
|
17
17
|
if (enqueuedTime) {
|
|
18
18
|
countEnqueueDiffs += 1;
|
|
19
19
|
sumEnqueueDiffs += startTimeMs - (parseFloat(enqueuedTime.toString()) || 0);
|
|
@@ -45,7 +45,10 @@ export const parseEventHubSpan = (span, baseData) => {
|
|
|
45
45
|
case SpanKind.CONSUMER:
|
|
46
46
|
baseData.type = `Queue Message | ${namespace}`;
|
|
47
47
|
baseData.source = `${peerAddress}/${messageBusDestination}`;
|
|
48
|
-
baseData.measurements =
|
|
48
|
+
baseData.measurements = {
|
|
49
|
+
...baseData.measurements,
|
|
50
|
+
[TIME_SINCE_ENQUEUED]: getTimeSinceEnqueued(span),
|
|
51
|
+
};
|
|
49
52
|
break;
|
|
50
53
|
default: // no op
|
|
51
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventhub.js","sourceRoot":"","sources":["../../../src/utils/eventhub.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAG7E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEtF;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAkB,EAAU,EAAE;IAC1D,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAEzD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;QACpC,MAAM,YAAY,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"eventhub.js","sourceRoot":"","sources":["../../../src/utils/eventhub.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAG7E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEtF;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAkB,EAAU,EAAE;IAC1D,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,eAAe,GAAG,CAAC,CAAC;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AAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC/C,QAAQ,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC9C,QAAgB,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YACrE,QAAQ,CAAC,YAAY,GAAG;gBACtB,GAAG,QAAQ,CAAC,YAAY;gBACxB,CAAC,mBAAmB,CAAC,EAAE,oBAAoB,CAAC,IAAI,CAAC;aAClD,CAAC;YACF,MAAM;QACR,QAAQ,CAAC,QAAQ;IACnB,CAAC;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { SpanKind } from \"@opentelemetry/api\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { SEMATTRS_NET_PEER_NAME } from \"@opentelemetry/semantic-conventions\";\nimport type { ReadableSpan } from \"@opentelemetry/sdk-trace-base\";\nimport type { RemoteDependencyData, RequestData } from \"../generated/index.js\";\nimport { TIME_SINCE_ENQUEUED, ENQUEUED_TIME } from \"./constants/applicationinsights.js\";\nimport type { MicrosoftEventHub } from \"./constants/span/azAttributes.js\";\nimport { AzNamespace, MessageBusDestination } from \"./constants/span/azAttributes.js\";\n\n/**\n * Average span.links[].attributes.enqueuedTime\n */\nconst getTimeSinceEnqueued = (span: ReadableSpan): number => {\n let countEnqueueDiffs = 0;\n let sumEnqueueDiffs = 0;\n const startTimeMs = hrTimeToMilliseconds(span.startTime);\n\n span.links.forEach(({ attributes }) => {\n const enqueuedTime = attributes?.[ENQUEUED_TIME] as string | number;\n if (enqueuedTime) {\n countEnqueueDiffs += 1;\n sumEnqueueDiffs += startTimeMs - (parseFloat(enqueuedTime.toString()) || 0);\n }\n });\n\n return Math.max(sumEnqueueDiffs / (countEnqueueDiffs || 1), 0);\n};\n\n/**\n * Implementation of Mapping to Azure Monitor\n *\n * https://gist.github.com/lmolkova/e4215c0f44a49ef824983382762e6b92#mapping-to-azure-monitor-application-insights-telemetry\n * @internal\n */\nexport const parseEventHubSpan = (\n span: ReadableSpan,\n baseData: RequestData | RemoteDependencyData,\n): void => {\n const namespace = span.attributes[AzNamespace] as typeof MicrosoftEventHub;\n const peerAddress = (\n (span.attributes[SEMATTRS_NET_PEER_NAME] ||\n span.attributes[\"peer.address\"] ||\n \"unknown\") as string\n ).replace(/\\/$/g, \"\"); // remove trailing \"/\"\n const messageBusDestination = (span.attributes[MessageBusDestination] || \"unknown\") as string;\n\n switch (span.kind) {\n case SpanKind.CLIENT:\n baseData.type = namespace;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.PRODUCER:\n baseData.type = `Queue Message | ${namespace}`;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.CONSUMER:\n baseData.type = `Queue Message | ${namespace}`;\n (baseData as any).source = `${peerAddress}/${messageBusDestination}`;\n baseData.measurements = {\n ...baseData.measurements,\n [TIME_SINCE_ENQUEUED]: getTimeSinceEnqueued(span),\n };\n break;\n default: // no op\n }\n};\n"]}
|
|
@@ -93,18 +93,20 @@ export function logToEnvelope(log, ikey) {
|
|
|
93
93
|
version: 1,
|
|
94
94
|
data: {
|
|
95
95
|
baseType,
|
|
96
|
-
baseData:
|
|
97
|
-
|
|
96
|
+
baseData: {
|
|
97
|
+
...baseData,
|
|
98
|
+
properties,
|
|
99
|
+
measurements,
|
|
100
|
+
},
|
|
98
101
|
},
|
|
99
102
|
};
|
|
100
103
|
}
|
|
101
104
|
function createTagsFromLog(log) {
|
|
102
|
-
var _a, _b;
|
|
103
105
|
const tags = createTagsFromResource(log.resource);
|
|
104
|
-
if (
|
|
106
|
+
if (log.spanContext?.traceId) {
|
|
105
107
|
tags[KnownContextTagKeys.AiOperationId] = log.spanContext.traceId;
|
|
106
108
|
}
|
|
107
|
-
if (
|
|
109
|
+
if (log.spanContext?.spanId) {
|
|
108
110
|
tags[KnownContextTagKeys.AiOperationParentId] = log.spanContext.spanId;
|
|
109
111
|
}
|
|
110
112
|
if (log.attributes[KnownContextTagKeys.AiOperationName]) {
|
|
@@ -176,10 +178,9 @@ function getLegacyApplicationInsightsName(log) {
|
|
|
176
178
|
return name;
|
|
177
179
|
}
|
|
178
180
|
function getLegacyApplicationInsightsMeasurements(log) {
|
|
179
|
-
var _a;
|
|
180
181
|
let measurements = {};
|
|
181
|
-
if (
|
|
182
|
-
measurements =
|
|
182
|
+
if (log.body?.measurements) {
|
|
183
|
+
measurements = { ...log.body.measurements };
|
|
183
184
|
}
|
|
184
185
|
return measurements;
|
|
185
186
|
}
|
|
@@ -206,7 +207,7 @@ function getLegacyApplicationInsightsBaseData(log) {
|
|
|
206
207
|
baseData = log.body;
|
|
207
208
|
break;
|
|
208
209
|
}
|
|
209
|
-
if (typeof
|
|
210
|
+
if (typeof baseData?.message === "object") {
|
|
210
211
|
baseData.message = JSON.stringify(baseData.message);
|
|
211
212
|
}
|
|
212
213
|
}
|