@ms-cloudpack/telemetry 0.3.7 → 0.3.9

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.
Files changed (36) hide show
  1. package/lib/AppInsights/AppInsightsTelemetryClient.d.ts +6 -3
  2. package/lib/AppInsights/AppInsightsTelemetryClient.d.ts.map +1 -1
  3. package/lib/AppInsights/AppInsightsTelemetryClient.js +17 -15
  4. package/lib/AppInsights/AppInsightsTelemetryClient.js.map +1 -1
  5. package/lib/AppInsights/getAppInsightsConfig.d.ts +2 -2
  6. package/lib/AppInsights/getAppInsightsConfig.d.ts.map +1 -1
  7. package/lib/AppInsights/getAppInsightsConfig.js +16 -32
  8. package/lib/AppInsights/getAppInsightsConfig.js.map +1 -1
  9. package/lib/NoOp/NoOpTelemetryClient.d.ts +2 -0
  10. package/lib/NoOp/NoOpTelemetryClient.d.ts.map +1 -1
  11. package/lib/NoOp/NoOpTelemetryClient.js +2 -0
  12. package/lib/NoOp/NoOpTelemetryClient.js.map +1 -1
  13. package/lib/PerformanceRecorder.d.ts +28 -0
  14. package/lib/PerformanceRecorder.d.ts.map +1 -0
  15. package/lib/PerformanceRecorder.js +42 -0
  16. package/lib/PerformanceRecorder.js.map +1 -0
  17. package/lib/createNoOpTelemetryClient.d.ts +3 -0
  18. package/lib/createNoOpTelemetryClient.d.ts.map +1 -0
  19. package/lib/createNoOpTelemetryClient.js +5 -0
  20. package/lib/createNoOpTelemetryClient.js.map +1 -0
  21. package/lib/index.d.ts +4 -1
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +1 -1
  24. package/lib/index.js.map +1 -1
  25. package/lib/types/PerformanceTracker.d.ts +7 -0
  26. package/lib/types/PerformanceTracker.d.ts.map +1 -0
  27. package/lib/types/PerformanceTracker.js +2 -0
  28. package/lib/types/PerformanceTracker.js.map +1 -0
  29. package/lib/types/SpanAttributes.d.ts +2 -0
  30. package/lib/types/SpanAttributes.d.ts.map +1 -0
  31. package/lib/types/SpanAttributes.js +2 -0
  32. package/lib/types/SpanAttributes.js.map +1 -0
  33. package/lib/types/TelemetryClient.d.ts +5 -0
  34. package/lib/types/TelemetryClient.d.ts.map +1 -1
  35. package/lib/types/TelemetryClient.js.map +1 -1
  36. package/package.json +7 -7
@@ -1,11 +1,14 @@
1
- import type { Span, Tracer } from '@opentelemetry/api';
2
- import type { TelemetryOptions } from '../types/TelemetryOptions.js';
1
+ import { type Span, type Tracer } from '@opentelemetry/api';
2
+ import { PerformanceRecorder } from '../PerformanceRecorder.js';
3
3
  import type { TelemetryClient } from '../types/TelemetryClient.js';
