@ms-cloudpack/telemetry 0.4.4 → 0.4.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SpanEnrichingProcessor.js","sourceRoot":"","sources":["../../src/AppInsights/SpanEnrichingProcessor.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACjC,YAAoB,uBAA6C;QAA7C,4BAAuB,GAAvB,uBAAuB,CAAsB;IAAG,CAAC;IAErE,UAAU;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO;QACL,OAAO;IACT,CAAC;IAED,KAAK,CAAC,IAAkB;QACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,EAAE;YACzE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SAC9B;IACH,CAAC;CACF","sourcesContent":["import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport type { SpanAttributes } from '../types/SpanAttributes.js';\n\n/**\n * Span processor that adds shared attributes to all spans.\n */\nexport class SpanEnrichingProcessor implements SpanProcessor {\n constructor(private getSharedSpanAttributes: () => SpanAttributes) {}\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n\n onStart(): void {\n // noop\n }\n\n onEnd(span: ReadableSpan) {\n for (const [key, value] of Object.entries(this.getSharedSpanAttributes())) {\n span.attributes[key] = value;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"SpanEnrichingProcessor.js","sourceRoot":"","sources":["../../src/AppInsights/SpanEnrichingProcessor.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACjC,YAAoB,uBAA6C;QAA7C,4BAAuB,GAAvB,uBAAuB,CAAsB;IAAG,CAAC;IAErE,UAAU;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO;QACL,OAAO;IACT,CAAC;IAED,KAAK,CAAC,IAAkB;QACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,EAAE,CAAC;YAC1E,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC/B,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport type { SpanAttributes } from '../types/SpanAttributes.js';\n\n/**\n * Span processor that adds shared attributes to all spans.\n */\nexport class SpanEnrichingProcessor implements SpanProcessor {\n constructor(private getSharedSpanAttributes: () => SpanAttributes) {}\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n\n onStart(): void {\n // noop\n }\n\n onEnd(span: ReadableSpan) {\n for (const [key, value] of Object.entries(this.getSharedSpanAttributes())) {\n span.attributes[key] = value;\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"convertLogLevel.js","sourceRoot":"","sources":["../../src/AppInsights/convertLogLevel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,UAAU,eAAe,CAAC,QAAmB;IACjD,QAAQ,QAAQ,EAAE;QAChB,KAAK,OAAO;YACV,OAAO,YAAY,CAAC,KAAK,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,YAAY,CAAC,OAAO,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,YAAY,CAAC,IAAI,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,YAAY,CAAC,KAAK,CAAC;QAC5B,KAAK,KAAK;YACR,OAAO,YAAY,CAAC,GAAG,CAAC;QAC1B,KAAK,MAAM;YACT,OAAO,YAAY,CAAC,IAAI,CAAC;QAC3B,KAAK,MAAM,CAAC;QACZ;YACE,OAAO,YAAY,CAAC,IAAI,CAAC;KAC5B;AACH,CAAC","sourcesContent":["import { DiagLogLevel } from '@opentelemetry/api';\nimport type { LogLevel } from '../types/LogLevel.js';\n\nexport function convertLogLevel(logLevel?: LogLevel): DiagLogLevel {\n switch (logLevel) {\n case 'DEBUG':\n return DiagLogLevel.DEBUG;\n case 'VERBOSE':\n return DiagLogLevel.VERBOSE;\n case 'NONE':\n return DiagLogLevel.NONE;\n case 'ERROR':\n return DiagLogLevel.ERROR;\n case 'ALL':\n return DiagLogLevel.ALL;\n case 'INFO':\n return DiagLogLevel.INFO;\n case 'WARN':\n default:\n return DiagLogLevel.WARN;\n }\n}\n"]}
1
+ {"version":3,"file":"convertLogLevel.js","sourceRoot":"","sources":["../../src/AppInsights/convertLogLevel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,UAAU,eAAe,CAAC,QAAmB;IACjD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,YAAY,CAAC,KAAK,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,YAAY,CAAC,OAAO,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,YAAY,CAAC,IAAI,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,YAAY,CAAC,KAAK,CAAC;QAC5B,KAAK,KAAK;YACR,OAAO,YAAY,CAAC,GAAG,CAAC;QAC1B,KAAK,MAAM;YACT,OAAO,YAAY,CAAC,IAAI,CAAC;QAC3B,KAAK,MAAM,CAAC;QACZ;YACE,OAAO,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import { DiagLogLevel } from '@opentelemetry/api';\nimport type { LogLevel } from '../types/LogLevel.js';\n\nexport function convertLogLevel(logLevel?: LogLevel): DiagLogLevel {\n switch (logLevel) {\n case 'DEBUG':\n return DiagLogLevel.DEBUG;\n case 'VERBOSE':\n return DiagLogLevel.VERBOSE;\n case 'NONE':\n return DiagLogLevel.NONE;\n case 'ERROR':\n return DiagLogLevel.ERROR;\n case 'ALL':\n return DiagLogLevel.ALL;\n case 'INFO':\n return DiagLogLevel.INFO;\n case 'WARN':\n default:\n return DiagLogLevel.WARN;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getComputerName.js","sourceRoot":"","sources":["../../src/AppInsights/getComputerName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI;QACF,MAAM,mBAAmB,GAA+D;YACtF,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY;YACrC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE;SAC/D,CAAC;QAEF,MAAM,YAAY,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,QAAQ,EAAE,CAAC;QAE7E,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;KAC5B;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,IAAI,CAAC,iFAAiF,EAAE,CAAC,CAAC,CAAC;QAEnG,OAAO,QAAQ,EAAE,CAAC;KACnB;AACH,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport { hostname } from 'os';\n\n/**\n * Each OS has a different way of getting the computer name.\n * @returns computer name for the current OS, or the hostname if it cannot be determined\n */\nexport function getComputerName() {\n try {\n const computerNameGetters: Partial<Record<NodeJS.Platform, () => string | undefined>> = {\n win32: () => process.env.COMPUTERNAME,\n darwin: () => execSync('scutil --get ComputerName').toString(),\n };\n\n const computerName = computerNameGetters[process.platform]?.() || hostname();\n\n return computerName.trim();\n } catch (e) {\n console.warn('Unable to get OS specific computer name for telemetry, falling back to hostname', e);\n\n return hostname();\n }\n}\n"]}
1
+ {"version":3,"file":"getComputerName.js","sourceRoot":"","sources":["../../src/AppInsights/getComputerName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC;QACH,MAAM,mBAAmB,GAA+D;YACtF,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY;YACrC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE;SAC/D,CAAC;QAEF,MAAM,YAAY,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,QAAQ,EAAE,CAAC;QAE7E,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,iFAAiF,EAAE,CAAC,CAAC,CAAC;QAEnG,OAAO,QAAQ,EAAE,CAAC;IACpB,CAAC;AACH,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport { hostname } from 'os';\n\n/**\n * Each OS has a different way of getting the computer name.\n * @returns computer name for the current OS, or the hostname if it cannot be determined\n */\nexport function getComputerName() {\n try {\n const computerNameGetters: Partial<Record<NodeJS.Platform, () => string | undefined>> = {\n win32: () => process.env.COMPUTERNAME,\n darwin: () => execSync('scutil --get ComputerName').toString(),\n };\n\n const computerName = computerNameGetters[process.platform]?.() || hostname();\n\n return computerName.trim();\n } catch (e) {\n console.warn('Unable to get OS specific computer name for telemetry, falling back to hostname', e);\n\n return hostname();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MetricEventAggregatorRegistry.js","sourceRoot":"","sources":["../src/MetricEventAggregatorRegistry.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,6BAA6B;IAA1C;QACmB,iBAAY,GAAG,IAAI,GAAG,EAAkC,CAAC;IA4B5E,CAAC;IA1BC;;;;;OAKG;IACH,QAAQ,CAAI,UAAoC;QAC9C,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACtC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;SACnC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,mBAAmB;QACjB,MAAM,MAAM,GAAkB,EAAE,CAAC;QACjC,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;YAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC;SAClD;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import type { MetricEvent } from './types/MetricEvent.js';\nimport type { MetricEventAggregator } from './types/MetricEventAggregator.js';\n\nexport class MetricEventAggregatorRegistry {\n private readonly _aggregators = new Set<MetricEventAggregator<unknown>>();\n\n /**\n * Registers a new aggregator. If an aggregator already exists, it will be return the aggregator.\n * @param name - The name of the metric.\n * @param aggregate - The aggregator function.\n * @returns The aggregator that is passed in.\n */\n register<T>(aggregator: MetricEventAggregator<T>) {\n if (!this._aggregators.has(aggregator)) {\n this._aggregators.add(aggregator);\n }\n\n return aggregator;\n }\n\n /**\n * Gets all the aggregated events from all the registered aggregators.\n * @returns The aggregated events.\n */\n getAggregatedEvents(): MetricEvent[] {\n const events: MetricEvent[] = [];\n for (const aggregator of this._aggregators) {\n events.push(...aggregator.getAggregatedEvents());\n }\n\n return events;\n }\n}\n"]}
1
+ {"version":3,"file":"MetricEventAggregatorRegistry.js","sourceRoot":"","sources":["../src/MetricEventAggregatorRegistry.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,6BAA6B;IAA1C;QACmB,iBAAY,GAAG,IAAI,GAAG,EAAkC,CAAC;IA4B5E,CAAC;IA1BC;;;;;OAKG;IACH,QAAQ,CAAI,UAAoC;QAC9C,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,mBAAmB;QACjB,MAAM,MAAM,GAAkB,EAAE,CAAC;QACjC,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import type { MetricEvent } from './types/MetricEvent.js';\nimport type { MetricEventAggregator } from './types/MetricEventAggregator.js';\n\nexport class MetricEventAggregatorRegistry {\n private readonly _aggregators = new Set<MetricEventAggregator<unknown>>();\n\n /**\n * Registers a new aggregator. If an aggregator already exists, it will be return the aggregator.\n * @param name - The name of the metric.\n * @param aggregate - The aggregator function.\n * @returns The aggregator that is passed in.\n */\n register<T>(aggregator: MetricEventAggregator<T>) {\n if (!this._aggregators.has(aggregator)) {\n this._aggregators.add(aggregator);\n }\n\n return aggregator;\n }\n\n /**\n * Gets all the aggregated events from all the registered aggregators.\n * @returns The aggregated events.\n */\n getAggregatedEvents(): MetricEvent[] {\n const events: MetricEvent[] = [];\n for (const aggregator of this._aggregators) {\n events.push(...aggregator.getAggregatedEvents());\n }\n\n return events;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PerformanceRecorder.js","sourceRoot":"","sources":["../src/PerformanceRecorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAKnF;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAG9B,YAA6B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAFtB,mCAA8B,GAAG,IAAI,6BAA6B,EAAE,CAAC;IAE5C,CAAC;IAE3C;;;;;OAKG;IACH,kBAAkB,CAAI,UAAoC;QACxD,OAAO,IAAI,CAAC,8BAA8B,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,UAAkF;QACvF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,EAAE,EAAE,GAAG,oBAAoB,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACnF,OAAO,CAAC,KAAK,CAAC,uBAAuB,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAI,IAAY,EAAE,OAAoD;QAC/E,MAAM,oBAAoB,GAAmB,EAAE,CAAC;QAEhD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAEpC,MAAM,OAAO,GAAuB;YAClC,IAAI;YACJ,SAAS;YACT,aAAa,EAAE,CAAC,UAA0B,EAAE,EAAE;gBAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;oBACrD,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;iBACnC;YACH,CAAC;SACF,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAElF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,8BAA8B,CAAC,mBAAmB,EAAE,EAAE;YACnG,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAC,CAAC;SAChE;IACH,CAAC;CACF","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { performance } from 'perf_hooks';\nimport { MetricEventAggregatorRegistry } from './MetricEventAggregatorRegistry.js';\nimport type { PerformanceTracker } from './types/PerformanceTracker.js';\nimport type { SpanAttributes } from './types/SpanAttributes.js';\nimport type { MetricEventAggregator } from './types/MetricEventAggregator.js';\n\n/**\n * PerformanceRecorder is a utility class for recording performance metrics into telemetry.\n */\nexport class PerformanceRecorder {\n private readonly _metricEventAggregatorRegistry = new MetricEventAggregatorRegistry();\n\n constructor(private readonly span: Span) {}\n\n /**\n * Registers a new aggregator for a given metric.\n * If an aggregator already exists, it will be skipped.\n * @param name - The name of the metric.\n * @param aggregator - The aggregator function.\n */\n registerAggregator<T>(aggregator: MetricEventAggregator<T>) {\n return this._metricEventAggregatorRegistry.register(aggregator);\n }\n\n /**\n * Records a performance metric into telemetry. The metric will be recorded as an event on the span and logged to the console.\n * 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.\n * @param attributes\n */\n record(attributes: { name: string; value: number; additionalProperties?: SpanAttributes }): void {\n const { name, value, additionalProperties = {} } = attributes;\n this.span.addEvent('Performance-Metric', { ...additionalProperties, name, value });\n console.debug(`Performance-Metric: ${name} ${value}`);\n }\n\n /**\n * Tracks the execution time of a given `execute` function and report it to telemetry.\n * @param name - The name of the performance metric.\n * @param execute - The function to execute and track.\n * @returns - The result of the `execute` function.\n */\n async track<T>(name: string, execute: (tracker: PerformanceTracker) => Promise<T>): Promise<T> {\n const additionalProperties: SpanAttributes = {};\n\n const startTime = performance.now();\n\n const tracker: PerformanceTracker = {\n name,\n startTime,\n setProperties: (properties: SpanAttributes) => {\n for (const [key, value] of Object.entries(properties)) {\n additionalProperties[key] = value;\n }\n },\n };\n\n const result = await execute(tracker);\n\n this.record({ name, value: performance.now() - startTime, additionalProperties });\n\n return result;\n }\n\n /**\n * Shuts down the performance recorder and records any aggregated events.\n */\n shutdown(): void {\n for (const { name, value, attributes } of this._metricEventAggregatorRegistry.getAggregatedEvents()) {\n this.record({ name, value, additionalProperties: attributes });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"PerformanceRecorder.js","sourceRoot":"","sources":["../src/PerformanceRecorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAKnF;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAG9B,YAA6B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAFtB,mCAA8B,GAAG,IAAI,6BAA6B,EAAE,CAAC;IAE5C,CAAC;IAE3C;;;;;OAKG;IACH,kBAAkB,CAAI,UAAoC;QACxD,OAAO,IAAI,CAAC,8BAA8B,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,UAAkF;QACvF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,EAAE,EAAE,GAAG,oBAAoB,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACnF,OAAO,CAAC,KAAK,CAAC,uBAAuB,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAI,IAAY,EAAE,OAAoD;QAC/E,MAAM,oBAAoB,GAAmB,EAAE,CAAC;QAEhD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAEpC,MAAM,OAAO,GAAuB;YAClC,IAAI;YACJ,SAAS;YACT,aAAa,EAAE,CAAC,UAA0B,EAAE,EAAE;gBAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;oBACtD,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACpC,CAAC;YACH,CAAC;SACF,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAElF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,8BAA8B,CAAC,mBAAmB,EAAE,EAAE,CAAC;YACpG,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { performance } from 'perf_hooks';\nimport { MetricEventAggregatorRegistry } from './MetricEventAggregatorRegistry.js';\nimport type { PerformanceTracker } from './types/PerformanceTracker.js';\nimport type { SpanAttributes } from './types/SpanAttributes.js';\nimport type { MetricEventAggregator } from './types/MetricEventAggregator.js';\n\n/**\n * PerformanceRecorder is a utility class for recording performance metrics into telemetry.\n */\nexport class PerformanceRecorder {\n private readonly _metricEventAggregatorRegistry = new MetricEventAggregatorRegistry();\n\n constructor(private readonly span: Span) {}\n\n /**\n * Registers a new aggregator for a given metric.\n * If an aggregator already exists, it will be skipped.\n * @param name - The name of the metric.\n * @param aggregator - The aggregator function.\n */\n registerAggregator<T>(aggregator: MetricEventAggregator<T>) {\n return this._metricEventAggregatorRegistry.register(aggregator);\n }\n\n /**\n * Records a performance metric into telemetry. The metric will be recorded as an event on the span and logged to the console.\n * 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.\n * @param attributes\n */\n record(attributes: { name: string; value: number; additionalProperties?: SpanAttributes }): void {\n const { name, value, additionalProperties = {} } = attributes;\n this.span.addEvent('Performance-Metric', { ...additionalProperties, name, value });\n console.debug(`Performance-Metric: ${name} ${value}`);\n }\n\n /**\n * Tracks the execution time of a given `execute` function and report it to telemetry.\n * @param name - The name of the performance metric.\n * @param execute - The function to execute and track.\n * @returns - The result of the `execute` function.\n */\n async track<T>(name: string, execute: (tracker: PerformanceTracker) => Promise<T>): Promise<T> {\n const additionalProperties: SpanAttributes = {};\n\n const startTime = performance.now();\n\n const tracker: PerformanceTracker = {\n name,\n startTime,\n setProperties: (properties: SpanAttributes) => {\n for (const [key, value] of Object.entries(properties)) {\n additionalProperties[key] = value;\n }\n },\n };\n\n const result = await execute(tracker);\n\n this.record({ name, value: performance.now() - startTime, additionalProperties });\n\n return result;\n }\n\n /**\n * Shuts down the performance recorder and records any aggregated events.\n */\n shutdown(): void {\n for (const { name, value, attributes } of this._metricEventAggregatorRegistry.getAggregatedEvents()) {\n this.record({ name, value, additionalProperties: attributes });\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createTelemetryClient.js","sourceRoot":"","sources":["../src/createTelemetryClient.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAyB;IACnE,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;QAC7B,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAEzE,wEAAwE;QACxE,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAC;QAC9E,OAAO,IAAI,mBAAmB,EAAE,CAAC;KAClC;IAED,0EAA0E;IAC1E,OAAO,CAAC,GAAG,CAAC,iDAAiD,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC;IAE3F,yDAAyD;IACzD,MAAM,EAAE,0BAA0B,EAAE,GAAG,MAAM,MAAM,CAAC,6CAA6C,CAAC,CAAC;IACnG,OAAO,IAAI,0BAA0B,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type { TelemetryOptions } from './types/TelemetryOptions.js';\nimport type { TelemetryClient } from './types/TelemetryClient.js';\n\nexport async function createTelemetryClient(options: TelemetryOptions): Promise<TelemetryClient> {\n if (!options.connectionString) {\n console.debug('No connection string found. Telemetry will not be sent.');\n\n // Create a no-op telemetry client if no instrumentation key is provided\n const { NoOpTelemetryClient } = await import('./NoOp/NoOpTelemetryClient.js');\n return new NoOpTelemetryClient();\n }\n\n // Set initial log level to WARN to avoid logging telemetry initialization\n process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL = options.logLevel || 'WARN';\n\n // Import TelemetryClient after setting initial log level\n const { AppInsightsTelemetryClient } = await import('./AppInsights/AppInsightsTelemetryClient.js');\n return new AppInsightsTelemetryClient(options);\n}\n"]}
1
+ {"version":3,"file":"createTelemetryClient.js","sourceRoot":"","sources":["../src/createTelemetryClient.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAyB;IACnE,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAEzE,wEAAwE;QACxE,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAC;QAC9E,OAAO,IAAI,mBAAmB,EAAE,CAAC;IACnC,CAAC;IAED,0EAA0E;IAC1E,OAAO,CAAC,GAAG,CAAC,iDAAiD,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC;IAE3F,yDAAyD;IACzD,MAAM,EAAE,0BAA0B,EAAE,GAAG,MAAM,MAAM,CAAC,6CAA6C,CAAC,CAAC;IACnG,OAAO,IAAI,0BAA0B,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type { TelemetryOptions } from './types/TelemetryOptions.js';\nimport type { TelemetryClient } from './types/TelemetryClient.js';\n\nexport async function createTelemetryClient(options: TelemetryOptions): Promise<TelemetryClient> {\n if (!options.connectionString) {\n console.debug('No connection string found. Telemetry will not be sent.');\n\n // Create a no-op telemetry client if no instrumentation key is provided\n const { NoOpTelemetryClient } = await import('./NoOp/NoOpTelemetryClient.js');\n return new NoOpTelemetryClient();\n }\n\n // Set initial log level to WARN to avoid logging telemetry initialization\n process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL = options.logLevel || 'WARN';\n\n // Import TelemetryClient after setting initial log level\n const { AppInsightsTelemetryClient } = await import('./AppInsights/AppInsightsTelemetryClient.js');\n return new AppInsightsTelemetryClient(options);\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.1"
8
+ "packageVersion": "7.39.4"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/telemetry",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Helpers for logging tasks to the console.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,12 +14,12 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@azure/monitor-opentelemetry": "^1.1.0",
17
+ "@azure/monitor-opentelemetry": "~1.2.0",
18
18
  "@opentelemetry/api": "^1.7.0",
19
- "@opentelemetry/resources": "^1.18.0",
20
- "@opentelemetry/sdk-trace-base": "^1.18.0",
21
- "@opentelemetry/sdk-trace-node": "^1.18.0",
22
- "@opentelemetry/semantic-conventions": "^1.18.0"
19
+ "@opentelemetry/resources": "~1.21.0",
20
+ "@opentelemetry/sdk-trace-base": "~1.21.0",
21
+ "@opentelemetry/sdk-trace-node": "~1.21.0",
22
+ "@opentelemetry/semantic-conventions": "~1.21.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@ms-cloudpack/eslint-plugin-internal": "*",