Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
db640fa
Add telemetry infrastructure: CircuitBreaker and FeatureFlagCache
samikshya-db Jan 28, 2026
211f91c
Add authentication support for REST API calls
samikshya-db Jan 29, 2026
c3779af
Fix feature flag and telemetry export endpoints
samikshya-db Jan 29, 2026
a105777
Match JDBC telemetry payload format
samikshya-db Jan 29, 2026
1cdb716
Fix lint errors
samikshya-db Jan 29, 2026
8721993
Add telemetry infrastructure: CircuitBreaker and FeatureFlagCache
samikshya-db Jan 28, 2026
fd10a69
Add telemetry client management: TelemetryClient and Provider
samikshya-db Jan 28, 2026
dd2bac8
Add authentication support for REST API calls
samikshya-db Jan 29, 2026
4437ae9
Fix feature flag and telemetry export endpoints
samikshya-db Jan 29, 2026
e9c3138
Match JDBC telemetry payload format
samikshya-db Jan 29, 2026
32003e9
Fix lint errors
samikshya-db Jan 29, 2026
dfab781
Add telemetry infrastructure: CircuitBreaker and FeatureFlagCache
samikshya-db Jan 28, 2026
9f7d84c
Add telemetry client management: TelemetryClient and Provider
samikshya-db Jan 28, 2026
03b8f77
Add telemetry event emission and aggregation
samikshya-db Jan 28, 2026
a00c482
Add authentication support for REST API calls
samikshya-db Jan 29, 2026
33fcc22
Fix feature flag and telemetry export endpoints
samikshya-db Jan 29, 2026
1b49399
Match JDBC telemetry payload format
samikshya-db Jan 29, 2026
29376a6
Fix lint errors
samikshya-db Jan 29, 2026
da2e6d3
Add telemetry infrastructure: CircuitBreaker and FeatureFlagCache
samikshya-db Jan 28, 2026
02b2368
Add telemetry client management: TelemetryClient and Provider
samikshya-db Jan 28, 2026
3fcc454
Add telemetry event emission and aggregation
samikshya-db Jan 28, 2026
1daf6b5
Add telemetry export: DatabricksTelemetryExporter
samikshya-db Jan 28, 2026
d5ae8fb
Add authentication support for REST API calls
samikshya-db Jan 29, 2026
f75eb3d
Update DatabricksTelemetryExporter to use authenticated export
samikshya-db Jan 29, 2026
6663aad
Fix feature flag endpoint and telemetry export
samikshya-db Jan 29, 2026
36f2878
Match JDBC telemetry payload format
samikshya-db Jan 29, 2026
5c1851a
Fix lint errors
samikshya-db Jan 29, 2026
b6a3962
Add telemetry infrastructure: CircuitBreaker and FeatureFlagCache
samikshya-db Jan 28, 2026
68652de
Add telemetry client management: TelemetryClient and Provider
samikshya-db Jan 28, 2026
97f2106
Add telemetry event emission and aggregation
samikshya-db Jan 28, 2026
44185e4
Add telemetry export: DatabricksTelemetryExporter
samikshya-db Jan 28, 2026
013f305
Add telemetry integration into driver components
samikshya-db Jan 28, 2026
e357588
Add authentication support for REST API calls
samikshya-db Jan 29, 2026
e8c2033
Update DatabricksTelemetryExporter to use authenticated export
samikshya-db Jan 29, 2026
a2dbfb1
Fix telemetry event listeners and add config options
samikshya-db Jan 29, 2026
62545d6
Match JDBC telemetry payload format
samikshya-db Jan 29, 2026
9ac0978
Fix lint errors
samikshya-db Jan 29, 2026
689e561
Add missing getAuthHeaders method to ClientContextStub
samikshya-db Jan 29, 2026
bfb8303
Add missing getAuthHeaders method to ClientContextStub
samikshya-db Jan 29, 2026
4df6ce0
Add missing getAuthHeaders method to ClientContextStub
samikshya-db Jan 29, 2026
4effbc5
Add missing getAuthHeaders method to ClientContextStub
samikshya-db Jan 29, 2026
39f3c00
Add missing getAuthHeaders method to ClientContextStub
samikshya-db Jan 29, 2026
2d41e2d
Fix prettier formatting
samikshya-db Jan 29, 2026
ce7723a
Fix prettier formatting
samikshya-db Jan 29, 2026
589e062
Fix prettier formatting
samikshya-db Jan 29, 2026
844a187
Fix prettier formatting
samikshya-db Jan 29, 2026
d646c31
Fix prettier formatting
samikshya-db Jan 29, 2026
b8d20bf
Use nodejs-sql-driver as driver name in telemetry
samikshya-db Jan 30, 2026
e474256
Add DRIVER_NAME constant for nodejs-sql-driver
samikshya-db Jan 30, 2026
d7d2cec
Add DRIVER_NAME constant for nodejs-sql-driver
samikshya-db Jan 30, 2026
95ea6e0
Add DRIVER_NAME constant for nodejs-sql-driver
samikshya-db Jan 30, 2026
7cb09e9
Add DRIVER_NAME constant for nodejs-sql-driver
samikshya-db Jan 30, 2026
a3c9042
Add missing telemetry fields to match JDBC
samikshya-db Jan 30, 2026
43e404d
Add missing telemetry fields to match JDBC
samikshya-db Jan 30, 2026
c2daa4b
Populate all telemetry system configuration fields
samikshya-db Jan 30, 2026
5b47e7e
Add missing telemetry fields to match JDBC
samikshya-db Jan 30, 2026
bd031ca
Add missing telemetry fields to match JDBC
samikshya-db Jan 30, 2026
c5d4cfc
Add missing telemetry fields to match JDBC
samikshya-db Jan 30, 2026
228c2be
Fix telemetry aggregator cleanup in client close
samikshya-db Jan 30, 2026
6110797
Fix TypeScript compilation: add missing fields to system_configuratio…
samikshya-db Jan 30, 2026
7c5c16c
Fix TypeScript compilation: add missing fields to system_configuratio…
samikshya-db Jan 30, 2026
d68af66
Fix TypeScript compilation: add missing fields to system_configuratio…
samikshya-db Jan 30, 2026
288f624
Fix TypeScript compilation: add missing fields to system_configuratio…
samikshya-db Jan 30, 2026
f9bd330
Merge branch 'telemetry-2-infrastructure' into telemetry-3-client-man…
samikshya-db Jan 30, 2026
a98bdfd
Merge branch 'telemetry-3-client-management' into telemetry-4-event-a…
samikshya-db Jan 30, 2026
b2bbd0a
Merge branch 'telemetry-4-event-aggregation' into telemetry-5-export
samikshya-db Jan 30, 2026
4f6d5a6
Merge branch 'telemetry-5-export' into telemetry-6-integration
samikshya-db Jan 30, 2026
ac3f625
Add telemetry testing and documentation
samikshya-db Jan 28, 2026
6f5f72e
Add authentication support for REST API calls in telemetry
samikshya-db Jan 29, 2026
4badcc5
Fix telemetry and feature flag implementation
samikshya-db Jan 29, 2026
ee7fafe
Fix prettier formatting
samikshya-db Jan 29, 2026
b9cf684
Update telemetry design doc with system config and protoLogs format
samikshya-db Jan 30, 2026
ea1643b
Document telemetry export lifecycle and timing
samikshya-db Jan 30, 2026
29cc1b2
Merge branch 'telemetry-6-integration' into telemetry-7-documentation
samikshya-db Jan 30, 2026
c0e3a43
Add connection open latency tracking and enable telemetry by default
samikshya-db Jan 30, 2026
728f0d7
Populate sql_operation, statement_id, and auth_type in telemetry
samikshya-db Jan 30, 2026
d60b514
Map auth type to telemetry auth enum
samikshya-db Jan 30, 2026
d1d08d9
Add SqlExecutionEvent fields to telemetry
samikshya-db Jan 30, 2026
a8ec232
Filter out NIL UUID from statement ID in telemetry
samikshya-db Jan 30, 2026
42f1e23
Only populate sql_operation fields when present
samikshya-db Jan 30, 2026
658870f
Map Thrift operation type to proto Operation.Type enum
samikshya-db Jan 30, 2026
70c038c
Move auth_type to top level per proto definition
samikshya-db Jan 30, 2026
90fb7cd
Map result format to proto ExecutionResult.Format enum
samikshya-db Jan 30, 2026
8d6d819
Refactor telemetry type mappers to separate file
samikshya-db Jan 30, 2026
25c8f51
Add driver_connection_params with available fields
samikshya-db Jan 30, 2026
53189a8
Document proto field coverage in design doc
samikshya-db Jan 30, 2026
a37fdf0
Include system_configuration, driver_connection_params, and auth_type…
samikshya-db Jan 30, 2026
239e555
Add connection close telemetry event
samikshya-db Jan 30, 2026
e7f2144
Fix unit tests for connection close telemetry
samikshya-db Jan 30, 2026
d9cc2c9
Add connection.close event listener to telemetry wire-up
samikshya-db Jan 30, 2026
8ff09a9
Make telemetry logging silent by default
samikshya-db Jan 30, 2026
316d1e9
Ensure statement_type always populated in telemetry
samikshya-db Jan 30, 2026
adb70bc
Add operation types to connection metrics
samikshya-db Jan 30, 2026
09cde19
Fix telemetry proto field mapping
samikshya-db Jan 30, 2026
ee78dec
Add operation_detail field to telemetry interface and enhance test
samikshya-db Jan 30, 2026
a3c049f
Add error scenario test for telemetry validation
samikshya-db Jan 30, 2026
0f4ec12
Fix telemetry PR review comments from #325
samikshya-db Feb 5, 2026
42540bc
Fix telemetry PR review comments from #325
samikshya-db Feb 5, 2026
99eb2ab
Merge PR #325 fixes into PR #326
samikshya-db Feb 5, 2026
bdf8c5a
Merge PR #326 fixes into PR #327
samikshya-db Feb 5, 2026
3bef69c
Merge PR #327 fixes into PR #328
samikshya-db Feb 5, 2026
72372d2
Merge PR #328 fixes into PR #329
samikshya-db Feb 5, 2026
aa59460
Merge PR #329 fixes into PR #330
samikshya-db Feb 5, 2026
57b331c
Add proxy support to feature flag fetching
samikshya-db Feb 5, 2026
11590f3
Add proxy support to feature flag fetching
samikshya-db Feb 5, 2026
bda2cac
Merge telemetry-2-infrastructure proxy fix into telemetry-3-client-ma…
samikshya-db Feb 5, 2026
bb7a913
Merge telemetry-3-client-management proxy fix into telemetry-4-event-…
samikshya-db Feb 5, 2026
fa356e1
Merge telemetry-4-event-aggregation proxy fix into telemetry-5-export
samikshya-db Feb 5, 2026
86d7b8d
Merge telemetry-5-export proxy fix into telemetry-6-integration
samikshya-db Feb 5, 2026
a117e87
Merge telemetry-6-integration proxy fix into telemetry-7-documentation
samikshya-db Feb 5, 2026
168ebfc
Make feature flag cache extensible for multiple flags
samikshya-db Feb 5, 2026
c3494c1
Merge extensible feature flags from telemetry-4-event-aggregation
samikshya-db Feb 5, 2026
265dde4
Merge extensible feature flags from telemetry-5-export
samikshya-db Feb 5, 2026
77b740a
Merge extensible feature flags from telemetry-6-integration
samikshya-db Feb 5, 2026
74cd522
Add circuit breaker protection to feature flag fetching
samikshya-db Feb 5, 2026
575ca47
Fix telemetry unit tests for extensible feature flags and proto paylo…
samikshya-db Feb 5, 2026
fce4499
Merge latest main into telemetry-3-client-management
samikshya-db Mar 5, 2026
3590e09
Merge latest main into telemetry-4-event-aggregation
samikshya-db Mar 5, 2026
de17f1b
Merge latest main into telemetry-2-infrastructure
samikshya-db Mar 5, 2026
91ab633
Merge branch 'telemetry-3-client-management' into telemetry-4-event-a…
samikshya-db Apr 2, 2026
363e2fc
Merge branch 'telemetry-2-infrastructure' into telemetry-3-client-man…
samikshya-db Apr 2, 2026
38e9d03
Merge main into telemetry-3-client-management; prefer main versions f…
samikshya-db Apr 21, 2026
e81ad15
Merge main — take main's DatabricksTelemetryExporter, FeatureFlagCach…
samikshya-db Apr 21, 2026
d009957
fix: prettier formatting and add coverage/ to .prettierignore
samikshya-db Apr 21, 2026
990ec15
fix: delete host entry before awaiting close to prevent stale-client …
samikshya-db Apr 21, 2026
2749751
refactor: simplify TelemetryClient.close() and TelemetryClientProvider
samikshya-db Apr 21, 2026
dbeff48
Merge telemetry-3-client-management: sync TelemetryClient.close(), fi…
samikshya-db Apr 21, 2026
457b67d
Merge main into telemetry-4-event-aggregation
samikshya-db Apr 22, 2026
1c0fff1
chore: move telemetry MD docs to follow-up PR
samikshya-db Apr 22, 2026
64e2cb9
chore: drop tests/e2e/telemetry-local.test.ts
samikshya-db Apr 22, 2026
e8dadb6
chore: remove unused CircuitBreaker import in FeatureFlagCache
samikshya-db Apr 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
309 changes: 309 additions & 0 deletions lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import thrift from 'thrift';
import Int64 from 'node-int64';
import os from 'os';