4
+ import type { TelemetryOptions } from '../types/TelemetryOptions.js';
4
5
  export declare class AppInsightsTelemetryClient implements TelemetryClient {
6
+ private readonly _performance;
5
7
  private readonly _rootSpan;
6
- private readonly appInsightsClient;
7
8
  private readonly sharedSpanAttributes;
9
+ private readonly _traceProvider;
8
10
  constructor(options: TelemetryOptions);
11
+ get performance(): PerformanceRecorder;
9
12
  get rootSpan(): Span;
10
13
  /**
11
14
  * Sets a shared attribute that will be added to all spans.
@@ -1 +1 @@
1
- {"version":3,"file":"AppInsightsTelemetryClient.d.ts","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAMvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;IACjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA4B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA8B;gBAEvD,OAAO,EAAE,gBAAgB;IAqBrC,IAAW,QAAQ,IAAI,IAAI,CAE1B;IAED;;;;OAIG;IACI,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIxD;;OAEG;IACU,QAAQ;IAMrB;;;OAGG;IACI,SAAS,IAAI,MAAM;CAG3B"}
1
+ {"version":3,"file":"AppInsightsTelemetryClient.d.ts","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIrE,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;IACjC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA8B;IACnE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqB;gBAExC,OAAO,EAAE,gBAAgB;IAoBrC,IAAW,WAAW,IAAI,mBAAmB,CAE5C;IAED,IAAW,QAAQ,IAAI,IAAI,CAE1B;IAED;;;;OAIG;IACI,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIxD;;OAEG;IACU,QAAQ;IAMrB;;;OAGG;IACI,SAAS,IAAI,MAAM;CAG3B"}
@@ -1,23 +1,25 @@
1
- import { ApplicationInsightsClient } from 'applicationinsights';
2
- import { convertLogLevel } from './convertLogLevel.js';
3
- import { getAppInsightsConfig } from './getAppInsightsConfig.js';
1
+ import { shutdownAzureMonitor, useAzureMonitor } from '@azure/monitor-opentelemetry';
2
+ import { trace } from '@opentelemetry/api';
3
+ import { PerformanceRecorder } from '../PerformanceRecorder.js';
4
4
  import { SpanEnrichingProcessor } from './SpanEnrichingProcessor.js';
5
+ import { getAppInsightsConfig } from './getAppInsightsConfig.js';
5
6
  export class AppInsightsTelemetryClient {
6
7
  constructor(options) {
7
8
  this.sharedSpanAttributes = {};
8
9
  const config = getAppInsightsConfig(options);
9
- this.appInsightsClient = new ApplicationInsightsClient(config);
10
- this.appInsightsClient.getLogger().updateLogLevel(convertLogLevel(options.logLevel));
10
+ // Set up azure monitor (aka application insights)
11
+ useAzureMonitor(config);
12
+ this._traceProvider = trace.getTracerProvider().getDelegate();
11
13
  // Set shared attributes
12
14
  this.setSharedSpanAttribute('version', options.productVersion);
13
15
  // Set SpanEnrichingProcessor to add shared attributes to all spans
14
- const nodeTraceProvider = this.appInsightsClient.getTraceHandler().getTracerProvider();
15
- nodeTraceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));
16
+ this._traceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));
16
17
  // Create root span
17
- this._rootSpan = this.appInsightsClient
18
- .getTraceHandler()
19
- .getTracer()
20
- .startSpan(options.rootSpanName || 'root');
18
+ this._rootSpan = this.getTracer().startSpan(options.rootSpanName || 'root');
19
+ this._performance = new PerformanceRecorder(this._rootSpan);
20
+ }
21
+ get performance() {
22
+ return this._performance;
21
23
  }
22
24
  get rootSpan() {
23
25
  return this._rootSpan;
@@ -34,16 +36,16 @@ export class AppInsightsTelemetryClient {
34
36
  * Flushes all telemetry and shuts down the telemetry client.
35
37
  */
36
38
  async shutdown() {
37
- this._rootSpan.end();
38
- await this.appInsightsClient?.flush();
39
- await this.appInsightsClient?.shutdown();
39
+ this.rootSpan.end();
40
+ await this._traceProvider.forceFlush();
41
+ shutdownAzureMonitor();
40
42
  }
41
43
  /**
42
44
  * Gets the OpenTelemetry tracer.
43
45
  * @returns the OpenTelemetry tracer
44
46
  */
45
47
  getTracer() {
46
- return this.appInsightsClient?.getTraceHandler().getTracer();
48
+ return trace.getTracer('cloudpack-tracer');
47
49
  }
48
50
  }
49
51
  //# sourceMappingURL=AppInsightsTelemetryClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppInsightsTelemetryClient.js","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAIrE,MAAM,OAAO,0BAA0B;IAKrC,YAAY,OAAyB;QAFpB,yBAAoB,GAA2B,EAAE,CAAC;QAGjE,MAAM,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC,iBAAiB,GAAG,IAAI,yBAAyB,CAAC,MAAM,CAAC,CAAC;QAE/D,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAErF,wBAAwB;QACxB,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;QAE/D,mEAAmE;QACnE,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,eAAe,EAAE,CAAC,iBAAiB,EAAwB,CAAC;QAC7G,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,sBAAsB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAEhG,mBAAmB;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,iBAAiB;aACpC,eAAe,EAAE;aACjB,SAAS,EAAE;aACX,SAAS,CAAC,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,sBAAsB,CAAC,GAAW,EAAE,KAAa;QACtD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QACrB,MAAM,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,CAAC;QACtC,MAAM,IAAI,CAAC,iBAAiB,EAAE,QAAQ,EAAE,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,iBAAiB,EAAE,eAAe,EAAE,CAAC,SAAS,EAAE,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\nimport type { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';\nimport { ApplicationInsightsClient } from 'applicationinsights';\nimport { convertLogLevel } from './convertLogLevel.js';\nimport { getAppInsightsConfig } from './getAppInsightsConfig.js';\nimport { SpanEnrichingProcessor } from './SpanEnrichingProcessor.js';\nimport type { TelemetryOptions } from '../types/TelemetryOptions.js';\nimport type { TelemetryClient } from '../types/TelemetryClient.js';\n\nexport class AppInsightsTelemetryClient implements TelemetryClient {\n private readonly _rootSpan: Span;\n private readonly appInsightsClient: ApplicationInsightsClient;\n private readonly sharedSpanAttributes: Record<string, string> = {};\n\n constructor(options: TelemetryOptions) {\n const config = getAppInsightsConfig(options);\n\n this.appInsightsClient = new ApplicationInsightsClient(config);\n\n this.appInsightsClient.getLogger().updateLogLevel(convertLogLevel(options.logLevel));\n\n // Set shared attributes\n this.setSharedSpanAttribute('version', options.productVersion);\n\n // Set SpanEnrichingProcessor to add shared attributes to all spans\n const nodeTraceProvider = this.appInsightsClient.getTraceHandler().getTracerProvider() as NodeTracerProvider;\n nodeTraceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));\n\n // Create root span\n this._rootSpan = this.appInsightsClient\n .getTraceHandler()\n .getTracer()\n .startSpan(options.rootSpanName || 'root');\n }\n\n public get rootSpan(): Span {\n return this._rootSpan;\n }\n\n /**\n * Sets a shared attribute that will be added to all spans.\n * @param key - key of the attribute\n * @param value - value of the attribute\n */\n public setSharedSpanAttribute(key: string, value: string) {\n this.sharedSpanAttributes[key] = value;\n }\n\n /**\n * Flushes all telemetry and shuts down the telemetry client.\n */\n public async shutdown() {\n this._rootSpan.end();\n await this.appInsightsClient?.flush();\n await this.appInsightsClient?.shutdown();\n }\n\n /**\n * Gets the OpenTelemetry tracer.\n * @returns the OpenTelemetry tracer\n */\n public getTracer(): Tracer {\n return this.appInsightsClient?.getTraceHandler().getTracer();\n }\n}\n"]}
