@ms-cloudpack/telemetry 0.7.0 → 0.8.1

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.
@@ -21,7 +21,7 @@ import {
21
21
  require_src2,
22
22
  require_src3,
23
23
  require_src4
24
- } from "./chunk-ITZ7GKLO.js";
24
+ } from "./chunk-NJ4KSOZ3.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-MZUZAXPV.js";
10
- import "./chunk-ITZ7GKLO.js";
9
+ } from "./chunk-BNPQM6Z3.js";
10
+ import "./chunk-NJ4KSOZ3.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-ITZ7GKLO.js";
10
+ } from "./chunk-NJ4KSOZ3.js";
11
11
 
12
12
  // src/NoOpTelemetryClient.ts
13
13
  var _NoOpTelemetryClient = class _NoOpTelemetryClient extends BaseTelemetryClient {
@@ -4965,11 +4965,11 @@ var require_ExportResult = __commonJS({
4965
4965
  "use strict";
4966
4966
  Object.defineProperty(exports, "__esModule", { value: true });
4967
4967
  exports.ExportResultCode = void 0;
4968
- var ExportResultCode;
4969
- (function(ExportResultCode2) {
4970
- ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
4971
- ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
4972
- })(ExportResultCode = exports.ExportResultCode || (exports.ExportResultCode = {}));
4968
+ var ExportResultCode2;
4969
+ (function(ExportResultCode3) {
4970
+ ExportResultCode3[ExportResultCode3["SUCCESS"] = 0] = "SUCCESS";
4971
+ ExportResultCode3[ExportResultCode3["FAILED"] = 1] = "FAILED";
4972
+ })(ExportResultCode2 = exports.ExportResultCode || (exports.ExportResultCode = {}));
4973
4973
  }
4974
4974
  });
4975
4975
 
@@ -6988,8 +6988,8 @@ var require_BatchSpanProcessor = __commonJS({
6988
6988
  }
6989
6989
  };
6990
6990
  __name(_BatchSpanProcessor, "BatchSpanProcessor");
6991
- var BatchSpanProcessor = _BatchSpanProcessor;
6992
- exports.BatchSpanProcessor = BatchSpanProcessor;
6991
+ var BatchSpanProcessor2 = _BatchSpanProcessor;
6992
+ exports.BatchSpanProcessor = BatchSpanProcessor2;
6993
6993
  }
6994
6994
  });
6995
6995
 