import { EventEmitter } from 'events';
import TCLIService from '../thrift/TCLIService';
Expand Down Expand Up @@ -31,6 +32,14 @@ import IDBSQLLogger, { LogLevel } from './contracts/IDBSQLLogger';
import DBSQLLogger from './DBSQLLogger';
import CloseableCollection from './utils/CloseableCollection';
import IConnectionProvider from './connection/contracts/IConnectionProvider';
import FeatureFlagCache from './telemetry/FeatureFlagCache';
import TelemetryClientProvider from './telemetry/TelemetryClientProvider';
import TelemetryEventEmitter from './telemetry/TelemetryEventEmitter';
import MetricsAggregator from './telemetry/MetricsAggregator';
import DatabricksTelemetryExporter from './telemetry/DatabricksTelemetryExporter';
import { CircuitBreakerRegistry } from './telemetry/CircuitBreaker';
import { DriverConfiguration, DRIVER_NAME } from './telemetry/types';
import driverVersion from './version';

function prependSlash(str: string): string {
if (str.length > 0 && str.charAt(0) !== '/') {
Expand Down Expand Up @@ -75,6 +84,23 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I

private readonly sessions = new CloseableCollection<DBSQLSession>();

// Telemetry components (instance-based, NOT singletons)
private host?: string;

private httpPath?: string;

private authType?: string;

private featureFlagCache?: FeatureFlagCache;

private telemetryClientProvider?: TelemetryClientProvider;

private telemetryEmitter?: TelemetryEventEmitter;

private telemetryAggregator?: MetricsAggregator;

private circuitBreakerRegistry?: CircuitBreakerRegistry;

private static getDefaultLogger(): IDBSQLLogger {
if (!this.defaultLogger) {
this.defaultLogger = new DBSQLLogger();
Expand All @@ -101,6 +127,15 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
cloudFetchSpeedThresholdMBps: 0.1,

useLZ4Compression: true,

// Telemetry defaults
telemetryEnabled: true, // Enabled by default, gated by feature flag
telemetryBatchSize: 100,
telemetryFlushIntervalMs: 5000,
telemetryMaxRetries: 3,
telemetryAuthenticatedExport: true,
telemetryCircuitBreakerThreshold: 5,
telemetryCircuitBreakerTimeout: 60000, // 1 minute
};
}

Expand Down Expand Up @@ -212,6 +247,214 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
return new HttpConnection(this.getConnectionOptions(options), this);
}

/**
* Extract workspace ID from hostname.
* @param host - The host string (e.g., "workspace-id.cloud.databricks.com")
* @returns Workspace ID or host if extraction fails
*/
private extractWorkspaceId(host: string): string {
// Extract workspace ID from hostname (first segment before first dot)
const parts = host.split('.');
return parts.length > 0 ? parts[0] : host;
}

/**
* Build driver configuration for telemetry reporting.
* @returns DriverConfiguration object with current driver settings
*/
private buildDriverConfiguration(): DriverConfiguration {
return {
driverVersion,
driverName: DRIVER_NAME,
nodeVersion: process.version,
platform: process.platform,
osVersion: os.release(),
osArch: os.arch(),
runtimeVendor: 'Node.js Foundation',
localeName: this.getLocaleName(),
charSetEncoding: 'UTF-8',
processName: this.getProcessName(),
authType: this.authType || 'pat',

// Feature flags
cloudFetchEnabled: this.config.useCloudFetch ?? false,
lz4Enabled: this.config.useLZ4Compression ?? false,
arrowEnabled: this.config.arrowEnabled ?? false,
directResultsEnabled: true, // Direct results always enabled

// Configuration values
socketTimeout: this.config.socketTimeout ?? 0,
retryMaxAttempts: this.config.retryMaxAttempts ?? 0,
cloudFetchConcurrentDownloads: this.config.cloudFetchConcurrentDownloads ?? 0,

// Connection parameters
httpPath: this.httpPath,
enableMetricViewMetadata: this.config.enableMetricViewMetadata,
};
}

/**
* Map Node.js auth type to telemetry auth enum string.
* Distinguishes between U2M and M2M OAuth flows.
*/
private mapAuthType(options: ConnectionOptions): string {
if (options.authType === 'databricks-oauth') {
// Check if M2M (has client secret) or U2M (no client secret)
return options.oauthClientSecret === undefined
? 'external-browser' // U2M OAuth (User-to-Machine)
: 'oauth-m2m'; // M2M OAuth (Machine-to-Machine)
}

if (options.authType === 'custom') {
return 'custom'; // Custom auth provider
}

// 'access-token' or undefined
return 'pat'; // Personal Access Token
}

/**
* Get locale name in format language_country (e.g., en_US).
* Matches JDBC format: user.language + '_' + user.country
*/
private getLocaleName(): string {
try {
// Try to get from environment variables
const lang = process.env.LANG || process.env.LC_ALL || process.env.LC_MESSAGES || '';
if (lang) {
// LANG format is typically "en_US.UTF-8", extract "en_US"
const match = lang.match(/^([a-z]{2}_[A-Z]{2})/);
if (match) {
return match[1];
}
}
// Fallback to en_US
return 'en_US';
} catch {
return 'en_US';
}
}

/**
* Get process name, similar to JDBC's ProcessNameUtil.
* Returns the script name or process title.
*/
private getProcessName(): string {
try {
// Try process.title first (can be set by application)
if (process.title && process.title !== 'node') {
return process.title;
}
// Try to get the main script name from argv[1]
if (process.argv && process.argv.length > 1) {
const scriptPath = process.argv[1];
// Extract filename without path
const filename = scriptPath.split('/').pop()?.split('\\').pop() || '';
// Remove extension
const nameWithoutExt = filename.replace(/\.[^.]*$/, '');
if (nameWithoutExt) {
return nameWithoutExt;
}
}
return 'node';
} catch {
return 'node';
}
}

/**
* Initialize telemetry components if enabled.
* CRITICAL: All errors swallowed and logged at LogLevel.debug ONLY.
* Driver NEVER throws exceptions due to telemetry.
*/
private async initializeTelemetry(): Promise<void> {
if (!this.host) {
return;
}

try {
// Create circuit breaker registry (shared by feature flags and telemetry)
this.circuitBreakerRegistry = new CircuitBreakerRegistry(this);

// Create feature flag cache instance with circuit breaker protection
this.featureFlagCache = new FeatureFlagCache(this, this.circuitBreakerRegistry);
this.featureFlagCache.getOrCreateContext(this.host);

// Check if telemetry enabled via feature flag
const enabled = await this.featureFlagCache.isTelemetryEnabled(this.host);

if (!enabled) {
this.logger.log(LogLevel.debug, 'Telemetry: disabled');
return;
}

// Create telemetry components (all instance-based)
this.telemetryClientProvider = new TelemetryClientProvider(this);
this.telemetryEmitter = new TelemetryEventEmitter(this);

// Get or create telemetry client for this host (increments refCount)
this.telemetryClientProvider.getOrCreateClient(this.host);

// Create telemetry exporter with shared circuit breaker registry
const exporter = new DatabricksTelemetryExporter(this, this.host, this.circuitBreakerRegistry);
this.telemetryAggregator = new MetricsAggregator(this, exporter);

// Wire up event listeners
this.telemetryEmitter.on('connection.open', (event) => {
try {
this.telemetryAggregator?.processEvent(event);
} catch (error: any) {
this.logger.log(LogLevel.debug, `Error processing connection.open event: ${error.message}`);
}
});

this.telemetryEmitter.on('connection.close', (event) => {
try {
this.telemetryAggregator?.processEvent(event);
} catch (error: any) {
this.logger.log(LogLevel.debug, `Error processing connection.close event: ${error.message}`);
}
});

this.telemetryEmitter.on('statement.start', (event) => {
try {
this.telemetryAggregator?.processEvent(event);
} catch (error: any) {
this.logger.log(LogLevel.debug, `Error processing statement.start event: ${error.message}`);
}
});

this.telemetryEmitter.on('statement.complete', (event) => {
try {
this.telemetryAggregator?.processEvent(event);
} catch (error: any) {
this.logger.log(LogLevel.debug, `Error processing statement.complete event: ${error.message}`);
}
});

this.telemetryEmitter.on('cloudfetch.chunk', (event) => {
try {
this.telemetryAggregator?.processEvent(event);
} catch (error: any) {
this.logger.log(LogLevel.debug, `Error processing cloudfetch.chunk event: ${error.message}`);
}
});

this.telemetryEmitter.on('error', (event) => {
try {
this.telemetryAggregator?.processEvent(event);
} catch (error: any) {
this.logger.log(LogLevel.debug, `Error processing error event: ${error.message}`);
}
});

this.logger.log(LogLevel.debug, 'Telemetry: enabled');
} catch (error: any) {
// Swallow all telemetry initialization errors
this.logger.log(LogLevel.debug, `Telemetry initialization error: ${error.message}`);
}
}

/**
* Connects DBSQLClient to endpoint
* @public
Expand All @@ -233,11 +476,27 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
}
}

// Store connection params for telemetry
this.host = options.host;
this.httpPath = options.path;
this.authType = this.mapAuthType(options);

// Store enableMetricViewMetadata configuration
if (options.enableMetricViewMetadata !== undefined) {
this.config.enableMetricViewMetadata = options.enableMetricViewMetadata;
}

// Override telemetry config if provided in options
if (options.telemetryEnabled !== undefined) {
this.config.telemetryEnabled = options.telemetryEnabled;
}
if (options.telemetryBatchSize !== undefined) {
this.config.telemetryBatchSize = options.telemetryBatchSize;
}
if (options.telemetryAuthenticatedExport !== undefined) {
this.config.telemetryAuthenticatedExport = options.telemetryAuthenticatedExport;
}

// Persist userAgentEntry so telemetry and feature-flag call sites reuse
// the same value as the primary Thrift connection's User-Agent.
if (options.userAgentEntry !== undefined) {
Expand Down Expand Up @@ -277,6 +536,11 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
this.emit('timeout');
});

// Initialize telemetry if enabled
if (this.config.telemetryEnabled) {
await this.initializeTelemetry();
}

return this;
}

Expand All @@ -290,6 +554,9 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
* const session = await client.openSession();
*/
public async openSession(request: OpenSessionRequest = {}): Promise<IDBSQLSession> {
// Track connection open latency
const startTime = Date.now();

// Prepare session configuration
const configuration = request.configuration ? { ...request.configuration } : {};

Expand All @@ -312,12 +579,54 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
serverProtocolVersion: response.serverProtocolVersion,
});
this.sessions.add(session);