1
+ {"version":3,"file":"AppInsightsTelemetryClient.js","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,KAAK,EAAoD,MAAM,oBAAoB,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,OAAO,0BAA0B;IAMrC,YAAY,OAAyB;QAHpB,yBAAoB,GAA2B,EAAE,CAAC;QAIjE,MAAM,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE7C,kDAAkD;QAClD,eAAe,CAAC,MAAM,CAAC,CAAC;QAExB,IAAI,CAAC,cAAc,GAAI,KAAK,CAAC,iBAAiB,EAA0B,CAAC,WAAW,EAAwB,CAAC;QAE7G,wBAAwB;QACxB,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;QAE/D,mEAAmE;QACnE,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,IAAI,sBAAsB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAElG,mBAAmB;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC;QAE5E,IAAI,CAAC,YAAY,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,sBAAsB,CAAC,GAAW,EAAE,KAAa;QACtD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACpB,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QACvC,oBAAoB,EAAE,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,KAAK,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import { shutdownAzureMonitor, useAzureMonitor } from '@azure/monitor-opentelemetry';\nimport { trace, type ProxyTracerProvider, type Span, type Tracer } from '@opentelemetry/api';\nimport type { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';\nimport { PerformanceRecorder } from '../PerformanceRecorder.js';\nimport type { TelemetryClient } from '../types/TelemetryClient.js';\nimport type { TelemetryOptions } from '../types/TelemetryOptions.js';\nimport { SpanEnrichingProcessor } from './SpanEnrichingProcessor.js';\nimport { getAppInsightsConfig } from './getAppInsightsConfig.js';\n\nexport class AppInsightsTelemetryClient implements TelemetryClient {\n private readonly _performance: PerformanceRecorder;\n private readonly _rootSpan: Span;\n private readonly sharedSpanAttributes: Record<string, string> = {};\n private readonly _traceProvider: NodeTracerProvider;\n\n constructor(options: TelemetryOptions) {\n const config = getAppInsightsConfig(options);\n\n // Set up azure monitor (aka application insights)\n useAzureMonitor(config);\n\n this._traceProvider = (trace.getTracerProvider() as ProxyTracerProvider).getDelegate() as NodeTracerProvider;\n\n // Set shared attributes\n this.setSharedSpanAttribute('version', options.productVersion);\n\n // Set SpanEnrichingProcessor to add shared attributes to all spans\n this._traceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));\n\n // Create root span\n this._rootSpan = this.getTracer().startSpan(options.rootSpanName || 'root');\n\n this._performance = new PerformanceRecorder(this._rootSpan);\n }\n\n public get performance(): PerformanceRecorder {\n return this._performance;\n }\n\n public get rootSpan(): Span {\n return this._rootSpan;\n }\n\n /**\n * Sets a shared attribute that will be added to all spans.\n * @param key - key of the attribute\n * @param value - value of the attribute\n */\n public setSharedSpanAttribute(key: string, value: string) {\n this.sharedSpanAttributes[key] = value;\n }\n\n /**\n * Flushes all telemetry and shuts down the telemetry client.\n */\n public async shutdown() {\n this.rootSpan.end();\n await this._traceProvider.forceFlush();\n shutdownAzureMonitor();\n }\n\n /**\n * Gets the OpenTelemetry tracer.\n * @returns the OpenTelemetry tracer\n */\n public getTracer(): Tracer {\n return trace.getTracer('cloudpack-tracer');\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { ApplicationInsightsConfig } from 'applicationinsights';
1
+ import type { AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';
2
2
  import type { TelemetryOptions } from '../types/TelemetryOptions.js';
3
- export declare function getAppInsightsConfig(options: TelemetryOptions): ApplicationInsightsConfig;
3
+ export declare function getAppInsightsConfig(options: TelemetryOptions): AzureMonitorOpenTelemetryOptions;
4
4
  //# sourceMappingURL=getAppInsightsConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAppInsightsConfig.d.ts","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AASrE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,6BAsC7D"}
1
+ {"version":3,"file":"getAppInsightsConfig.d.ts","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAGrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AASrE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,oCAuB7D"}
@@ -1,6 +1,5 @@
1
1
  import Resources from '@opentelemetry/resources';
2
2
  import SemanticConventions from '@opentelemetry/semantic-conventions';
3
- import { ApplicationInsightsConfig } from 'applicationinsights';
4
3
  import { createHash } from 'crypto';
5
4
  import { getComputerName } from './getComputerName.js';
6
5
  const { Resource } = Resources;
@@ -9,40 +8,25 @@ function sha256(input) {
9
8
  return createHash('sha256').update(input).digest('hex');
10
9
  }
11
10
  export function getAppInsightsConfig(options) {
12
- const config = new ApplicationInsightsConfig();
13
- config.azureMonitorExporterConfig = {
14
- ...(config.azureMonitorExporterConfig || {}),
15
- connectionString: `InstrumentationKey=${options.instrumentationKey}`,
16
- };
17
- config.enableAutoCollectExceptions = false;
18
- config.enableAutoCollectHeartbeat = false;
19
- config.enableAutoCollectPerformance = false;
20
- config.enableAutoCollectStandardMetrics = false;
21
- config.instrumentations = {
22
- http: {
23
- enabled: false,
24
- },
25
- azureSdk: {
26
- enabled: false,
27
- },
28
- };
29
- config.logInstrumentations = {
30
- bunyan: {
31
- enabled: false,
32
- },
33
- console: {
34
- enabled: false,
11
+ const config = {
12
+ azureMonitorExporterOptions: {
13
+ connectionString: 'InstrumentationKey=d512a3ac-e644-47b8-895a-4a9a25778aaf;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com',
35
14
  },
36
- winston: {
37
- enabled: false,
15
+ instrumentationOptions: {
16
+ http: {
17
+ enabled: false,
18
+ },
19
+ azureSdk: {
20
+ enabled: false,
21
+ },
38
22
  },
23
+ resource: new Resource({
24
+ // Use a hash of the computer name to avoid PII
25
+ [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),
26
+ [SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,
27
+ [SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,
28
+ }),
39
29
  };
40
- config.resource = new Resource({
41
- // Use a hash of the computer name to avoid PII
42
- [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),
43
- [SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,
44
- [SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,
45
- });
46
30
  return config;
47
31
  }
48
32
  //# sourceMappingURL=getAppInsightsConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAppInsightsConfig.js","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,0BAA0B,CAAC;AACjD,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAC/B,MAAM,EAAE,0BAA0B,EAAE,GAAG,mBAAmB,CAAC;AAE3D,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,MAAM,GAAG,IAAI,yBAAyB,EAAE,CAAC;IAC/C,MAAM,CAAC,0BAA0B,GAAG;QAClC,GAAG,CAAC,MAAM,CAAC,0BAA0B,IAAI,EAAE,CAAC;QAC5C,gBAAgB,EAAE,sBAAsB,OAAO,CAAC,kBAAkB,EAAE;KACrE,CAAC;IACF,MAAM,CAAC,2BAA2B,GAAG,KAAK,CAAC;IAC3C,MAAM,CAAC,0BAA0B,GAAG,KAAK,CAAC;IAC1C,MAAM,CAAC,4BAA4B,GAAG,KAAK,CAAC;IAC5C,MAAM,CAAC,gCAAgC,GAAG,KAAK,CAAC;IAChD,MAAM,CAAC,gBAAgB,GAAG;QACxB,IAAI,EAAE;YACJ,OAAO,EAAE,KAAK;SACf;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,KAAK;SACf;KACF,CAAC;IACF,MAAM,CAAC,mBAAmB,GAAG;QAC3B,MAAM,EAAE;YACN,OAAO,EAAE,KAAK;SACf;QACD,OAAO,EAAE;YACP,OAAO,EAAE,KAAK;SACf;QACD,OAAO,EAAE;YACP,OAAO,EAAE,KAAK;SACf;KACF,CAAC;IAEF,MAAM,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC;QAC7B,+CAA+C;QAC/C,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QAC3E,CAAC,0BAA0B,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,WAAW;QAC9D,CAAC,0BAA0B,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,gBAAgB;KACzE,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import Resources from '@opentelemetry/resources';\nimport SemanticConventions from '@opentelemetry/semantic-conventions';\nimport { ApplicationInsightsConfig } from 'applicationinsights';\nimport { createHash } from 'crypto';\nimport { getComputerName } from './getComputerName.js';\nimport type { TelemetryOptions } from '../types/TelemetryOptions.js';\n\nconst { Resource } = Resources;\nconst { SemanticResourceAttributes } = SemanticConventions;\n\nfunction sha256(input: string) {\n return createHash('sha256').update(input).digest('hex');\n}\n\nexport function getAppInsightsConfig(options: TelemetryOptions) {\n const config = new ApplicationInsightsConfig();\n config.azureMonitorExporterConfig = {\n ...(config.azureMonitorExporterConfig || {}),\n connectionString: `InstrumentationKey=${options.instrumentationKey}`,\n };\n config.enableAutoCollectExceptions = false;\n config.enableAutoCollectHeartbeat = false;\n config.enableAutoCollectPerformance = false;\n config.enableAutoCollectStandardMetrics = false;\n config.instrumentations = {\n http: {\n enabled: false,\n },\n azureSdk: {\n enabled: false,\n },\n };\n config.logInstrumentations = {\n bunyan: {\n enabled: false,\n },\n console: {\n enabled: false,\n },\n winston: {\n enabled: false,\n },\n };\n\n config.resource = new Resource({\n // Use a hash of the computer name to avoid PII\n [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),\n [SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,\n [SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,\n });\n\n return config;\n}\n"]}
1
+ {"version":3,"file":"getAppInsightsConfig.js","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,0BAA0B,CAAC;AACjD,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAC/B,MAAM,EAAE,0BAA0B,EAAE,GAAG,mBAAmB,CAAC;AAE3D,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,MAAM,GAAqC;QAC/C,2BAA2B,EAAE;YAC3B,gBAAgB,EACd,6HAA6H;SAChI;QACD,sBAAsB,EAAE;YACtB,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;aACf;YACD,QAAQ,EAAE;gBACR,OAAO,EAAE,KAAK;aACf;SACF;QACD,QAAQ,EAAE,IAAI,QAAQ,CAAC;YACrB,+CAA+C;YAC/C,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;YAC3E,CAAC,0BAA0B,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,WAAW;YAC9D,CAAC,0BAA0B,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,gBAAgB;SACzE,CAAC;KACH,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import Resources from '@opentelemetry/resources';\nimport SemanticConventions from '@opentelemetry/semantic-conventions';\nimport type { AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';\nimport { createHash } from 'crypto';\nimport { getComputerName } from './getComputerName.js';\nimport type { TelemetryOptions } from '../types/TelemetryOptions.js';\n\nconst { Resource } = Resources;\nconst { SemanticResourceAttributes } = SemanticConventions;\n\nfunction sha256(input: string) {\n return createHash('sha256').update(input).digest('hex');\n}\n\nexport function getAppInsightsConfig(options: TelemetryOptions) {\n const config: AzureMonitorOpenTelemetryOptions = {\n azureMonitorExporterOptions: {\n connectionString:\n 'InstrumentationKey=d512a3ac-e644-47b8-895a-4a9a25778aaf;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com',\n },\n instrumentationOptions: {\n http: {\n enabled: false,\n },\n azureSdk: {\n enabled: false,\n },\n },\n resource: new Resource({\n // Use a hash of the computer name to avoid PII\n [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),\n [SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,\n [SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,\n }),\n };\n\n return config;\n}\n"]}
@@ -1,12 +1,14 @@
1
1
  import type { Span } from '@opentelemetry/api';
2
2
  import type { TelemetryClient } from '../types/TelemetryClient.js';
3
3
  import { NoOpTracer } from './NoOpTracer.js';
4
+ import { PerformanceRecorder } from '../PerformanceRecorder.js';
4
5
  /**
5
6
  * No-op implementation of {@link TelemetryClient}.
6
7
  * This class will be used when Telemetry is disabled.
7
8
  */
8
9
  export declare class NoOpTelemetryClient implements TelemetryClient {
9
10
  readonly rootSpan: Span;
11
+ readonly performance: PerformanceRecorder;
10
12
  private tracer;
11
13
  setSharedSpanAttribute(): TelemetryClient;
12
14
  shutdown(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"NoOpTelemetryClient.d.ts","sourceRoot":"","sources":["../../src/NoOp/NoOpTelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAoB;IAElC,sBAAsB,IAAI,eAAe;IAKzC,QAAQ;IAKR,SAAS;CAGV"}
1
+ {"version":3,"file":"NoOpTelemetryClient.d.ts","sourceRoot":"","sources":["../../src/NoOp/NoOpTelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAkB;IACzC,QAAQ,CAAC,WAAW,sBAA0C;IAC9D,OAAO,CAAC,MAAM,CAAoB;IAElC,sBAAsB,IAAI,eAAe;IAKzC,QAAQ;IAKR,SAAS;CAGV"}
@@ -1,5 +1,6 @@
1
1
  import { NoOpTracer } from './NoOpTracer.js';
2
2
  import { NoOpSpan } from './NoOpSpan.js';
3
+ import { PerformanceRecorder } from '../PerformanceRecorder.js';
3
4
  /**
4
5
  * No-op implementation of {@link TelemetryClient}.
5
6
  * This class will be used when Telemetry is disabled.
@@ -7,6 +8,7 @@ import { NoOpSpan } from './NoOpSpan.js';
7
8
  export class NoOpTelemetryClient {
8
9
  constructor() {
9
10
  this.rootSpan = new NoOpSpan();
11
+ this.performance = new PerformanceRecorder(this.rootSpan);
10
12
  this.tracer = new NoOpTracer();
11
13
  }
12
14
  setSharedSpanAttribute() {
@@ -1 +1 @@
1
- {"version":3,"file":"NoOpTelemetryClient.js","sourceRoot":"","sources":["../../src/NoOp/NoOpTelemetryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QACW,aAAQ,GAAS,IAAI,QAAQ,EAAE,CAAC;QACjC,WAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAepC,CAAC;IAbC,sBAAsB;QACpB,QAAQ;QACR,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,QAAQ;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport type { TelemetryClient } from '../types/TelemetryClient.js';\nimport { NoOpTracer } from './NoOpTracer.js';\nimport { NoOpSpan } from './NoOpSpan.js';\n\n/**\n * No-op implementation of {@link TelemetryClient}.\n * This class will be used when Telemetry is disabled.\n */\nexport class NoOpTelemetryClient implements TelemetryClient {\n readonly rootSpan: Span = new NoOpSpan();\n private tracer = new NoOpTracer();\n\n setSharedSpanAttribute(): TelemetryClient {\n // No-op\n return this;\n }\n\n shutdown() {\n // No-op\n return Promise.resolve();\n }\n\n getTracer() {\n return this.tracer;\n }\n}\n"]}
1
+ {"version":3,"file":"NoOpTelemetryClient.js","sourceRoot":"","sources":["../../src/NoOp/NoOpTelemetryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QACW,aAAQ,GAAS,IAAI,QAAQ,EAAE,CAAC;QAChC,gBAAW,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtD,WAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAepC,CAAC;IAbC,sBAAsB;QACpB,QAAQ;QACR,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,QAAQ;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport type { TelemetryClient } from '../types/TelemetryClient.js';\nimport { NoOpTracer } from './NoOpTracer.js';\nimport { NoOpSpan } from './NoOpSpan.js';\nimport { PerformanceRecorder } from '../PerformanceRecorder.js';\n\n/**\n * No-op implementation of {@link TelemetryClient}.\n * This class will be used when Telemetry is disabled.\n */\nexport class NoOpTelemetryClient implements TelemetryClient {\n readonly rootSpan: Span = new NoOpSpan();\n readonly performance = new PerformanceRecorder(this.rootSpan);\n private tracer = new NoOpTracer();\n\n setSharedSpanAttribute(): TelemetryClient {\n // No-op\n return this;\n }\n\n shutdown() {\n // No-op\n return Promise.resolve();\n }\n\n getTracer() {\n return this.tracer;\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import type { SpanAttributes } from './types/SpanAttributes.js';
3
+ import type { PerformanceTracker } from './types/PerformanceTracker.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
+ constructor(span: Span);
10
+ /**
11
+ * Records a performance metric into telemetry. The metric will be recorded as an event on the span and logged to the console.
12
+ * 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.
13
+ * @param attributes
14
+ */
15
+ record(attributes: {
16
+ name: string;
17
+ value: number;
18
+ additionalProperties?: SpanAttributes;
19
+ }): void;
20
+ /**
21
+ * Tracks the execution time of a given `execute` function and report it to telemetry.
22
+ * @param name - The name of the performance metric.
23
+ * @param execute - The function to execute and track.
24
+ * @returns - The result of the `execute` function.
25
+ */
26
+ track<T>(name: string, execute: (tracker: PerformanceTracker) => Promise<T>): Promise<T>;
27
+ }
28
+ //# sourceMappingURL=PerformanceRecorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceRecorder.d.ts","sourceRoot":"","sources":["../src/PerformanceRecorder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAExE;;GAEG;AACH,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI;IAEvC;;;;OAIG;IACH,MAAM,CAAC,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,IAAI;IAMhG;;;;;OAKG;IACG,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAqB/F"}
@@ -0,0 +1,42 @@
1
+ import { performance } from 'perf_hooks';
2
+ /**
3
+ * PerformanceRecorder is a utility class for recording performance metrics into telemetry.
4
+ */
5
+ export class PerformanceRecorder {
6
+ constructor(span) {
7
+ this.span = span;
8
+ }
9
+ /**
10
+ * Records a performance metric into telemetry. The metric will be recorded as an event on the span and logged to the console.
11
+ * 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.
12
+ * @param attributes
13
+ */
14
+ record(attributes) {
15
+ const { name, value, additionalProperties = {} } = attributes;
16
+ this.span.addEvent('Performance-Metric', { ...additionalProperties, name, value });
17
+ console.debug(`Performance-Metric: ${name} ${value} ms`);
18
+ }
19
+ /**
20
+ * Tracks the execution time of a given `execute` function and report it to telemetry.
21
+ * @param name - The name of the performance metric.
22
+ * @param execute - The function to execute and track.
23
+ * @returns - The result of the `execute` function.
24
+ */
25
+ async track(name, execute) {
26
+ const additionalProperties = {};
27
+ const startTime = performance.now();
28
+ const tracker = {
29
+ name,
30
+ startTime,
31
+ setProperties: (properties) => {
32
+ for (const [key, value] of Object.entries(properties)) {
33
+ additionalProperties[key] = value;
34
+ }
35
+ },
36
+ };
37
+ const result = await execute(tracker);
38
+ this.record({ name, value: performance.now() - startTime, additionalProperties });
39
+ return result;
40
+ }
41
+ }
42
+ //# sourceMappingURL=PerformanceRecorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceRecorder.js","sourceRoot":"","sources":["../src/PerformanceRecorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAIzC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC9B,YAA6B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAG,CAAC;IAE3C;;;;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,KAAK,CAAC,CAAC;IAC3D,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;CACF","sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { performance } from 'perf_hooks';\nimport type { SpanAttributes } from './types/SpanAttributes.js';\nimport type { PerformanceTracker } from './types/PerformanceTracker.js';\n\n/**\n * PerformanceRecorder is a utility class for recording performance metrics into telemetry.\n */\nexport class PerformanceRecorder {\n constructor(private readonly span: Span) {}\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} ms`);\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"]}
@@ -0,0 +1,3 @@
1
+ import type { TelemetryClient } from './types/TelemetryClient.js';
2
+ export declare function createNoOpTelemetryClient(): TelemetryClient;
3
+ //# sourceMappingURL=createNoOpTelemetryClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNoOpTelemetryClient.d.ts","sourceRoot":"","sources":["../src/createNoOpTelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE,wBAAgB,yBAAyB,IAAI,eAAe,CAE3D"}
@@ -0,0 +1,5 @@
1
+ import { NoOpTelemetryClient } from './NoOp/NoOpTelemetryClient.js';
2
+ export function createNoOpTelemetryClient() {
3
+ return new NoOpTelemetryClient();
4
+ }
5
+ //# sourceMappingURL=createNoOpTelemetryClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNoOpTelemetryClient.js","sourceRoot":"","sources":["../src/createNoOpTelemetryClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import type { TelemetryClient } from './types/TelemetryClient.js';\nimport { NoOpTelemetryClient } from './NoOp/NoOpTelemetryClient.js';\n\nexport function createNoOpTelemetryClient(): TelemetryClient {\n return new NoOpTelemetryClient();\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -3,5 +3,8 @@ 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
- export { NoOpTelemetryClient } from './NoOp/NoOpTelemetryClient.js';
6
+ export { createNoOpTelemetryClient } from './createNoOpTelemetryClient.js';
7
+ export type { PerformanceTracker } from './types/PerformanceTracker.js';
8
+ export type { SpanAttributes } from './types/SpanAttributes.js';
9
+ export type { PerformanceRecorder } from './PerformanceRecorder.js';
7
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { createTelemetryClient } from './createTelemetryClient.js';
2
- export { NoOpTelemetryClient } from './NoOp/NoOpTelemetryClient.js';
2
+ export { createNoOpTelemetryClient } from './createNoOpTelemetryClient.js';
3
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAInE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export type { Span, Tracer } from '@opentelemetry/api';\nexport { createTelemetryClient } from './createTelemetryClient.js';\nexport type { LogLevel } from './types/LogLevel.js';\nexport type { TelemetryClient } from './types/TelemetryClient.js';\nexport type { TelemetryOptions } from './types/TelemetryOptions.js';\nexport { NoOpTelemetryClient } from './NoOp/NoOpTelemetryClient.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAInE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export type { Span, Tracer } from '@opentelemetry/api';\nexport { createTelemetryClient } from './createTelemetryClient.js';\nexport type { LogLevel } from './types/LogLevel.js';\nexport type { TelemetryClient } from './types/TelemetryClient.js';\nexport type { TelemetryOptions } from './types/TelemetryOptions.js';\nexport { createNoOpTelemetryClient } from './createNoOpTelemetryClient.js';\nexport type { PerformanceTracker } from './types/PerformanceTracker.js';\nexport type { SpanAttributes } from './types/SpanAttributes.js';\nexport type { PerformanceRecorder } from './PerformanceRecorder.js';\n"]}
@@ -0,0 +1,7 @@
1
+ import type { SpanAttributes } from './SpanAttributes.js';
2
+ export interface PerformanceTracker {
3
+ name: string;
4
+ startTime: number;
5
+ setProperties(properties: SpanAttributes): void;
6
+ }
7
+ //# sourceMappingURL=PerformanceTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceTracker.d.ts","sourceRoot":"","sources":["../../src/types/PerformanceTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;CACjD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PerformanceTracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceTracker.js","sourceRoot":"","sources":["../../src/types/PerformanceTracker.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanAttributes } from './SpanAttributes.js';\n\nexport interface PerformanceTracker {\n name: string;\n startTime: number;\n setProperties(properties: SpanAttributes): void;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export type SpanAttributes = Record<string, string | number>;
2
+ //# sourceMappingURL=SpanAttributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpanAttributes.d.ts","sourceRoot":"","sources":["../../src/types/SpanAttributes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SpanAttributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpanAttributes.js","sourceRoot":"","sources":["../../src/types/SpanAttributes.ts"],"names":[],"mappings":"","sourcesContent":["export type SpanAttributes = Record<string, string | number>;\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { Span, Tracer } from '@opentelemetry/api';
2
+ import type { PerformanceRecorder } from '../PerformanceRecorder.js';
2
3
  export interface TelemetryClient {
3
4
  /**
4
5
  * Root span which measures the duration of the highest level application (ie: CLI)
@@ -19,5 +20,9 @@ export interface TelemetryClient {
19
20
  * @returns the OpenTelemetry tracer
20
21
  */
21
22
  getTracer(): Tracer;
23
+ /**
24
+ * Gets the performance recorder.
25
+ */
26
+ performance: PerformanceRecorder;
22
27
  }
23
28
  //# sourceMappingURL=TelemetryClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TelemetryClient.d.ts","sourceRoot":"","sources":["../../src/types/TelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IAEf;;;;OAIG;IACH,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;OAGG;IACH,SAAS,IAAI,MAAM,CAAC;CACrB"}
1
+ {"version":3,"file":"TelemetryClient.d.ts","sourceRoot":"","sources":["../../src/types/TelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IAEf;;;;OAIG;IACH,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;OAGG;IACH,SAAS,IAAI,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,EAAE,mBAAmB,CAAC;CAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TelemetryClient.js","sourceRoot":"","sources":["../../src/types/TelemetryClient.ts"],"names":[],"mappings":"","sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\n\nexport interface TelemetryClient {\n /**\n * Root span which measures the duration of the highest level application (ie: CLI)\n */\n rootSpan: Span;\n\n /**\n * Sets a shared attribute that will be added to all spans.\n * @param key - key of the attribute\n * @param value - value of the attribute\n */\n setSharedSpanAttribute(key: string, value: string): void;\n\n /**\n * Flushes all telemetry and shuts down the telemetry client.\n */\n shutdown(): Promise<void>;\n\n /**\n * Gets the OpenTelemetry tracer.\n * @returns the OpenTelemetry tracer\n */\n getTracer(): Tracer;\n}\n"]}
1
+ {"version":3,"file":"TelemetryClient.js","sourceRoot":"","sources":["../../src/types/TelemetryClient.ts"],"names":[],"mappings":"","sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\nimport type { PerformanceRecorder } from '../PerformanceRecorder.js';\n\nexport interface TelemetryClient {\n /**\n * Root span which measures the duration of the highest level application (ie: CLI)\n */\n rootSpan: Span;\n\n /**\n * Sets a shared attribute that will be added to all spans.\n * @param key - key of the attribute\n * @param value - value of the attribute\n */\n setSharedSpanAttribute(key: string, value: string): void;\n\n /**\n * Flushes all telemetry and shuts down the telemetry client.\n */\n shutdown(): Promise<void>;\n\n /**\n * Gets the OpenTelemetry tracer.\n * @returns the OpenTelemetry tracer\n */\n getTracer(): Tracer;\n\n /**\n * Gets the performance recorder.\n */\n performance: PerformanceRecorder;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/telemetry",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Helpers for logging tasks to the console.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,12 +13,12 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@opentelemetry/api": "^1.4.0",
17
- "@opentelemetry/resources": "^1.9.1",
18
- "@opentelemetry/sdk-trace-base": "^1.9.1",
19
- "@opentelemetry/sdk-trace-node": "^1.9.1",
20
- "@opentelemetry/semantic-conventions": "^1.9.1",
21
- "applicationinsights": "3.0.0-beta.5"
16
+ "@azure/monitor-opentelemetry": "^1.0.0",
17
+ "@opentelemetry/api": "^1.6.0",
18
+ "@opentelemetry/resources": "^1.17.0",
19
+ "@opentelemetry/sdk-trace-base": "^1.17.0",
20
+ "@opentelemetry/sdk-trace-node": "^1.17.0",
21
+ "@opentelemetry/semantic-conventions": "^1.17.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@ms-cloudpack/eslint-plugin-internal": "*",