/** * Copyright (c) 2025 Databricks Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import IClientContext from '../contracts/IClientContext'; import TelemetryClient from './TelemetryClient'; /** * Process-wide registry of `TelemetryClient`s, one per host. Multiple * `DBSQLClient` instances connecting to the same host share the same * `TelemetryClient`, which owns the host-scoped circuit breaker, feature * flag cache, exporter, and aggregator. * * Singleton because the resources we're sharing — circuit-breaker counters, * batched HTTP exports — are correct only at process scope. Per-`DBSQLClient` * provider scope (the previous design) deduplicates nothing. * * `getOrCreateClient` is sync: caller increments refcount, registers its * context+auth, and walks away. `releaseClient` is `async` because the * underlying `TelemetryClient.close()` awaits the final flush. */ declare class TelemetryClientProvider { private static instance; private clients; private softLimitWarned; static getInstance(): TelemetryClientProvider; /** * Reset the process-wide singleton. Test-only — name-prefixed so * production callsites can't reach for it accidentally via autocomplete. * Resetting in production drops every host's circuit-breaker counters, * feature-flag cache, exporter, and pending-metric buffer at once. * * @internal Test-only. Production code MUST NOT call this. */ static __resetInstanceForTests(): void; private static normalizeHostKey; /** * Get or create the `TelemetryClient` for `host`, registering `context` as * a participant. Increments refcount. */ getOrCreateClient(context: IClientContext, host: string): TelemetryClient; /** * Release `context`'s registration. When the last `DBSQLClient` releases, * the underlying `TelemetryClient.close()` runs and the entry is removed. */ releaseClient(context: IClientContext, host: string): Promise; /** @internal Exposed for testing only. */ getRefCount(host: string): number; /** @internal Exposed for testing only. */ getActiveClients(): Map; } export default TelemetryClientProvider;