@ms-cloudpack/telemetry 0.11.74 → 0.12.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.
@@ -0,0 +1,15 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { createRequire as topLevelCreateRequire } from 'node:module';
4
+ import topLevelPath from 'node:path';
5
+ import topLevelUrl from 'node:url';
6
+ const require = topLevelCreateRequire(import.meta.url);
7
+ const __filename = topLevelUrl.fileURLToPath(import.meta.url);
8
+ const __dirname = topLevelPath.dirname(__filename);
9
+ import {
10
+ AzureMonitorStatsbeatExporter
11
+ } from "./chunk-5KML56LI.js";
12
+ import "./chunk-VFMIPDJG.js";
13
+ export {
14
+ AzureMonitorStatsbeatExporter
15
+ };
@@ -1,4 +1,4 @@
1
- import { Resource } from '@opentelemetry/resources';
1
+ import { type Resource } from '@opentelemetry/resources';
2
2
  import type { TelemetryOptions } from './types/TelemetryOptions.js';
3
3
  export declare function createResourceFromOptions(options: TelemetryOptions): Resource;
4
4
  //# sourceMappingURL=createResourceFromOptions.d.ts.map
package/lib/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- export type { Span } from '@opentelemetry/api';
2
- export type { TelemetryApi } from './types/TelemetryApi.js';
1
+ export { SpanStatusCode, type Span } from '@opentelemetry/api';
2
+ export { createNoOpTelemetryClient } from './createNoOpTelemetryClient.js';
3
+ export { startTelemetry } from './startTelemetry.js';
4
+ export type { AsyncTracer } from './types/AsyncTracer.js';
3
5
  export type { LogLevel } from './types/LogLevel.js';
6
+ export type { TelemetryApi } from './types/TelemetryApi.js';
4
7
  export type { TelemetryClient } from './types/TelemetryClient.js';
5
8
  export type { TelemetryOptions } from './types/TelemetryOptions.js';
6
- export type { AsyncTracer } from './proxies/createProxiedTracer.js';
7
- export { SpanStatusCode } from '@opentelemetry/api';
8
- export { startTelemetry } from './startTelemetry.js';
9
- export { createNoOpTelemetryClient } from './createNoOpTelemetryClient.js';
10
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,6 @@
1
1
  import { type Span } from '@opentelemetry/api';
2
+ /** Symbol to store the `hasEnded` flag inside a Span (exported for testing) */
3
+ export declare const _hasEnded: unique symbol;
2
4
  /**
3
5
  * A span that can be ended only once
4
6
  */
@@ -1,15 +1,27 @@
1
- import type { Context, Span, SpanOptions, Tracer } from '@opentelemetry/api';
2
- export type AsyncTracer = Omit<Tracer, 'startActiveSpan'> & {
3
- startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): Promise<Awaited<ReturnType<F>>>;
4
- startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): Promise<Awaited<ReturnType<F>>>;
5
- startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): Promise<Awaited<ReturnType<F>>>;
6
- };
1
+ import { type Context, type SpanOptions, type Tracer } from '@opentelemetry/api';
2
+ import type { AsyncTracer, SpanFunction, StartActiveSpanFn } from '../types/AsyncTracer.ts';
7
3
  /**
8
- * Creates a proxied tracer that will automatically do the following things;
9
- * - End the span when the function ends
10
- * - Record any exceptions that are thrown
4
+ * Creates a proxied tracer that will automatically do the following things in the `startActiveSpan` method:
5
+ * - Provide the correct context based on `getRootContext` (also does this for `startSpan`)
6
+ * - Await the async function
7
+ * - End the span when the function ends (no-op if ended multiple times)
8
+ * - Record any exceptions that are thrown and set the span status to `ERROR`
9
+ *
10
+ * (Use a proxy instead of returning a new object in case any internals of opentelemetry rely on
11
+ * other methods being present that aren't included on the interface.)
12
+ *
11
13
  * @param tracer - The tracer to proxy
12
14
  * @returns - Proxied tracer
13
15
  */
14
- export declare function createProxiedTracer(tracer: Tracer, getRootContext?: () => Context): AsyncTracer;
16
+ export declare function createProxiedTracer(tracer: Tracer, getRootContext: () => Context): AsyncTracer;
17
+ /**
18
+ * Parses the parameters for startActiveSpan, which can be called with 2, 3, or 4 arguments.
19
+ * Exported for use in tests.
20
+ */
21
+ export declare function _parseParameters<T>(...params: Parameters<StartActiveSpanFn>): {
22
+ name: string;
23
+ options?: SpanOptions;
24
+ context?: Context;
25
+ fn: SpanFunction<T>;
26
+ };
15
27
  //# sourceMappingURL=createProxiedTracer.d.ts.map
