solarwinds-apm
Version:
OpenTelemetry-based SolarWinds APM library
75 lines • 2.9 kB
TypeScript
import { type Context, type Span } from "@opentelemetry/api";
import { type ReadableSpan } from "@opentelemetry/sdk-trace-base";
/**
* Creates a global value shared between ESM and CommonJS contexts
*
* @param id - Descriptive unique ID for the global
* @param init - Initializer for the global if it needs to be
*
* @returns Shared global
*/
export declare function global<const T>(id: string, init: () => T): T;
/** Typed wrapper around the OTel {@link Context} API for a specific key */
export interface ContextStorage<T> {
/**
* Gets the value for the key
*
* Note that while the context object itself is immutable,
* reference types stored in it are not. This means it is possible
* to modify the return value of this function in-place if it is
* a reference type.
*/
get(context: Context): T | undefined;
/**
* Sets the value for the key
*
* Note that the context object is immutable and this function
* returns an updated context without modifying the given one in-place.
* in-place
*/
set(context: Context, value: T): Context;
/**
* Deletes the value for the key
*
* Note that the context object is immutable and this function
* returns an updated context without modifying the given one in-place.
*/
delete(context: Context): Context;
}
/**
* Typed OTel {@link Span} attached storage API for a specific key
*
* This makes it possible to attach arbitrary data to OTel spans
* without altering the span object.
*
* The stored value will be accessible throughout the entire
* lifecycle of the span from the moment it is set until the span
* finishes being exported.
*
* Unlike the previous implementation which used the span ID as a key
* and needed to be carefully cleared at the right times to avoid leaking
* memory, this uses a WeakMap with the span object itself as a key
* which ensures the stored values are kept at least as long as they need
* to be accessed.
*
* However it it still useful to manually clear unused entries to avoid
* using up memory unnecessarily while waiting for the next GC cycle.
*/
export interface SpanStorage<T> {
get(span: Span | ReadableSpan): T | undefined;
set(span: Span | ReadableSpan, value: T): boolean;
delete(span: Span | ReadableSpan): boolean;
}
/**
* Promise which resolves to the value passed to it
* when calling its resolve method.
*/
export interface CellStorage<T> extends Promise<T> {
resolve(instance: T): void;
}
/** Creates a new {@link ContextStorage} for the given ID */
export declare function contextStorage<T>(id: string): ContextStorage<T>;
/** Creates a new {@link SpanStorage} for the given ID */
export declare function spanStorage<T>(id: string): SpanStorage<T>;
export declare function cellStorage<T>(id: string): CellStorage<T>;
//# sourceMappingURL=storage.d.ts.map