@ms-cloudpack/telemetry 0.8.1 → 0.8.2
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/{AppInsightsTelemetryClient-R4KUMXIS.js → AppInsightsTelemetryClient-DIN7NSX7.js} +1 -1
- package/dist/{NoOpTelemetryClient-TTBAN54Z.js → NoOpTelemetryClient-IZOMUV4R.js} +2 -2
- package/dist/{chunk-NJ4KSOZ3.js → chunk-6K6C2B4T.js} +103 -1
- package/dist/{chunk-BNPQM6Z3.js → chunk-7OGMQ6JV.js} +1 -1
- package/dist/index.js +4 -4
- package/lib/proxies/createEndGuardedSpan.d.ts +12 -0
- package/lib/proxies/createEndGuardedSpan.test.d.ts +2 -0
- package/lib/proxies/createImprovedStartActiveSpan.d.ts +4 -0
- package/lib/proxies/createImprovedStartActiveSpan.test.d.ts +2 -0
- package/lib/proxies/createProxiedTracer.d.ts +10 -0
- package/lib/proxies/createProxiedTracer.test.d.ts +2 -0
- package/lib/proxies/createSpanFunctionWrapper.d.ts +9 -0
- package/lib/proxies/createSpanFunctionWrapper.test.d.ts +2 -0
- package/package.json +6 -3
package/dist/{AppInsightsTelemetryClient-R4KUMXIS.js → AppInsightsTelemetryClient-DIN7NSX7.js}
RENAMED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
require_src2,
|
|
22
22
|
require_src3,
|
|
23
23
|
require_src4
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-6K6C2B4T.js";
|
|
25
25
|
|
|
26
26
|
// ../../node_modules/.store/@azure-core-rest-pipeline-npm-1.17.0-aa1ea9ace7/package/dist/commonjs/pipeline.js
|
|
27
27
|
var require_pipeline = __commonJS({
|
|
@@ -6,8 +6,8 @@ const __filename = topLevelUrl.fileURLToPath(import.meta.url);
|
|
|
6
6
|
const __dirname = topLevelPath.dirname(__filename);
|
|
7
7
|
import {
|
|
8
8
|
NoOpTelemetryClient
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-7OGMQ6JV.js";
|
|
10
|
+
import "./chunk-6K6C2B4T.js";
|
|
11
11
|
export {
|
|
12
12
|
NoOpTelemetryClient
|
|
13
13
|
};
|
|
@@ -12405,6 +12405,108 @@ var _ConsoleSpanExporter = class _ConsoleSpanExporter {
|
|
|
12405
12405
|
__name(_ConsoleSpanExporter, "ConsoleSpanExporter");
|
|
12406
12406
|
var ConsoleSpanExporter = _ConsoleSpanExporter;
|
|
12407
12407
|
|
|
12408
|
+
// src/proxies/createEndGuardedSpan.ts
|
|
12409
|
+
var hasEnded = Symbol("hasEnded");
|
|
12410
|
+
function createEndGuardedSpan(span) {
|
|
12411
|
+
return new Proxy(span, {
|
|
12412
|
+
get(target, prop) {
|
|
12413
|
+
if (prop === "hasEnded") {
|
|
12414
|
+
return () => !!Reflect.get(target, hasEnded);
|
|
12415
|
+
}
|
|
12416
|
+
if (prop === "end") {
|
|
12417
|
+
return () => {
|
|
12418
|
+
if (!Reflect.get(target, hasEnded)) {
|
|
12419
|
+
target.end();
|
|
12420
|
+
Reflect.set(target, hasEnded, true);
|
|
12421
|
+
}
|
|
12422
|
+
};
|
|
12423
|
+
}
|
|
12424
|
+
return Reflect.get(target, prop);
|
|
12425
|
+
},
|
|
12426
|
+
set(target, prop, value) {
|
|
12427
|
+
if (prop === "end") {
|
|
12428
|
+
throw new Error("Cannot overwrite 'end' method on Span.");
|
|
12429
|
+
}
|
|
12430
|
+
return Reflect.set(target, prop, value);
|
|
12431
|
+
}
|
|
12432
|
+
});
|
|
12433
|
+
}
|
|
12434
|
+
__name(createEndGuardedSpan, "createEndGuardedSpan");
|
|
12435
|
+
|
|
12436
|
+
// src/proxies/createSpanFunctionWrapper.ts
|
|
12437
|
+
function createSpanFunctionWrapper(fn) {
|
|
12438
|
+
return function(span) {
|
|
12439
|
+
const guardedSpan = createEndGuardedSpan(span);
|
|
12440
|
+
try {
|
|
12441
|
+
return fn(guardedSpan);
|
|
12442
|
+
} catch (error) {
|
|
12443
|
+
if (!guardedSpan.hasEnded()) {
|
|
12444
|
+
guardedSpan.recordException(error instanceof Error || typeof error === "string" ? error : String(error));
|
|
12445
|
+
} else {
|
|
12446
|
+
console.info("OpenTelemetry:startActiveSpan: span has already ended, skipping recording exception.");
|
|
12447
|
+
}
|
|
12448
|
+
throw error;
|
|
12449
|
+
} finally {
|
|
12450
|
+
guardedSpan.end();
|
|
12451
|
+
}
|
|
12452
|
+
};
|
|
12453
|
+
}
|
|
12454
|
+
__name(createSpanFunctionWrapper, "createSpanFunctionWrapper");
|
|
12455
|
+
|
|
12456
|
+
// src/proxies/createImprovedStartActiveSpan.ts
|
|
12457
|
+
function parseParameters(...params) {
|
|
12458
|
+
const [name, optionsOrFn, contextOrFn, maybeFn] = params;
|
|
12459
|
+
if (params.length === 2) {
|
|
12460
|
+
return { name, fn: optionsOrFn };
|
|
12461
|
+
}
|
|
12462
|
+
if (params.length === 3) {
|
|
12463
|
+
return { name, options: optionsOrFn, fn: contextOrFn };
|
|
12464
|
+
}
|
|
12465
|
+
if (params.length === 4) {
|
|
12466
|
+
return {
|
|
12467
|
+
name,
|
|
12468
|
+
options: optionsOrFn,
|
|
12469
|
+
context: contextOrFn,
|
|
12470
|
+
fn: maybeFn
|
|
12471
|
+
};
|
|
12472
|
+
}
|
|
12473
|
+
throw new Error("Number of arguments is not supported for startActiveSpan");
|
|
12474
|
+
}
|
|
12475
|
+
__name(parseParameters, "parseParameters");
|
|
12476
|
+
function createImprovedStartActiveSpan(target) {
|
|
12477
|
+
return (...params) => {
|
|
12478
|
+
const { fn, name, context: context2, options } = parseParameters(...params);
|
|
12479
|
+
const wrappedSpanFunction = createSpanFunctionWrapper(fn);
|
|
12480
|
+
if (context2) {
|
|
12481
|
+
return target.startActiveSpan(name, options, context2, wrappedSpanFunction);
|
|
12482
|
+
}
|
|
12483
|
+
if (options) {
|
|
12484
|
+
return target.startActiveSpan(name, options, wrappedSpanFunction);
|
|
12485
|
+
}
|
|
12486
|
+
return target.startActiveSpan(name, wrappedSpanFunction);
|
|
12487
|
+
};
|
|
12488
|
+
}
|
|
12489
|
+
__name(createImprovedStartActiveSpan, "createImprovedStartActiveSpan");
|
|
12490
|
+
|
|
12491
|
+
// src/proxies/createProxiedTracer.ts
|
|
12492
|
+
var isProxy = Symbol("isProxy");
|
|
12493
|
+
function createProxiedTracer(tracer) {
|
|
12494
|
+
if (Reflect.has(tracer, isProxy)) {
|
|
12495
|
+
return tracer;
|
|
12496
|
+
}
|
|
12497
|
+
const proxiedTracer = new Proxy(tracer, {
|
|
12498
|
+
get(target, prop) {
|
|
12499
|
+
if (prop === "startActiveSpan") {
|
|
12500
|
+
return createImprovedStartActiveSpan(target);
|
|
12501
|
+
}
|
|
12502
|
+
return Reflect.get(target, prop);
|
|
12503
|
+
}
|
|
12504
|
+
});
|
|
12505
|
+
Reflect.set(proxiedTracer, isProxy, true);
|
|
12506
|
+
return proxiedTracer;
|
|
12507
|
+
}
|
|
12508
|
+
__name(createProxiedTracer, "createProxiedTracer");
|
|
12509
|
+
|
|
12408
12510
|
// src/BaseTelemetryClient.ts
|
|
12409
12511
|
var _BaseTelemetryClient = class _BaseTelemetryClient {
|
|
12410
12512
|
constructor(options) {
|
|
@@ -12444,7 +12546,7 @@ var _BaseTelemetryClient = class _BaseTelemetryClient {
|
|
|
12444
12546
|
* @returns the OpenTelemetry tracer
|
|
12445
12547
|
*/
|
|
12446
12548
|
get tracer() {
|
|
12447
|
-
return this._tracerProvider.getTracer("cloudpack-tracer");
|
|
12549
|
+
return createProxiedTracer(this._tracerProvider.getTracer("cloudpack-tracer"));
|
|
12448
12550
|
}
|
|
12449
12551
|
get performance() {
|
|
12450
12552
|
return this._performance;
|
|
@@ -7,7 +7,7 @@ const __dirname = topLevelPath.dirname(__filename);
|
|
|
7
7
|
import {
|
|
8
8
|
BaseTelemetryClient,
|
|
9
9
|
__name
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-6K6C2B4T.js";
|
|
11
11
|
|
|
12
12
|
// src/NoOpTelemetryClient.ts
|
|
13
13
|
var _NoOpTelemetryClient = class _NoOpTelemetryClient extends BaseTelemetryClient {
|
package/dist/index.js
CHANGED
|
@@ -6,28 +6,28 @@ const __filename = topLevelUrl.fileURLToPath(import.meta.url);
|
|
|
6
6
|
const __dirname = topLevelPath.dirname(__filename);
|
|
7
7
|
import {
|
|
8
8
|
NoOpTelemetryClient
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7OGMQ6JV.js";
|
|
10
10
|
import {
|
|
11
11
|
DiagConsoleLogger,
|
|
12
12
|
DiagLogLevel,
|
|
13
13
|
__name,
|
|
14
14
|
diag,
|
|
15
15
|
init_esm
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-6K6C2B4T.js";
|
|
17
17
|
|
|
18
18
|
// src/createTelemetryClient.ts
|
|
19
19
|
init_esm();
|
|
20
20
|
async function createTelemetryClient(options) {
|
|
21
21
|
if (!options.connectionString) {
|
|
22
22
|
console.debug("No connection string found. Telemetry will not be sent.");
|
|
23
|
-
const { NoOpTelemetryClient: NoOpTelemetryClient2 } = await import("./NoOpTelemetryClient-
|
|
23
|
+
const { NoOpTelemetryClient: NoOpTelemetryClient2 } = await import("./NoOpTelemetryClient-IZOMUV4R.js");
|
|
24
24
|
return new NoOpTelemetryClient2();
|
|
25
25
|
}
|
|
26
26
|
diag.setLogger(new DiagConsoleLogger(), {
|
|
27
27
|
logLevel: options.logLevel || DiagLogLevel.WARN,
|
|
28
28
|
suppressOverrideMessage: true
|
|
29
29
|
});
|
|
30
|
-
const { AppInsightsTelemetryClient } = await import("./AppInsightsTelemetryClient-
|
|
30
|
+
const { AppInsightsTelemetryClient } = await import("./AppInsightsTelemetryClient-DIN7NSX7.js");
|
|
31
31
|
return new AppInsightsTelemetryClient(options);
|
|
32
32
|
}
|
|
33
33
|
__name(createTelemetryClient, "createTelemetryClient");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* A span that can be ended only once
|
|
4
|
+
*/
|
|
5
|
+
export type EndGuardedSpan = Span & {
|
|
6
|
+
hasEnded: () => boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a Span in a Proxy to intercept calls to `end` and ensure it’s only called once.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createEndGuardedSpan(span: Span): EndGuardedSpan;
|
|
12
|
+
//# sourceMappingURL=createEndGuardedSpan.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Tracer, Span, SpanOptions, Context } from '@opentelemetry/api';
|
|
2
|
+
export type SpanFunction<T> = (span: Span) => T;
|
|
3
|
+
export declare function createImprovedStartActiveSpan(target: Tracer): <T>(name: string, optionsOrFn?: SpanOptions | SpanFunction<unknown> | undefined, contextOrFn?: Context | SpanFunction<unknown> | undefined, maybeFn?: SpanFunction<unknown> | undefined) => T;
|
|
4
|
+
//# sourceMappingURL=createImprovedStartActiveSpan.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Tracer } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a proxied tracer that will automatically do the following things;
|
|
4
|
+
* - End the span when the function ends
|
|
5
|
+
* - Record any exceptions that are thrown
|
|
6
|
+
* @param tracer - The tracer to proxy
|
|
7
|
+
* @returns - Proxied tracer
|
|
8
|
+
*/
|
|
9
|
+
export declare function createProxiedTracer(tracer: Tracer): Tracer;
|
|
10
|
+
//# sourceMappingURL=createProxiedTracer.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
|
+
import type { SpanFunction } from './createImprovedStartActiveSpan.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a span function to ensure that the span is ended and any exceptions are recorded.
|
|
5
|
+
* @param fn - The span function to wrap
|
|
6
|
+
* @returns - Wrapped span function
|
|
7
|
+
*/
|
|
8
|
+
export declare function createSpanFunctionWrapper<T>(fn: SpanFunction<T>): (span: Span) => T;
|
|
9
|
+
//# sourceMappingURL=createSpanFunctionWrapper.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/telemetry",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Helpers for reporting telemetry in Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@azure/monitor-opentelemetry-exporter": "1.0.0-beta.26",
|
|
18
18
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^10.2.
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^10.2.8",
|
|
20
20
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
21
21
|
"@opentelemetry/api": "~1.9.0",
|
|
22
22
|
"@opentelemetry/core": "~1.26.0",
|
|
@@ -32,7 +32,10 @@
|
|
|
32
32
|
"build:watch": "cloudpack-scripts build-watch",
|
|
33
33
|
"build": "cloudpack-scripts build && cloudpack-scripts bundle-node",
|
|
34
34
|
"lint:update": "cloudpack-scripts lint-update",
|
|
35
|
-
"lint": "cloudpack-scripts lint"
|
|
35
|
+
"lint": "cloudpack-scripts lint",
|
|
36
|
+
"test:update": "cloudpack-scripts test-update",
|
|
37
|
+
"test:watch": "cloudpack-scripts test-watch",
|
|
38
|
+
"test": "cloudpack-scripts test"
|
|
36
39
|
},
|
|
37
40
|
"files": [
|
|
38
41
|
"dist",
|