Skip to content

Commit d60b514

Browse files
samikshya-dbclaude
andcommitted
Map auth type to telemetry auth enum
- Convert 'access-token' (or undefined) to 'pat' - Convert 'databricks-oauth' to 'external-browser' (U2M) or 'oauth-m2m' (M2M) - Distinguish M2M from U2M by checking for oauthClientSecret - Keep 'custom' as 'custom' Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 728f0d7 commit d60b514

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/DBSQLClient.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
212212
localeName: this.getLocaleName(),
213213
charSetEncoding: 'UTF-8',
214214
processName: this.getProcessName(),
215-
authType: this.authType || 'access-token',
215+
authType: this.authType || 'pat',
216216

217217
// Feature flags
218218
cloudFetchEnabled: this.config.useCloudFetch ?? false,
@@ -227,6 +227,26 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
227227
};
228228
}
229229

230+
/**
231+
* Map Node.js auth type to telemetry auth enum string.
232+
* Distinguishes between U2M and M2M OAuth flows.
233+
*/
234+
private mapAuthType(options: ConnectionOptions): string {
235+
if (options.authType === 'databricks-oauth') {
236+
// Check if M2M (has client secret) or U2M (no client secret)
237+
return options.oauthClientSecret === undefined
238+
? 'external-browser' // U2M OAuth (User-to-Machine)
239+
: 'oauth-m2m'; // M2M OAuth (Machine-to-Machine)
240+
}
241+
242+
if (options.authType === 'custom') {
243+
return 'custom'; // Custom auth provider
244+
}
245+
246+
// 'access-token' or undefined
247+
return 'pat'; // Personal Access Token
248+
}
249+
230250
/**
231251
* Get locale name in format language_country (e.g., en_US).
232252
* Matches JDBC format: user.language + '_' + user.country
@@ -380,9 +400,9 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
380400
}
381401
}
382402

383-
// Store host and auth type for telemetry
403+
// Store host and auth type for telemetry (convert to telemetry auth enum)
384404
this.host = options.host;
385-
this.authType = options.authType || 'access-token'; // Default to access-token
405+
this.authType = this.mapAuthType(options);
386406

387407
// Store enableMetricViewMetadata configuration
388408
if (options.enableMetricViewMetadata !== undefined) {

lib/telemetry/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export interface DriverConfiguration {
210210
/** Process name */
211211
processName: string;
212212

213-
/** Authentication type (access-token, databricks-oauth, custom) */
213+
/** Authentication type (pat, external-browser, oauth-m2m, custom) */
214214
authType: string;
215215

216216
// Feature flags

0 commit comments

Comments
 (0)