import { Bearer, Token } from './token.js'; /** Contains the stable result label for a successful metric event. */ export declare const METRIC_RESULT_SUCCESS = "success"; /** Contains the stable result label for a failed metric event. */ export declare const METRIC_RESULT_ERROR = "error"; /** Contains the suggested prefix for SDK metrics in a monitoring system. */ export declare const DEFAULT_METRIC_PREFIX = "jssdk"; /** Defines the result labels used by SDK metric events. */ export type MetricResult = typeof METRIC_RESULT_SUCCESS | typeof METRIC_RESULT_ERROR; /** Describes one attempt to acquire an access token. */ export interface TokenAcquireMetric { /** Identifies the credential implementation, such as `service-account`. */ provider: string; /** Contains the result. */ result: MetricResult; /** Contains elapsed wall-clock duration in seconds. */ durationSeconds: number; /** Contains the one-based acquisition attempt number for this receiver. */ attempt: number; } /** Describes the remaining lifetime of an acquired token. */ export interface TokenLifetimeMetric { /** Contains the provider. */ provider: string; /** Contains the non-negative lifetime in seconds at acquisition time. */ ttlSeconds: number; } /** Describes one token refresh. */ export interface TokenRefreshMetric { /** Contains the provider. */ provider: string; /** Contains the result. */ result: MetricResult; /** Contains the duration in seconds. */ durationSeconds: number; /** Specifies whether the refresh ran in the background. */ background: boolean; } /** Describes one token-cache action. */ export interface CacheMetric { /** Contains the provider. */ provider: string; /** Contains the result when the cache action can fail. */ result?: MetricResult; } /** Describes a configuration or credential-resolution action. */ export interface ConfigMetric { /** Identifies the source, such as `file`, `env`, or `service-account`. */ source: string; /** Contains the result. */ result: MetricResult; /** Contains the duration in seconds. */ durationSeconds: number; } /** * Receives authorization metric events. * * Implement only the callbacks that you need by passing a * {@link AuthMetricsLike}. The SDK does not include token values in events. * Callback failures do not fail SDK work. */ export interface AuthMetrics { /** Records a token acquisition. */ tokenAcquire(metric: TokenAcquireMetric): void; /** Records a token lifetime. */ tokenLifetime(metric: TokenLifetimeMetric): void; /** Records a token refresh. */ tokenRefresh(metric: TokenRefreshMetric): void; /** Records a token-cache hit. */ cacheHit(metric: CacheMetric): void; /** Records a token-cache miss. */ cacheMiss(metric: CacheMetric): void; /** Records a token-cache write. */ cacheStore(metric: CacheMetric): void; /** Records a token-cache refresh. */ cacheRefresh(metric: CacheMetric): void; /** Records a token-cache invalidation. */ cacheInvalidate(metric: CacheMetric): void; } /** * Receives configuration and authorization metric events. * * Pass a partial implementation as * {@link https://nebius.github.io/js-sdk/interfaces/sdk.SDKOptions.html#metrics | SDKOptions.metrics}. * Durations use seconds, which makes them suitable for histogram recorders. * * @example * ```ts * import { SDK } from '@nebius/js-sdk'; * * const sdk = new SDK({ * metrics: { * tokenAcquire: ({ provider, result, durationSeconds }) => { * console.log('token acquire', { provider, result, durationSeconds }); * }, * credentialsResolve: ({ source, result, durationSeconds }) => { * console.log('credentials resolve', { source, result, durationSeconds }); * }, * }, * userAgentPrefix: 'example-application/1.0', * }); * ``` */ export interface Metrics extends AuthMetrics { /** Records the result of a configuration load. */ configLoad(metric: ConfigMetric): void; /** Records the result of credential resolution. */ credentialsResolve(metric: ConfigMetric): void; } /** Defines an optional subset of authorization metric callbacks. */ export type AuthMetricsLike = Partial | undefined; /** Defines an optional subset of all SDK metric callbacks. */ export type MetricsLike = Partial | undefined; /** * Defines either callback functions or an existing shared recorder. * * Credential implementations use this type to keep one callback set while * they change the provider label. */ export type AuthMetricsInput = AuthMetricsLike | AuthMetricsRecorder; /** * Defines suggested names for exporting SDK events to a monitoring system. * * The SDK emits callbacks, not named metrics. Your monitoring adapter can use * these names or replace them with its own naming convention. */ export interface MetricNames { /** Contains the token acquire duration. */ tokenAcquireDuration: string; /** Contains the token refresh. */ tokenRefresh: string; /** Contains the token refresh duration. */ tokenRefreshDuration: string; /** Contains the token lifetime. */ tokenLifetime: string; /** Contains the cache hit. */ cacheHit: string; /** Contains the cache miss. */ cacheMiss: string; /** Contains the cache store. */ cacheStore: string; /** Contains the cache refresh. */ cacheRefresh: string; /** Contains the cache invalidate. */ cacheInvalidate: string; /** Contains the config load. */ configLoad: string; /** Contains the credentials resolve. */ credentialsResolve: string; } /** Returns a new set of suggested SDK metric names without a prefix. */ export declare function defaultMetricNames(): MetricNames; /** * Joins a prefix and metric name with exactly one underscore. * * Empty input is allowed. For example, `metricName('app_', '_calls')` returns * `app_calls`. */ export declare function metricName(prefix: string, name: string): string; /** * Returns a high-resolution start value for {@link metricDurationMs}. * * The value has no defined epoch. Use it only for elapsed time. */ export declare function metricStart(): number; /** Returns elapsed milliseconds since a value from {@link metricStart}. */ export declare function metricDurationMs(start: number): number; /** * Sends normalized authorization events to a shared callback set. * * This is a low-level helper for credential implementations. Application code * normally passes callbacks through * {@link https://nebius.github.io/js-sdk/interfaces/sdk.SDKOptions.html#metrics | SDKOptions.metrics} * or * {@link https://nebius.github.io/js-sdk/interfaces/sdk.SDKOptions.html#authmetrics | SDKOptions.authMetrics}. * * Recorder instances created with {@link withProvider} share the same mutable * callback set. Calling {@link setMetrics} on one of them updates all recorder * instances in that group. */ export declare class AuthMetricsRecorder { /** Identifies the credential provider on every emitted event. */ readonly provider: string; private cell; /** Creates a recorder with a provider label and callback set. */ constructor(metrics: AuthMetricsInput, /** Identifies the credential provider on every emitted event. */ provider: string); /** Returns a recorder that shares callbacks and uses another provider label. */ withProvider(provider: string): AuthMetricsRecorder; /** Replaces the shared callback set for this recorder group. */ setMetrics(metrics: AuthMetricsInput): void; /** Records a token acquisition. */ tokenAcquire(result: MetricResult, durationMs: number, attempt: number): void; /** * Records a token lifetime when the token has an expiration time. * * Tokens without an expiration time do not produce an event. */ tokenLifetime(token: Token): void; /** Records a token refresh. */ tokenRefresh(result: MetricResult, durationMs: number, background?: boolean): void; /** Records a token-cache hit. */ cacheHit(): void; /** Records a token-cache miss. */ cacheMiss(result: MetricResult): void; /** Records a token-cache write. */ cacheStore(result: MetricResult): void; /** Records a token-cache refresh. */ cacheRefresh(result: MetricResult): void; /** Records a token-cache invalidation. */ cacheInvalidate(): void; } /** * Returns an authorization metrics recorder for a provider. * * When `metrics` is already a recorder, the result shares its callbacks and * changes only the provider label. */ export declare function authMetricsRecorder(metrics: AuthMetricsInput, provider: string): AuthMetricsRecorder; /** Returns a bearer's provider label, or `custom` when it has none. */ export declare function authMetricProvider(bearer: Bearer | undefined): string; /** * Adds metric recording to a bearer when callbacks are present. * * The returned bearer can be the input object or a wrapper. Use the return * value for later token requests. */ export declare function instrumentBearer(bearer: Bearer, metrics: AuthMetricsLike): Bearer; /** * Connects a bearer to authorization metrics. * * A bearer that supports metric injection is updated in place. Other bearers * are wrapped. No wrapper is created when `metrics` is absent. */ export declare function bindAuthMetrics(bearer: Bearer, metrics: AuthMetricsInput): Bearer; /** * Records a configuration or credential-resolution metric. * * `durationMs` is converted to seconds. Missing callbacks and callback errors * are ignored. */ export declare function recordConfigMetric(metrics: MetricsLike, kind: 'configLoad' | 'credentialsResolve', source: string, result: MetricResult, durationMs: number): void; //# sourceMappingURL=metrics.d.ts.map