Skip to content

Commit 728f0d7

Browse files
samikshya-dbclaude
andcommitted
Populate sql_operation, statement_id, and auth_type in telemetry
Fixes: - sql_operation now properly populated by fetching metadata before statement close - statement_id always populated from operation handle GUID - auth_type now included in driver_connection_params Changes: - DBSQLOperation: Fetch metadata before emitting statement.complete to ensure resultFormat is available for sql_operation field - DBSQLClient: Track authType from connection options and include in driver configuration - DatabricksTelemetryExporter: Export auth_type in driver_connection_params - types.ts: Add authType to DriverConfiguration interface - Design doc: Document auth_type, resultFormat population, and connection params Implementation details: - emitStatementComplete() is now async to await metadata fetch - Auth type defaults to 'access-token' if not specified - Result format fetched even if not explicitly requested by user - Handles metadata fetch failures gracefully (continues without resultFormat) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: samikshya-chand_data <samikshya.chand@databricks.com>
1 parent c0e3a43 commit 728f0d7

5 files changed

Lines changed: 36 additions & 12 deletions

File tree

lib/DBSQLClient.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
8080
// Telemetry components (instance-based, NOT singletons)
8181
private host?: string;
8282

83+
private authType?: string;
84+
8385
private featureFlagCache?: FeatureFlagCache;
8486

8587
private telemetryClientProvider?: TelemetryClientProvider;
@@ -210,6 +212,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
210212
localeName: this.getLocaleName(),
211213
charSetEncoding: 'UTF-8',
212214
processName: this.getProcessName(),
215+
authType: this.authType || 'access-token',
213216

214217
// Feature flags
215218
cloudFetchEnabled: this.config.useCloudFetch ?? false,
@@ -377,8 +380,9 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
377380
}
378381
}
379382

380-
// Store host for telemetry
383+
// Store host and auth type for telemetry
381384
this.host = options.host;
385+
this.authType = options.authType || 'access-token'; // Default to access-token
382386

383387
// Store enableMetricViewMetadata configuration
384388
if (options.enableMetricViewMetadata !== undefined) {

lib/DBSQLOperation.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export default class DBSQLOperation implements IOperation {
296296
const result = new Status(response.status);
297297

298298
// Emit statement.complete telemetry event
299-
this.emitStatementComplete();
299+
await this.emitStatementComplete();
300300

301301
this.onClose?.();
302302
return result;
@@ -526,18 +526,29 @@ export default class DBSQLOperation implements IOperation {
526526
* Emit statement.complete telemetry event and complete aggregation.
527527
* CRITICAL: All exceptions swallowed and logged at LogLevel.debug ONLY.
528528
*/
529-
private emitStatementComplete(): void {
529+
private async emitStatementComplete(): Promise<void> {
530530
try {
531531
const {telemetryEmitter} = (this.context as any);
532532
const {telemetryAggregator} = (this.context as any);
533533
if (!telemetryEmitter || !telemetryAggregator) {
534534
return;
535535
}
536536

537+
// Fetch metadata if not already fetched to get result format
538+
let resultFormat: string | undefined;
539+
try {
540+
if (!this.metadata && !this.cancelled) {
541+
await this.getMetadata();
542+
}
543+
resultFormat = this.metadata?.resultFormat
544+
? TSparkRowSetType[this.metadata.resultFormat]
545+
: undefined;
546+
} catch (error) {
547+
// If metadata fetch fails, continue without it
548+
resultFormat = undefined;
549+
}
550+
537551
const latencyMs = Date.now() - this.startTime;
538-
const resultFormat = this.metadata?.resultFormat
539-
? TSparkRowSetType[this.metadata.resultFormat]
540-
: undefined;
541552

542553
telemetryEmitter.emitStatementComplete({
543554
statementId: this.id,

lib/telemetry/DatabricksTelemetryExporter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ export default class DatabricksTelemetryExporter {
293293
if (metric.latencyMs !== undefined) {
294294
log.entry.sql_driver_log.operation_latency_ms = metric.latencyMs;
295295
}
296+
// Include driver connection params (auth type)
297+
log.entry.sql_driver_log.driver_connection_params = {
298+
auth_type: metric.driverConfig.authType,
299+
};
296300
} else if (metric.metricType === 'statement') {
297301
log.entry.sql_driver_log.operation_latency_ms = metric.latencyMs;
298302

lib/telemetry/types.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export enum TelemetryEventType {
3030
ERROR = 'error',
3131
}
3232

33-
/**
34-
* Driver name constant for telemetry
35-
*/
36-
export const DRIVER_NAME = 'nodejs-sql-driver';
37-
3833
/**
3934
* Configuration for telemetry components
4035
*/
@@ -215,6 +210,9 @@ export interface DriverConfiguration {
215210
/** Process name */
216211
processName: string;
217212

213+
/** Authentication type (access-token, databricks-oauth, custom) */
214+
authType: string;
215+
218216
// Feature flags
219217
/** Whether CloudFetch is enabled */
220218
cloudFetchEnabled: boolean;

spec/telemetry-design.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ interface DriverConfiguration {
12341234
localeName: string; // Locale (e.g., 'en_US')
12351235
charSetEncoding: string; // Character encoding (e.g., 'UTF-8')
12361236
processName: string; // Process name from process.title or script name
1237+
authType: string; // Authentication type (access-token, databricks-oauth, custom)
12371238

12381239
// Feature flags
12391240
cloudFetchEnabled: boolean;
@@ -1255,6 +1256,10 @@ interface DriverConfiguration {
12551256
- **localeName**: Extracted from `LANG` environment variable in format `language_country` (e.g., `en_US`), defaults to `en_US`
12561257
- **charSetEncoding**: Always `'UTF-8'` (Node.js default encoding), equivalent to JDBC's Charset.defaultCharset()
12571258
- **processName**: Obtained from `process.title` or extracted from `process.argv[1]` (script name), equivalent to JDBC's ProcessNameUtil.getProcessName()
1259+
- **authType**: Authentication method used ('access-token', 'databricks-oauth', or 'custom'), exported as `driver_connection_params.auth_type`
1260+
1261+
**Connection Parameters**:
1262+
- **auth_type**: Exported in `driver_connection_params` field for connection metrics, indicates authentication method used
12581263

12591264
### 4.3 Statement Metrics
12601265

@@ -1271,7 +1276,7 @@ interface StatementMetrics {
12711276
pollCount: number;
12721277
pollLatencyMs: number;
12731278

1274-
// Result format
1279+
// Result format (fetched from metadata before statement close)
12751280
resultFormat: 'inline' | 'cloudfetch' | 'arrow';
12761281

12771282
// CloudFetch metrics
@@ -1281,6 +1286,8 @@ interface StatementMetrics {
12811286
}
12821287
```
12831288

1289+
**Result Format Population**: To ensure `sql_operation` is properly populated in telemetry logs, the driver fetches result set metadata before emitting the `statement.complete` event. This guarantees that `resultFormat` is available even if the user closes the statement immediately after execution without explicitly fetching results.
1290+
12841291
### 4.4 Privacy Considerations
12851292

12861293
**Never Collected**:

0 commit comments

Comments
 (0)