/** * 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 IAuthentication from '../connection/contracts/IAuthentication'; import HiveDriverError from '../errors/HiveDriverError'; import { TelemetryMetric } from './types'; import { CircuitBreakerRegistry } from './CircuitBreaker'; /** * Thrown for non-credential terminal telemetry failures (e.g. refusal to * export to an invalid host). Separate from `AuthenticationError` so the * classifier can keep the "short-circuit, don't retry, count as breaker * failure" contract without muddying the auth taxonomy used by the rest of * the driver. */ export declare class TelemetryTerminalError extends HiveDriverError { readonly terminal: true; } /** * Exports telemetry metrics to the Databricks telemetry service. * * CRITICAL: export() never throws — all errors are swallowed and logged at * LogLevel.debug (the one exception is a single warn on the first observed * auth-missing, re-armed on recovery). */ export default class DatabricksTelemetryExporter { private context; private host; private circuitBreakerRegistry; private authProvider?; private readonly circuitBreaker; private readonly authenticatedUserAgent; /** User-Agent used for the unauthenticated endpoint; strips any * caller-supplied `userAgentEntry` that could identify the customer. */ private readonly unauthenticatedUserAgent; private authMissingWarned; constructor(context: IClientContext, host: string, circuitBreakerRegistry: CircuitBreakerRegistry, authProvider?: IAuthentication | undefined); /** * Release the per-host circuit breaker. Intended for the owning client's * close() path. * * NOTE: `CircuitBreakerRegistry` currently shares one breaker per host * across consumers; calling this while another consumer is active will * reset their failure-count memory. The owning-client is expected to be * the last consumer on its host; multi-consumer refcounting on the * registry will land in the consumer-wiring PR. */ dispose(): void; export(metrics: TelemetryMetric[]): Promise; /** * Retry wrapper shaped after HttpRetryPolicy: retries only on errors * classified as retryable by ExceptionClassifier, stops on terminal ones, * surfaces the last error to the circuit breaker. * * `maxRetries` is the number of retries *after* the first attempt (i.e. * attempts = maxRetries + 1), matching HttpRetryPolicy's semantics. */ private exportWithRetry; private exportInternal; private getAuthHeaders; private sendRequest; private toTelemetryLog; private sleep; }