@@ -8418,7 +8418,7 @@ var require_ConsoleSpanExporter = __commonJS({
8418
8418
  Object.defineProperty(exports, "__esModule", { value: true });
8419
8419
  exports.ConsoleSpanExporter = void 0;
8420
8420
  var core_1 = require_src2();
8421
- var _ConsoleSpanExporter = class _ConsoleSpanExporter {
8421
+ var _ConsoleSpanExporter2 = class _ConsoleSpanExporter2 {
8422
8422
  /**
8423
8423
  * Export spans.
8424
8424
  * @param spans
@@ -8479,9 +8479,9 @@ var require_ConsoleSpanExporter = __commonJS({
8479
8479
  }
8480
8480
  }
8481
8481
  };
8482
- __name(_ConsoleSpanExporter, "ConsoleSpanExporter");
8483
- var ConsoleSpanExporter = _ConsoleSpanExporter;
8484
- exports.ConsoleSpanExporter = ConsoleSpanExporter;
8482
+ __name(_ConsoleSpanExporter2, "ConsoleSpanExporter");
8483
+ var ConsoleSpanExporter2 = _ConsoleSpanExporter2;
8484
+ exports.ConsoleSpanExporter = ConsoleSpanExporter2;
8485
8485
  }
8486
8486
  });
8487
8487
 
@@ -12109,8 +12109,8 @@ var import_sdk_trace_node = __toESM(require_src7(), 1);
12109
12109
 
12110
12110
  // src/SpanEnrichingProcessor.ts
12111
12111
  var _SpanEnrichingProcessor = class _SpanEnrichingProcessor {
12112
- constructor(getSharedSpanAttributes) {
12113
- this.getSharedSpanAttributes = getSharedSpanAttributes;
12112
+ constructor(sharedSpanAttributes) {
12113
+ this.sharedSpanAttributes = sharedSpanAttributes;
12114
12114
  }
12115
12115
  forceFlush() {
12116
12116
  return Promise.resolve();
@@ -12121,7 +12121,7 @@ var _SpanEnrichingProcessor = class _SpanEnrichingProcessor {
12121
12121
  onStart() {
12122
12122
  }
12123
12123
  onEnd(span) {
12124
- for (const [key, value] of Object.entries(this.getSharedSpanAttributes())) {
12124
+ for (const [key, value] of Object.entries(this.sharedSpanAttributes)) {
12125
12125
  span.attributes[key] = value;
12126
12126
  }
12127
12127
  }
@@ -12359,21 +12359,71 @@ function getVersion(importUrl) {
12359
12359
  }
12360
12360
  __name(getVersion, "getVersion");
12361
12361
 
12362
+ // src/ConsoleSpanExporter.ts
12363
+ var import_core = __toESM(require_src2(), 1);
12364
+ var _ConsoleSpanExporter = class _ConsoleSpanExporter {
12365
+ /**
12366
+ * Export spans.
12367
+ */
12368
+ export(spans, resultCallback) {
12369
+ return this._sendSpans(spans, resultCallback);
12370
+ }
12371
+ /**
12372
+ * Shutdown the exporter.
12373
+ */
12374
+ shutdown() {
12375
+ this._sendSpans([]);
12376
+ return this.forceFlush();
12377
+ }
12378
+ /**
12379
+ * Exports any pending spans in exporter
12380
+ */
12381
+ forceFlush() {
12382
+ return Promise.resolve();
12383
+ }
12384
+ /**
12385
+ * converts span info into more readable format
12386
+ */
12387
+ _exportInfo(span) {
12388
+ return [
12389
+ `Telemetry Span: ${span.name} in ${span.duration}ms`,
12390
+ span.events.length > 0 ? `with ${span.events.length} events` : void 0
12391
+ ].filter((text) => !!text).join(" ");
12392
+ }
12393
+ /**
12394
+ * Showing spans in console
12395
+ */
12396
+ _sendSpans(spans, done) {
12397
+ for (const span of spans) {
12398
+ console.debug(this._exportInfo(span));
12399
+ }
12400
+ if (done) {
12401
+ return done({ code: import_core.ExportResultCode.SUCCESS });
12402
+ }
12403
+ }
12404
+ };
12405
+ __name(_ConsoleSpanExporter, "ConsoleSpanExporter");
12406
+ var ConsoleSpanExporter = _ConsoleSpanExporter;
12407
+
12362
12408
  // src/BaseTelemetryClient.ts
12363
12409
  var _BaseTelemetryClient = class _BaseTelemetryClient {
12364
12410
  constructor(options) {
12365
12411
  diag2.debug("Initializing TelemetryClient with options:", options);
12366
12412
  metrics.disable();
12367
12413
  trace.disable();
12368
- this.sharedSpanAttributes = {
12369
- "cloudpack.telemetry.id": v4_default(),
12370
- "cloudpack.telemetry.version": getVersion(import.meta.url)
12371
- };
12372
12414
  const resource = createResourceFromOptions(options);
12373
12415
  this._tracerProvider = new import_sdk_trace_node.NodeTracerProvider({
12374
12416
  resource
12375
12417
  });
12376
- this._tracerProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));
12418
+ this._tracerProvider.addSpanProcessor(
12419
+ new SpanEnrichingProcessor({
12420
+ "cloudpack.telemetry.id": v4_default(),
12421
+ "cloudpack.telemetry.version": getVersion(import.meta.url)
12422
+ })
12423
+ );
12424
+ if (options.logLevel === "DEBUG") {
12425
+ this._tracerProvider.addSpanProcessor(new import_sdk_trace_node.BatchSpanProcessor(new ConsoleSpanExporter()));
12426
+ }
12377
12427
  this._rootSpan = this.tracer.startSpan(options.rootSpanName || "root");
12378
12428
  this._performance = new PerformanceRecorder(this._rootSpan);
12379
12429
  diag2.info("TelemetryClient is initialized.");
@@ -12389,14 +12439,6 @@ var _BaseTelemetryClient = class _BaseTelemetryClient {
12389
12439
  await this._tracerProvider.shutdown();
12390
12440
  diag2.debug("TelemetryClient has shutdown.");
12391
12441
  }
12392
- /**
12393
- * Sets a shared attribute that will be added to all spans.
12394
- * @param key - key of the attribute
12395
- * @param value - value of the attribute
12396
- */
12397
- setSharedSpanAttribute(key, value) {
12398
- this.sharedSpanAttributes[key] = value;
12399
- }
12400
12442
  /**
12401
12443
  * Gets the OpenTelemetry tracer.
12402
12444
  * @returns the OpenTelemetry tracer
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-MZUZAXPV.js";
9
+ } from "./chunk-BNPQM6Z3.js";
10
10
  import {
11
11
  DiagConsoleLogger,
12
12
  DiagLogLevel,
13
13
  __name,
14
14
  diag,
15
15
  init_esm
16
- } from "./chunk-ITZ7GKLO.js";
16
+ } from "./chunk-NJ4KSOZ3.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-AODPEX3O.js");
23
+ const { NoOpTelemetryClient: NoOpTelemetryClient2 } = await import("./NoOpTelemetryClient-TTBAN54Z.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-ETNBIAWP.js");
30
+ const { AppInsightsTelemetryClient } = await import("./AppInsightsTelemetryClient-R4KUMXIS.js");
31
31
  return new AppInsightsTelemetryClient(options);
32
32
  }
33
33
  __name(createTelemetryClient, "createTelemetryClient");
@@ -1,4 +1,4 @@
1
- import { type AttributeValue, type Span, type Tracer } from '@opentelemetry/api';
1
+ import { type Span, 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';
@@ -6,19 +6,12 @@ import { PerformanceRecorder } from './PerformanceRecorder.js';
6
6
  export declare class BaseTelemetryClient implements TelemetryClient {
7
7
  private readonly _performance;
8
8
  private readonly _rootSpan;
9
- private readonly sharedSpanAttributes;
10
9
  protected readonly _tracerProvider: NodeTracerProvider;
11
10
  constructor(options: TelemetryOptions);
12
11
  /**
13
12
  * Flushes all telemetry and shuts down the telemetry client.
14
13
  */
15
14
  shutdown(): Promise<void>;
16
- /**
17
- * Sets a shared attribute that will be added to all spans.
18
- * @param key - key of the attribute
19
- * @param value - value of the attribute
20
- */
21
- setSharedSpanAttribute(key: string, value: AttributeValue): void;
22
15
  /**
23
16
  * Gets the OpenTelemetry tracer.
24
17
  * @returns the OpenTelemetry tracer
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A customized version of the OpenTelemetry `ConsoleSpanExporter`.
3
+ * Original source: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts
4
+ *
5
+ * This modified exporter adjusts the format of the output for improved readability.
6
+ */
7
+ import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
8
+ import type { ExportResult } from '@opentelemetry/core';
9
+ /**
10
+ * This is implementation of {@link SpanExporter} that prints spans to the
11
+ * console. This class can be used for diagnostic purposes.
12
+ *
13
+ * NOTE: This {@link SpanExporter} is intended for diagnostics use only, output rendered to the console may change at any time.
14
+ */
15
+ export declare class ConsoleSpanExporter implements SpanExporter {
16
+ /**
17
+ * Export spans.
18
+ */
19
+ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
20
+ /**
21
+ * Shutdown the exporter.
22
+ */
23
+ shutdown(): Promise<void>;
24
+ /**
25
+ * Exports any pending spans in exporter
26
+ */
27
+ forceFlush(): Promise<void>;
28
+ /**
29
+ * converts span info into more readable format
30
+ */
31
+ private _exportInfo;
32
+ /**
33
+ * Showing spans in console
34
+ */
35
+ private _sendSpans;
36
+ }
37
+ //# sourceMappingURL=ConsoleSpanExporter.d.ts.map
@@ -4,8 +4,8 @@ import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base'
4
4
  * Span processor that adds shared attributes to all spans.
5
5
  */
6
6
  export declare class SpanEnrichingProcessor implements SpanProcessor {
7
- private getSharedSpanAttributes;
8
- constructor(getSharedSpanAttributes: () => Attributes);
7
+ private sharedSpanAttributes;
8
+ constructor(sharedSpanAttributes: Attributes);
9
9
  forceFlush(): Promise<void>;
10
10
  shutdown(): Promise<void>;
11
11
  onStart(): void;
@@ -1,16 +1,10 @@
1
- import type { AttributeValue, Span, Tracer } from '@opentelemetry/api';
1
+ import type { Span, Tracer } from '@opentelemetry/api';
2
2
  import type { PerformanceRecorder } from '../PerformanceRecorder.js';
3
3
  export interface TelemetryClient {
4
4
  /**
5
5
  * Root span which measures the duration of the highest level application (ie: CLI)
6
6
  */
7
7
  rootSpan: Span;
8
- /**
9
- * Sets a shared attribute that will be added to all spans.
10
- * @param key - key of the attribute
11
- * @param value - value of the attribute
12
- */
13
- setSharedSpanAttribute(key: string, value: AttributeValue): void;
14
8
  /**
15
9
  * Flushes all telemetry and shuts down the telemetry client.
16
10
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/telemetry",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Helpers for reporting telemetry in Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,9 +16,10 @@
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.6",
19
+ "@ms-cloudpack/package-utilities": "^10.2.7",
20
20
  "@ms-cloudpack/scripts": "^0.0.1",
21
21
  "@opentelemetry/api": "~1.9.0",
22
+ "@opentelemetry/core": "~1.26.0",
22
23
  "@opentelemetry/resources": "~1.26.0",
23
24
  "@opentelemetry/sdk-trace-base": "~1.26.0",
24
25
  "@opentelemetry/sdk-trace-node": "~1.26.0",