-
Notifications
You must be signed in to change notification settings - Fork 257
OTel Web SDK Phase 1 #2715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
OTel Web SDK Phase 1 #2715
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6dd518d
OTel Web SDK Phase 1
hectorhdzg 4b2e813
Update shared/otel-core/src/utils/DataCacheHelper.ts
hectorhdzg 262b741
Update shared/otel-core/src/otel/sdk/OTelWebSdk.ts
hectorhdzg 1e23bd4
Address comments
hectorhdzg 11fa3e1
Update
hectorhdzg 7e64771
Addresing comments
hectorhdzg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,051 changes: 1,051 additions & 0 deletions
1,051
shared/otel-core/Tests/Unit/src/sdk/OTelWebSdk.Tests.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { IPromise } from "@nevware21/ts-async"; | ||
| import { IOTelWebSdkConfig } from "./config/IOTelWebSdkConfig"; | ||
| import { IOTelLogger } from "./logs/IOTelLogger"; | ||
| import { IOTelLoggerOptions } from "./logs/IOTelLoggerOptions"; | ||
| import { IOTelTracer } from "./trace/IOTelTracer"; | ||
| import { IOTelTracerOptions } from "./trace/IOTelTracerOptions"; | ||
|
|
||
| /** | ||
| * Main interface for the OpenTelemetry Web SDK. | ||
| * Provides access to tracer and logger providers, configuration management, | ||
| * and complete lifecycle control including unload/cleanup. | ||
| * | ||
| * @remarks | ||
| * - Supports multiple isolated instances without global state | ||
| * - All dependencies injected through {@link IOTelWebSdkConfig} | ||
| * - Complete unload support — every instance must fully clean up on unload | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const sdk = createOTelWebSdk({ | ||
| * resource: myResource, | ||
| * errorHandlers: myHandlers, | ||
| * contextManager: myContextManager, | ||
| * idGenerator: myIdGenerator, | ||
| * sampler: myAlwaysOnSampler | ||
| * }); | ||
| * | ||
| * // Get a tracer and create spans | ||
| * const tracer = sdk.getTracer("my-service"); | ||
| * const span = tracer.startSpan("operation"); | ||
| * span.end(); | ||
| * | ||
| * // Get a logger and emit log records | ||
| * const logger = sdk.getLogger("my-service"); | ||
| * logger.emit({ body: "Hello, World!" }); | ||
| * | ||
| * // Cleanup when done | ||
| * sdk.shutdown(); | ||
| * ``` | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| export interface IOTelWebSdk { | ||
| /** | ||
| * Returns a Tracer for creating spans. | ||
| * Tracers are cached by name + version combination — requesting the same | ||
| * name and version returns the same Tracer instance. | ||
| * | ||
| * @param name - The name of the tracer or instrumentation library | ||
| * @param version - The version of the tracer or instrumentation library | ||
| * @param options - Additional tracer options (e.g., schemaUrl) | ||
| * @returns A Tracer with the given name and version, or null if the SDK is shutdown or | ||
| * required dependencies are not configured | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const tracer = sdk.getTracer("my-component", "1.0.0"); | ||
| * const span = tracer.startSpan("my-operation"); | ||
| * ``` | ||
| */ | ||
| getTracer(name: string, version?: string, options?: IOTelTracerOptions): IOTelTracer | null; | ||
|
|
||
| /** | ||
| * Returns a Logger for emitting log records. | ||
| * Loggers are cached by name + version + schemaUrl combination — | ||
| * requesting the same combination returns the same Logger instance. | ||
| * | ||
| * @param name - The name of the logger or instrumentation library | ||
| * @param version - The version of the logger or instrumentation library | ||
| * @param options - Additional logger options (e.g., schemaUrl, scopeAttributes) | ||
| * @returns A Logger with the given name and version, or null if the SDK is shutdown | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const logger = sdk.getLogger("my-component", "1.0.0"); | ||
| * logger.emit({ body: "Operation completed", severityText: "INFO" }); | ||
| * ``` | ||
| */ | ||
| getLogger(name: string, version?: string, options?: IOTelLoggerOptions): IOTelLogger | null; | ||
|
|
||
| // TODO: Phase 5 - Uncomment when metrics are implemented | ||
| // /** | ||
| // * Returns a Meter for recording metrics. | ||
| // * @param name - The name of the meter or instrumentation library | ||
| // * @param version - The version of the meter or instrumentation library | ||
| // * @param options - Additional meter options | ||
| // * @returns A Meter with the given name and version | ||
| // */ | ||
| // getMeter(name: string, version?: string, options?: IOTelMeterOptions): IOTelMeter; | ||
|
|
||
| /** | ||
| * Forces all providers to flush any buffered data. | ||
| * This is useful before application shutdown to ensure all telemetry | ||
| * is exported. | ||
| * | ||
| * @returns A promise that resolves when the flush is complete | ||
| */ | ||
| forceFlush(): IPromise<void>; | ||
|
|
||
| /** | ||
| * Shuts down the SDK and releases all resources. | ||
| * After shutdown, the SDK instance is no longer usable — all | ||
| * subsequent calls to `getTracer` or `getLogger` will return null. | ||
| * | ||
| * @remarks | ||
| * Shutdown performs the following: | ||
| * - Flushes all pending telemetry | ||
| * - Shuts down all providers (trace, log) | ||
| * - Removes all config change listeners (calls `IUnloadHook.rm()`) | ||
| * - Clears all cached instances | ||
| * | ||
| * @returns A promise that resolves when shutdown is complete | ||
| */ | ||
| shutdown(): IPromise<void>; | ||
|
|
||
| /** | ||
| * Gets the current SDK configuration as a live reference. | ||
| * Callers should treat the returned configuration as read-only. | ||
| * | ||
| * @returns The current SDK configuration | ||
| */ | ||
| getConfig(): Readonly<IOTelWebSdkConfig>; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.