@@ -1,8 +1,9 @@
1
- import type { TelemetryOptions } from './types/TelemetryOptions.js';
2
1
  import type { TelemetryApi } from './types/TelemetryApi.js';
2
+ import type { TelemetryOptions } from './types/TelemetryOptions.js';
3
3
  /**
4
- * Initialize the telemetry infrastructure.
5
- * This function sets up the OpenTelemetry, configures the tracer provider.
4
+ * Initialize the telemetry infrastructure: set up OpenTelemetry, configure the tracer provider, and
5
+ * add processors for each app (including one to send telemetry if a connection string is provided
6
+ * for that app).
6
7
  */
7
- export declare function startTelemetry(options: TelemetryOptions): TelemetryApi;
8
+ export declare function startTelemetry(options: TelemetryOptions): Promise<TelemetryApi>;
8
9
  //# sourceMappingURL=startTelemetry.d.ts.map
@@ -0,0 +1,34 @@
1
+ import type { Context, Span, SpanOptions } from '@opentelemetry/api';
2
+ export type SpanFunction<T> = (span: Span) => T | Promise<T>;
3
+ /**
4
+ * Tracer that supports tracking async operations and automatically managing span lifecycle
5
+ * within `startActiveSpan`. (`startSpan` only sets the proper parent context.)
6
+ */
7
+ export interface AsyncTracer {
8
+ /**
9
+ * Start a new span without modifying the current context.
10
+ *
11
+ * This version sets the proper parent context for the span, but does not end the span automatically.
12
+ *
13
+ * @param name The name of the span
14
+ * @param options Span options
15
+ * @param context Don't use this directly. The proper app context will be set automatically.
16
+ */
17
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
18
+ /**
19
+ * Start an active span within the proper parent context and automatically end it when the
20
+ * function completes. It will call the provided function with the active span as its argument,
21
+ * and await the result if async.
22
+ *
23
+ * If the function throws an error, it will be recorded on the span (and set the span status
24
+ * to `ERROR`) then re-thrown.
25
+ *
26
+ * @param name The name of the span
27
+ */
28
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): Promise<Awaited<ReturnType<F>>>;
29
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): Promise<Awaited<ReturnType<F>>>;
30
+ /** Don't use this directly. The proper app context will be set automatically. */
31
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): Promise<Awaited<ReturnType<F>>>;
32
+ }
33
+ export type StartActiveSpanFn = <T>(name: string, optionsOrFn?: SpanOptions | SpanFunction<T>, contextOrFn?: Context | SpanFunction<T>, maybeFn?: SpanFunction<T>) => T;
34
+ //# sourceMappingURL=AsyncTracer.d.ts.map
@@ -1,13 +1,12 @@
1
- import type { TelemetryClient } from './TelemetryClient.js';
1
+ import type { TelemetryClient } from './TelemetryClient.ts';
2
2
  export interface TelemetryApi {
3
3
  /**
4
- * Flushes all telemetry and shuts down the telemetry client.
4
+ * Mapping from app path to telemetry client.
5
5
  */
6
- shutdown(): Promise<void>;
6
+ clients: Record<string, TelemetryClient>;
7
7
  /**
8
- * Creates a telemetry client with the given connection string.
9
- * @param connectionString - The connection string for the telemetry client.
8
+ * Flushes all telemetry and shuts down the telemetry client.
10
9
  */
11
- createClient(connectionString?: string): Promise<TelemetryClient>;
10
+ shutdown(): Promise<void>;
12
11
  }
13
12
  //# sourceMappingURL=TelemetryApi.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { AsyncTracer } from '../proxies/createProxiedTracer.js';