// Emit connection.open telemetry event
if (this.telemetryEmitter && this.host) {
try {
const latencyMs = Date.now() - startTime;
const workspaceId = this.extractWorkspaceId(this.host);
const driverConfig = this.buildDriverConfiguration();
this.telemetryEmitter.emitConnectionOpen({
sessionId: session.id,
workspaceId,
driverConfig,
latencyMs,
});
} catch (error: any) {
// CRITICAL: All telemetry exceptions swallowed
this.logger.log(LogLevel.debug, `Error emitting connection.open event: ${error.message}`);
}
}

return session;
}

public async close(): Promise<void> {
await this.sessions.closeAll();

// Cleanup telemetry
if (this.host) {
try {
// Step 1: Close aggregator (stops timer, completes statements, final flush)
if (this.telemetryAggregator) {
this.telemetryAggregator.close();
}

// Step 2: Release telemetry client (decrements ref count, closes if last)
if (this.telemetryClientProvider) {
await this.telemetryClientProvider.releaseClient(this.host);
}

// Step 3: Release feature flag context (decrements ref count)
if (this.featureFlagCache) {
this.featureFlagCache.releaseContext(this.host);
}
} catch (error: any) {
// Swallow all telemetry cleanup errors
this.logger.log(LogLevel.debug, `Telemetry cleanup error: ${error.message}`);
}
}

this.client = undefined;
this.connectionProvider = undefined;
this.authProvider = undefined;
Expand Down
Loading
Loading