@ms-cloudpack/telemetry 0.8.1 → 0.9.0
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-U3TW3MST.js} +1 -1
- package/dist/{NoOpTelemetryClient-TTBAN54Z.js → NoOpTelemetryClient-W2RWEMCF.js} +2 -2
- package/dist/{chunk-BNPQM6Z3.js → chunk-J5XDHDQP.js} +1 -2
- package/dist/{chunk-NJ4KSOZ3.js → chunk-NUFLYJEX.js} +103 -100
- package/dist/index.js +4 -4
- package/lib/BaseTelemetryClient.d.ts +1 -6
- package/lib/index.d.ts +1 -5
- 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/lib/types/TelemetryClient.d.ts +1 -10
- package/lib/types/TelemetryOptions.d.ts +0 -4
- package/package.json +6 -3
- package/lib/MetricEventAggregatorRegistry.d.ts +0 -18
- package/lib/PerformanceRecorder.d.ts +0 -41
- package/lib/types/MetricEvent.d.ts +0 -7
- package/lib/types/MetricEventAggregator.d.ts +0 -6
- package/lib/types/PerformanceTracker.d.ts +0 -7
package/dist/{AppInsightsTelemetryClient-R4KUMXIS.js → AppInsightsTelemetryClient-U3TW3MST.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-NUFLYJEX.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-J5XDHDQP.js";
|
|
10
|
+
import "./chunk-NUFLYJEX.js";
|
|
11
11
|
export {
|
|
12
12
|
NoOpTelemetryClient
|
|
13
13
|
};
|
|
@@ -7,7 +7,7 @@ const __dirname = topLevelPath.dirname(__filename);
|
|
|
7
7
|
import {
|
|
8
8
|
BaseTelemetryClient,
|
|
9
9
|
__name
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NUFLYJEX.js";
|
|
11
11
|
|
|
12
12
|
// src/NoOpTelemetryClient.ts
|
|
13
13
|
var _NoOpTelemetryClient = class _NoOpTelemetryClient extends BaseTelemetryClient {
|
|
@@ -15,7 +15,6 @@ var _NoOpTelemetryClient = class _NoOpTelemetryClient extends BaseTelemetryClien
|
|
|
15
15
|
super({
|
|
16
16
|
productVersion: "no-op",
|
|
17
17
|
serviceName: "no-op",
|
|
18
|
-
rootSpanName: "no-op",
|
|
19
18
|
serviceNamespace: "no-op",
|
|
20
19
|
logLevel: "NONE"
|
|
21
20
|
});
|
|
@@ -12129,95 +12129,6 @@ var _SpanEnrichingProcessor = class _SpanEnrichingProcessor {
|
|
|
12129
12129
|
__name(_SpanEnrichingProcessor, "SpanEnrichingProcessor");
|
|
12130
12130
|
var SpanEnrichingProcessor = _SpanEnrichingProcessor;
|
|
12131
12131
|
|
|
12132
|
-
// src/PerformanceRecorder.ts
|
|
12133
|
-
import { performance } from "perf_hooks";
|
|
12134
|
-
|
|
12135
|
-
// src/MetricEventAggregatorRegistry.ts
|
|
12136
|
-
var _MetricEventAggregatorRegistry = class _MetricEventAggregatorRegistry {
|
|
12137
|
-
constructor() {
|
|
12138
|
-
this._aggregators = /* @__PURE__ */ new Set();
|
|
12139
|
-
}
|
|
12140
|
-
/**
|
|
12141
|
-
* Registers a new aggregator. If an aggregator already exists, it will be return the aggregator.
|
|
12142
|
-
* @param name - The name of the metric.
|
|
12143
|
-
* @param aggregate - The aggregator function.
|
|
12144
|
-
* @returns The aggregator that is passed in.
|
|
12145
|
-
*/
|
|
12146
|
-
register(aggregator) {
|
|
12147
|
-
if (!this._aggregators.has(aggregator)) {
|
|
12148
|
-
this._aggregators.add(aggregator);
|
|
12149
|
-
}
|
|
12150
|
-
return aggregator;
|
|
12151
|
-
}
|
|
12152
|
-
/**
|
|
12153
|
-
* Gets all the aggregated events from all the registered aggregators.
|
|
12154
|
-
* @returns The aggregated events.
|
|
12155
|
-
*/
|
|
12156
|
-
getAggregatedEvents() {
|
|
12157
|
-
const events = [];
|
|
12158
|
-
for (const aggregator of this._aggregators) {
|
|
12159
|
-
events.push(...aggregator.getAggregatedEvents());
|
|
12160
|
-
}
|
|
12161
|
-
return events;
|
|
12162
|
-
}
|
|
12163
|
-
};
|
|
12164
|
-
__name(_MetricEventAggregatorRegistry, "MetricEventAggregatorRegistry");
|
|
12165
|
-
var MetricEventAggregatorRegistry = _MetricEventAggregatorRegistry;
|
|
12166
|
-
|
|
12167
|
-
// src/PerformanceRecorder.ts
|
|
12168
|
-
var _PerformanceRecorder = class _PerformanceRecorder {
|
|
12169
|
-
constructor(span) {
|
|
12170
|
-
this.span = span;
|
|
12171
|
-
this._metricEventAggregatorRegistry = new MetricEventAggregatorRegistry();
|
|
12172
|
-
}
|
|
12173
|
-
/**
|
|
12174
|
-
* Registers a new aggregator for a given metric.
|
|
12175
|
-
* If an aggregator already exists, it will be skipped.
|
|
12176
|
-
* @param name - The name of the metric.
|
|
12177
|
-
* @param aggregator - The aggregator function.
|
|
12178
|
-
*/
|
|
12179
|
-
registerAggregator(aggregator) {
|
|
12180
|
-
return this._metricEventAggregatorRegistry.register(aggregator);
|
|
12181
|
-
}
|
|
12182
|
-
/**
|
|
12183
|
-
* Records a performance metric into telemetry. The metric will be recorded as an event on the span and logged to the console.
|
|
12184
|
-
* It can be used for any situation where a performance metric (ie: how long does it take run something, or any other purpose) is needed.
|
|
12185
|
-
* @param attributes
|
|
12186
|
-
*/
|
|
12187
|
-
record(attributes) {
|
|
12188
|
-
const { name, value, additionalProperties = {} } = attributes;
|
|
12189
|
-
this.span.addEvent("Performance-Metric", { ...additionalProperties, name, value });
|
|
12190
|
-
console.debug(`Performance-Metric: ${name} ${value}`);
|
|
12191
|
-
}
|
|
12192
|
-
async track(name, execute) {
|
|
12193
|
-
const additionalProperties = {};
|
|
12194
|
-
const startTime = performance.now();
|
|
12195
|
-
const tracker = {
|
|
12196
|
-
name,
|
|
12197
|
-
startTime,
|
|
12198
|
-
setProperties: /* @__PURE__ */ __name((properties) => {
|
|
12199
|
-
Object.assign(additionalProperties, properties);
|
|
12200
|
-
}, "setProperties")
|
|
12201
|
-
};
|
|
12202
|
-
const result = execute(tracker);
|
|
12203
|
-
if (result instanceof Promise) {
|
|
12204
|
-
await result;
|
|
12205
|
-
}
|
|
12206
|
-
this.record({ name, value: performance.now() - startTime, additionalProperties });
|
|
12207
|
-
return result;
|
|
12208
|
-
}
|
|
12209
|
-
/**
|
|
12210
|
-
* Shuts down the performance recorder and records any aggregated events.
|
|
12211
|
-
*/
|
|
12212
|
-
shutdown() {
|
|
12213
|
-
for (const { name, value, attributes } of this._metricEventAggregatorRegistry.getAggregatedEvents()) {
|
|
12214
|
-
this.record({ name, value, additionalProperties: attributes });
|
|
12215
|
-
}
|
|
12216
|
-
}
|
|
12217
|
-
};
|
|
12218
|
-
__name(_PerformanceRecorder, "PerformanceRecorder");
|
|
12219
|
-
var PerformanceRecorder = _PerformanceRecorder;
|
|
12220
|
-
|
|
12221
12132
|
// ../../node_modules/.store/uuid-npm-10.0.0-4872b46ff8/package/dist/esm-node/stringify.js
|
|
12222
12133
|
var byteToHex = [];
|
|
12223
12134
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -12405,6 +12316,108 @@ var _ConsoleSpanExporter = class _ConsoleSpanExporter {
|
|
|
12405
12316
|
__name(_ConsoleSpanExporter, "ConsoleSpanExporter");
|
|
12406
12317
|
var ConsoleSpanExporter = _ConsoleSpanExporter;
|
|
12407
12318
|
|
|
12319
|
+
// src/proxies/createEndGuardedSpan.ts
|
|
12320
|
+
var hasEnded = Symbol("hasEnded");
|
|
12321
|
+
function createEndGuardedSpan(span) {
|
|
12322
|
+
return new Proxy(span, {
|
|
12323
|
+
get(target, prop) {
|
|
12324
|
+
if (prop === "hasEnded") {
|
|
12325
|
+
return () => !!Reflect.get(target, hasEnded);
|
|
12326
|
+
}
|
|
12327
|
+
if (prop === "end") {
|
|
12328
|
+
return () => {
|
|
12329
|
+
if (!Reflect.get(target, hasEnded)) {
|
|
12330
|
+
target.end();
|
|
12331
|
+
Reflect.set(target, hasEnded, true);
|
|
12332
|
+
}
|
|
12333
|
+
};
|
|
12334
|
+
}
|
|
12335
|
+
return Reflect.get(target, prop);
|
|
12336
|
+
},
|
|
12337
|
+
set(target, prop, value) {
|
|
12338
|
+
if (prop === "end") {
|
|
12339
|
+
throw new Error("Cannot overwrite 'end' method on Span.");
|
|
12340
|
+
}
|
|
12341
|
+
return Reflect.set(target, prop, value);
|
|
12342
|
+
}
|
|
12343
|
+
});
|
|
12344
|
+
}
|
|
12345
|
+
__name(createEndGuardedSpan, "createEndGuardedSpan");
|
|
12346
|
+
|
|
12347
|
+
// src/proxies/createSpanFunctionWrapper.ts
|
|
12348
|
+
function createSpanFunctionWrapper(fn) {
|
|
12349
|
+
return function(span) {
|
|
12350
|
+
const guardedSpan = createEndGuardedSpan(span);
|
|
12351
|
+
try {
|
|
12352
|
+
return fn(guardedSpan);
|
|
12353
|
+
} catch (error) {
|
|
12354
|
+
if (!guardedSpan.hasEnded()) {
|
|
12355
|
+
guardedSpan.recordException(error instanceof Error || typeof error === "string" ? error : String(error));
|
|
12356
|
+
} else {
|
|
12357
|
+
console.info("OpenTelemetry:startActiveSpan: span has already ended, skipping recording exception.");
|
|
12358
|
+
}
|
|
12359
|
+
throw error;
|
|
12360
|
+
} finally {
|
|
12361
|
+
guardedSpan.end();
|
|
12362
|
+
}
|
|
12363
|
+
};
|
|
12364
|
+
}
|
|
12365
|
+
__name(createSpanFunctionWrapper, "createSpanFunctionWrapper");
|
|
12366
|
+
|
|
12367
|
+
// src/proxies/createImprovedStartActiveSpan.ts
|
|
12368
|
+
function parseParameters(...params) {
|
|
12369
|
+
const [name, optionsOrFn, contextOrFn, maybeFn] = params;
|
|
12370
|
+
if (params.length === 2) {
|
|
12371
|
+
return { name, fn: optionsOrFn };
|
|
12372
|
+
}
|
|
12373
|
+
if (params.length === 3) {
|
|
12374
|
+
return { name, options: optionsOrFn, fn: contextOrFn };
|
|
12375
|
+
}
|
|
12376
|
+
if (params.length === 4) {
|
|
12377
|
+
return {
|
|
12378
|
+
name,
|
|
12379
|
+
options: optionsOrFn,
|
|
12380
|
+
context: contextOrFn,
|
|
12381
|
+
fn: maybeFn
|
|
12382
|
+
};
|
|
12383
|
+
}
|
|
12384
|
+
throw new Error("Number of arguments is not supported for startActiveSpan");
|
|
12385
|
+
}
|
|
12386
|
+
__name(parseParameters, "parseParameters");
|
|
12387
|
+
function createImprovedStartActiveSpan(target) {
|
|
12388
|
+
return (...params) => {
|
|
12389
|
+
const { fn, name, context: context2, options } = parseParameters(...params);
|
|
12390
|
+
const wrappedSpanFunction = createSpanFunctionWrapper(fn);
|
|
12391
|
+
if (context2) {
|
|
12392
|
+
return target.startActiveSpan(name, options, context2, wrappedSpanFunction);
|
|
12393
|
+
}
|
|
12394
|
+
if (options) {
|
|
12395
|
+
return target.startActiveSpan(name, options, wrappedSpanFunction);
|
|
12396
|
+
}
|
|
12397
|
+
return target.startActiveSpan(name, wrappedSpanFunction);
|
|
12398
|
+
};
|
|
12399
|
+
}
|
|
12400
|
+
__name(createImprovedStartActiveSpan, "createImprovedStartActiveSpan");
|
|
12401
|
+
|
|
12402
|
+
// src/proxies/createProxiedTracer.ts
|
|
12403
|
+
var isProxy = Symbol("isProxy");
|
|
12404
|
+
function createProxiedTracer(tracer) {
|
|
12405
|
+
if (Reflect.has(tracer, isProxy)) {
|
|
12406
|
+
return tracer;
|
|
12407
|
+
}
|
|
12408
|
+
const proxiedTracer = new Proxy(tracer, {
|
|
12409
|
+
get(target, prop) {
|
|
12410
|
+
if (prop === "startActiveSpan") {
|
|
12411
|
+
return createImprovedStartActiveSpan(target);
|
|
12412
|
+
}
|
|
12413
|
+
return Reflect.get(target, prop);
|
|
12414
|
+
}
|
|
12415
|
+
});
|
|
12416
|
+
Reflect.set(proxiedTracer, isProxy, true);
|
|
12417
|
+
return proxiedTracer;
|
|
12418
|
+
}
|
|
12419
|
+
__name(createProxiedTracer, "createProxiedTracer");
|
|
12420
|
+
|
|
12408
12421
|
// src/BaseTelemetryClient.ts
|
|
12409
12422
|
var _BaseTelemetryClient = class _BaseTelemetryClient {
|
|
12410
12423
|
constructor(options) {
|
|
@@ -12424,8 +12437,6 @@ var _BaseTelemetryClient = class _BaseTelemetryClient {
|
|
|
12424
12437
|
if (options.logLevel === "DEBUG") {
|
|
12425
12438
|
this._tracerProvider.addSpanProcessor(new import_sdk_trace_node.BatchSpanProcessor(new ConsoleSpanExporter()));
|
|
12426
12439
|
}
|
|
12427
|
-
this._rootSpan = this.tracer.startSpan(options.rootSpanName || "root");
|
|
12428
|
-
this._performance = new PerformanceRecorder(this._rootSpan);
|
|
12429
12440
|
diag2.info("TelemetryClient is initialized.");
|
|
12430
12441
|
}
|
|
12431
12442
|
/**
|
|
@@ -12433,8 +12444,6 @@ var _BaseTelemetryClient = class _BaseTelemetryClient {
|
|
|
12433
12444
|
*/
|
|
12434
12445
|
async shutdown() {
|
|
12435
12446
|
diag2.debug("TelemetryClient is shuting down.");
|
|
12436
|
-
this._performance.shutdown();
|
|
12437
|
-
this.rootSpan.end();
|
|
12438
12447
|
await this._tracerProvider.forceFlush();
|
|
12439
12448
|
await this._tracerProvider.shutdown();
|
|
12440
12449
|
diag2.debug("TelemetryClient has shutdown.");
|
|
@@ -12444,13 +12453,7 @@ var _BaseTelemetryClient = class _BaseTelemetryClient {
|
|
|
12444
12453
|
* @returns the OpenTelemetry tracer
|
|
12445
12454
|
*/
|
|
12446
12455
|
get tracer() {
|
|
12447
|
-
return this._tracerProvider.getTracer("cloudpack-tracer");
|
|
12448
|
-
}
|
|
12449
|
-
get performance() {
|
|
12450
|
-
return this._performance;
|
|
12451
|
-
}
|
|
12452
|
-
get rootSpan() {
|
|
12453
|
-
return this._rootSpan;
|
|
12456
|
+
return createProxiedTracer(this._tracerProvider.getTracer("cloudpack-tracer"));
|
|
12454
12457
|
}
|
|
12455
12458
|
};
|
|
12456
12459
|
__name(_BaseTelemetryClient, "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-J5XDHDQP.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-NUFLYJEX.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-W2RWEMCF.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-U3TW3MST.js");
|
|
31
31
|
return new AppInsightsTelemetryClient(options);
|
|
32
32
|
}
|
|
33
33
|
__name(createTelemetryClient, "createTelemetryClient");
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Tracer } from '@opentelemetry/api';
|
|
2
2
|
import type { TelemetryOptions } from './types/TelemetryOptions.js';
|
|
3
3
|
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
4
4
|
import type { TelemetryClient } from './types/TelemetryClient.js';
|
|
5
|
-
import { PerformanceRecorder } from './PerformanceRecorder.js';
|
|
6
5
|
export declare class BaseTelemetryClient implements TelemetryClient {
|
|
7
|
-
private readonly _performance;
|
|
8
|
-
private readonly _rootSpan;
|
|
9
6
|
protected readonly _tracerProvider: NodeTracerProvider;
|
|
10
7
|
constructor(options: TelemetryOptions);
|
|
11
8
|
/**
|
|
@@ -17,7 +14,5 @@ export declare class BaseTelemetryClient implements TelemetryClient {
|
|
|
17
14
|
* @returns the OpenTelemetry tracer
|
|
18
15
|
*/
|
|
19
16
|
get tracer(): Tracer;
|
|
20
|
-
get performance(): PerformanceRecorder;
|
|
21
|
-
get rootSpan(): Span;
|
|
22
17
|
}
|
|
23
18
|
//# sourceMappingURL=BaseTelemetryClient.d.ts.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
export type { Span, Tracer
|
|
1
|
+
export type { Span, Tracer } from '@opentelemetry/api';
|
|
2
2
|
export { createTelemetryClient } from './createTelemetryClient.js';
|
|
3
3
|
export type { LogLevel } from './types/LogLevel.js';
|
|
4
4
|
export type { TelemetryClient } from './types/TelemetryClient.js';
|
|
5
5
|
export type { TelemetryOptions } from './types/TelemetryOptions.js';
|
|
6
6
|
export { createNoOpTelemetryClient } from './createNoOpTelemetryClient.js';
|
|
7
|
-
export type { PerformanceTracker } from './types/PerformanceTracker.js';
|
|
8
|
-
export type { PerformanceRecorder } from './PerformanceRecorder.js';
|
|
9
|
-
export type { MetricEvent } from './types/MetricEvent.js';
|
|
10
|
-
export type { MetricEventAggregator } from './types/MetricEventAggregator.js';
|
|
11
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PerformanceRecorder } from '../PerformanceRecorder.js';
|
|
1
|
+
import type { Tracer } from '@opentelemetry/api';
|
|
3
2
|
export interface TelemetryClient {
|
|
4
|
-
/**
|
|
5
|
-
* Root span which measures the duration of the highest level application (ie: CLI)
|
|
6
|
-
*/
|
|
7
|
-
rootSpan: Span;
|
|
8
3
|
/**
|
|
9
4
|
* Flushes all telemetry and shuts down the telemetry client.
|
|
10
5
|
*/
|
|
@@ -14,9 +9,5 @@ export interface TelemetryClient {
|
|
|
14
9
|
* @returns the OpenTelemetry tracer
|
|
15
10
|
*/
|
|
16
11
|
get tracer(): Tracer;
|
|
17
|
-
/**
|
|
18
|
-
* Gets the performance recorder.
|
|
19
|
-
*/
|
|
20
|
-
performance: PerformanceRecorder;
|
|
21
12
|
}
|
|
22
13
|
//# sourceMappingURL=TelemetryClient.d.ts.map
|
|
@@ -22,9 +22,5 @@ export interface TelemetryOptions {
|
|
|
22
22
|
* Possible values: cli, bundler-service, etc.
|
|
23
23
|
*/
|
|
24
24
|
serviceName: string;
|
|
25
|
-
/**
|
|
26
|
-
* Name of the root span, 'root' will be used as a span name if this property is not set.
|
|
27
|
-
*/
|
|
28
|
-
rootSpanName?: string;
|
|
29
25
|
}
|
|
30
26
|
//# sourceMappingURL=TelemetryOptions.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/telemetry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { MetricEvent } from './types/MetricEvent.js';
|
|
2
|
-
import type { MetricEventAggregator } from './types/MetricEventAggregator.js';
|
|
3
|
-
export declare class MetricEventAggregatorRegistry {
|
|
4
|
-
private readonly _aggregators;
|
|
5
|
-
/**
|
|
6
|
-
* Registers a new aggregator. If an aggregator already exists, it will be return the aggregator.
|
|
7
|
-
* @param name - The name of the metric.
|
|
8
|
-
* @param aggregate - The aggregator function.
|
|
9
|
-
* @returns The aggregator that is passed in.
|
|
10
|
-
*/
|
|
11
|
-
register<T>(aggregator: MetricEventAggregator<T>): MetricEventAggregator<T>;
|
|
12
|
-
/**
|
|
13
|
-
* Gets all the aggregated events from all the registered aggregators.
|
|
14
|
-
* @returns The aggregated events.
|
|
15
|
-
*/
|
|
16
|
-
getAggregatedEvents(): MetricEvent[];
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=MetricEventAggregatorRegistry.d.ts.map
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Attributes, Span } from '@opentelemetry/api';
|
|
2
|
-
import type { PerformanceTracker } from './types/PerformanceTracker.js';
|
|
3
|
-
import type { MetricEventAggregator } from './types/MetricEventAggregator.js';
|
|
4
|
-
/**
|
|
5
|
-
* PerformanceRecorder is a utility class for recording performance metrics into telemetry.
|
|
6
|
-
*/
|
|
7
|
-
export declare class PerformanceRecorder {
|
|
8
|
-
private readonly span;
|
|
9
|
-
private readonly _metricEventAggregatorRegistry;
|
|
10
|
-
constructor(span: Span);
|
|
11
|
-
/**
|
|
12
|
-
* Registers a new aggregator for a given metric.
|
|
13
|
-
* If an aggregator already exists, it will be skipped.
|
|
14
|
-
* @param name - The name of the metric.
|
|
15
|
-
* @param aggregator - The aggregator function.
|
|
16
|
-
*/
|
|
17
|
-
registerAggregator<T>(aggregator: MetricEventAggregator<T>): MetricEventAggregator<T>;
|
|
18
|
-
/**
|
|
19
|
-
* Records a performance metric into telemetry. The metric will be recorded as an event on the span and logged to the console.
|
|
20
|
-
* It can be used for any situation where a performance metric (ie: how long does it take run something, or any other purpose) is needed.
|
|
21
|
-
* @param attributes
|
|
22
|
-
*/
|
|
23
|
-
record(attributes: {
|
|
24
|
-
name: string;
|
|
25
|
-
value: number;
|
|
26
|
-
additionalProperties?: Attributes;
|
|
27
|
-
}): void;
|
|
28
|
-
/**
|
|
29
|
-
* Tracks the execution time of a given `execute` function and report it to telemetry.
|
|
30
|
-
* @param name - The name of the performance metric.
|
|
31
|
-
* @param execute - The function to execute and track.
|
|
32
|
-
* @returns - The result of the `execute` function.
|
|
33
|
-
*/
|
|
34
|
-
track<T>(name: string, execute: (tracker: PerformanceTracker) => T): T;
|
|
35
|
-
track<T>(name: string, execute: (tracker: PerformanceTracker) => Promise<T>): Promise<T>;
|
|
36
|
-
/**
|
|
37
|
-
* Shuts down the performance recorder and records any aggregated events.
|
|
38
|
-
*/
|
|
39
|
-
shutdown(): void;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=PerformanceRecorder.d.ts.map
|