1
+ import type { AsyncTracer } from './AsyncTracer.js';
2
2
  export interface TelemetryClient {
3
3
  /**
4
4
  * Gets the OpenTelemetry tracer.
@@ -3,15 +3,19 @@ export interface TelemetryOptions {
3
3
  /**
4
4
  * The log level for the telemetry client.
5
5
  */
6
- logLevel?: LogLevel;
6
+ logLevel: LogLevel | undefined;
7
7
  /**
8
8
  * The version of the product. This will be added as a shared attribute to all spans.
9
9
  */
10
10
  productVersion: string;
11
11
  /**
12
- * Logic name of the service
13
- * Possible values: cli, bundler-service, etc.
12
+ * Logical name of the service (e.g. `'cli'`, `'storybook'`)
14
13
  */
15
14
  serviceName: string;
15
+ /**
16
+ * Mapping from app path to telemetry connection string.
17
+ * `undefined` means no telemetry will be sent for that app.
18
+ */
19
+ connectionStrings: Record<string, string | undefined>;
16
20
  }
17
21
  //# sourceMappingURL=TelemetryOptions.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/telemetry",
3
- "version": "0.11.74",
3
+ "version": "0.12.0",
4
4
  "description": "Helpers for reporting telemetry in Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,18 +24,23 @@
24
24
  "test": "cloudpack-scripts test"
25
25
  },
26
26
  "devDependencies": {
27
- "@azure/monitor-opentelemetry-exporter": "1.0.0-beta.28",
28
- "@ms-cloudpack/environment": "^0.1.1",
27
+ "@azure/monitor-opentelemetry-exporter": "1.0.0-beta.39",
28
+ "@ms-cloudpack/environment": "^0.1.3",
29
29
  "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
30
- "@ms-cloudpack/package-utilities": "^13.8.1",
30
+ "@ms-cloudpack/package-utilities": "^13.8.3",
31
31
  "@ms-cloudpack/scripts": "^0.0.1",
32
- "@opentelemetry/api": "~1.9.0",
33
- "@opentelemetry/context-async-hooks": "~1.30.0",
34
- "@opentelemetry/core": "~1.30.0",
35
- "@opentelemetry/resources": "~1.30.0",
36
- "@opentelemetry/sdk-trace-base": "~1.30.0",
37
- "@opentelemetry/sdk-trace-node": "~1.30.0",
38
- "@opentelemetry/semantic-conventions": "~1.28.0"
32
+ "@opentelemetry/api": "1.9.1",
33
+ "@opentelemetry/context-async-hooks": "2.1.0",
34
+ "@opentelemetry/resources": "2.1.0",
35
+ "@opentelemetry/sdk-trace-base": "2.1.0",
36
+ "@opentelemetry/sdk-trace-node": "2.1.0",
37
+ "@opentelemetry/semantic-conventions": "1.40.0"
38
+ },
39
+ "rationale": {
40
+ "devDependencies": {
41
+ "@opentelemetry/*": "match versions used by @azure/monitor-opentelemetry-exporter (see also resolutions in root package.json)",
42
+ "@azure/monitor-opentelemetry-exporter": "Should follow beta tag (NOT latest) to get opentelemetry dep updates sooner"
43
+ }
39
44
  },
40
45
  "files": [
41
46
  "dist",
@@ -1,37 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- import { DiagLogLevel } from '@opentelemetry/api';
2
- import type { LogLevel } from './types/LogLevel.js';
3
- export declare function convertLogLevel(logLevel?: LogLevel): DiagLogLevel;
4
- //# sourceMappingURL=convertLogLevel.d.ts.map
@@ -1,6 +0,0 @@
1
- /**
2
- * Each OS has a different way of getting the computer name.
3
- * @returns computer name for the current OS, or the hostname if it cannot be determined
4
- */
5
- export declare function getComputerName(): string;
6
- //# sourceMappingURL=getComputerName.d.ts.map
@@ -1,6 +0,0 @@
1
- import { type Tracer, type Span, type SpanOptions, type Context } from '@opentelemetry/api';
2
- export type SpanFunction<T> = (span: Span) => T | Promise<T>;
3
- type StartActiveSpanFn = <T>(name: string, optionsOrFn?: SpanOptions | SpanFunction<T>, contextOrFn?: Context | SpanFunction<T>, maybeFn?: SpanFunction<T>) => T;
4
- export declare function createImprovedStartActiveSpan(target: Tracer, getRootContext?: () => Context): <T>(...params: Parameters<StartActiveSpanFn>) => Promise<T>;
5
- export {};
6
- //# sourceMappingURL=createImprovedStartActiveSpan.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=createImprovedStartActiveSpan.test.d.ts.map
@@ -1,9 +0,0 @@
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) => Promise<T>;
9
- //# sourceMappingURL=createSpanFunctionWrapper.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=createSpanFunctionWrapper.test.d.ts.map