@databricks/sql 1.13.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +12 -0
  2. package/dist/DBSQLClient.d.ts +107 -0
  3. package/dist/DBSQLClient.js +470 -0
  4. package/dist/DBSQLClient.js.map +1 -1
  5. package/dist/DBSQLOperation.d.ts +32 -1
  6. package/dist/DBSQLOperation.js +138 -29
  7. package/dist/DBSQLOperation.js.map +1 -1
  8. package/dist/DBSQLSession.d.ts +1 -0
  9. package/dist/DBSQLSession.js +43 -12
  10. package/dist/DBSQLSession.js.map +1 -1
  11. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +10 -6
  12. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
  13. package/dist/contracts/IClientContext.d.ts +36 -0
  14. package/dist/contracts/IDBSQLClient.d.ts +90 -0
  15. package/dist/contracts/IDBSQLSession.d.ts +6 -0
  16. package/dist/index.d.ts +4 -0
  17. package/dist/index.js +12 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/result/CloudFetchResultHandler.d.ts +8 -1
  20. package/dist/result/CloudFetchResultHandler.js +28 -2
  21. package/dist/result/CloudFetchResultHandler.js.map +1 -1
  22. package/dist/result/RowSetProvider.d.ts +8 -1
  23. package/dist/result/RowSetProvider.js +110 -1
  24. package/dist/result/RowSetProvider.js.map +1 -1
  25. package/dist/telemetry/CircuitBreaker.d.ts +73 -0
  26. package/dist/telemetry/CircuitBreaker.js +176 -0
  27. package/dist/telemetry/CircuitBreaker.js.map +1 -0
  28. package/dist/telemetry/DatabricksTelemetryExporter.d.ts +76 -0
  29. package/dist/telemetry/DatabricksTelemetryExporter.js +358 -0
  30. package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -0
  31. package/dist/telemetry/ExceptionClassifier.js +12 -0
  32. package/dist/telemetry/ExceptionClassifier.js.map +1 -1
  33. package/dist/telemetry/FeatureFlagCache.d.ts +61 -0
  34. package/dist/telemetry/FeatureFlagCache.js +214 -0
  35. package/dist/telemetry/FeatureFlagCache.js.map +1 -0
  36. package/dist/telemetry/MetricsAggregator.d.ts +110 -0
  37. package/dist/telemetry/MetricsAggregator.js +610 -0
  38. package/dist/telemetry/MetricsAggregator.js.map +1 -0
  39. package/dist/telemetry/TelemetryClient.d.ts +121 -0
  40. package/dist/telemetry/TelemetryClient.js +296 -0
  41. package/dist/telemetry/TelemetryClient.js.map +1 -0
  42. package/dist/telemetry/TelemetryClientProvider.d.ts +62 -0
  43. package/dist/telemetry/TelemetryClientProvider.js +154 -0
  44. package/dist/telemetry/TelemetryClientProvider.js.map +1 -0
  45. package/dist/telemetry/TelemetryEventEmitter.d.ts +119 -0
  46. package/dist/telemetry/TelemetryEventEmitter.js +151 -0
  47. package/dist/telemetry/TelemetryEventEmitter.js.map +1 -0
  48. package/dist/telemetry/telemetryTypeMappers.d.ts +25 -0
  49. package/dist/telemetry/telemetryTypeMappers.js +72 -0
  50. package/dist/telemetry/telemetryTypeMappers.js.map +1 -0
  51. package/dist/telemetry/telemetryUtils.d.ts +70 -0
  52. package/dist/telemetry/telemetryUtils.js +273 -0
  53. package/dist/telemetry/telemetryUtils.js.map +1 -0
  54. package/dist/telemetry/types.d.ts +70 -5
  55. package/dist/telemetry/types.js +19 -6
  56. package/dist/telemetry/types.js.map +1 -1
  57. package/dist/utils/agentDetector.d.ts +20 -0
  58. package/dist/utils/agentDetector.js +39 -0
  59. package/dist/utils/agentDetector.js.map +1 -0
  60. package/dist/utils/buildUserAgentString.js +7 -1
  61. package/dist/utils/buildUserAgentString.js.map +1 -1
  62. package/dist/utils/index.d.ts +2 -1
  63. package/dist/utils/index.js +3 -1
  64. package/dist/utils/index.js.map +1 -1
  65. package/dist/utils/queryTags.d.ts +12 -0
  66. package/dist/utils/queryTags.js +35 -0
  67. package/dist/utils/queryTags.js.map +1 -0
  68. package/dist/version.d.ts +1 -1
  69. package/dist/version.js +1 -1
  70. package/package.json +2 -2
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright (c) 2025 Databricks Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /// <reference types="node" />
17
+ import { EventEmitter } from 'events';
18
+ import IClientContext from '../contracts/IClientContext';
19
+ import { TelemetryEvent, TelemetryEventType, DriverConfiguration } from './types';
20
+ /**
21
+ * Typed map of event-type → listener payload shape. Keeps `on`/`off` calls
22
+ * structurally typed: `emitter.on(TelemetryEventType.ERROR, (e) => …)` infers
23
+ * `e: TelemetryEvent` instead of `any`. Avoids the EventEmitter-default
24
+ * `(...args: any[]) => void` trap where a typo in the event name silently
25
+ * registers a listener that never fires.
26
+ */
27
+ export interface TelemetryEventMap {
28
+ [TelemetryEventType.CONNECTION_OPEN]: (event: TelemetryEvent) => void;
29
+ [TelemetryEventType.CONNECTION_CLOSE]: (event: TelemetryEvent) => void;
30
+ [TelemetryEventType.STATEMENT_START]: (event: TelemetryEvent) => void;
31
+ [TelemetryEventType.STATEMENT_COMPLETE]: (event: TelemetryEvent) => void;
32
+ [TelemetryEventType.CLOUDFETCH_CHUNK]: (event: TelemetryEvent) => void;
33
+ [TelemetryEventType.ERROR]: (event: TelemetryEvent) => void;
34
+ }
35
+ /**
36
+ * EventEmitter for driver telemetry.
37
+ * Emits events at key driver operations.
38
+ *
39
+ * CRITICAL REQUIREMENT: ALL exceptions must be caught and logged at LogLevel.debug ONLY
40
+ * (never warn/error) to avoid customer anxiety. NO console logging allowed - only IDBSQLLogger.
41
+ *
42
+ * All emit methods funnel through `emitWrapped`, which holds the
43
+ * try/catch/debug-log scaffold. The per-method bodies do nothing but build
44
+ * the event shape — adding a new event type is a one-method change.
45
+ */
46
+ export default class TelemetryEventEmitter extends EventEmitter {
47
+ private context;
48
+ private enabled;
49
+ constructor(context: IClientContext);
50
+ on<K extends keyof TelemetryEventMap>(eventName: K, listener: TelemetryEventMap[K]): this;
51
+ off<K extends keyof TelemetryEventMap>(eventName: K, listener: TelemetryEventMap[K]): this;
52
+ once<K extends keyof TelemetryEventMap>(eventName: K, listener: TelemetryEventMap[K]): this;
53
+ /**
54
+ * Build-and-emit helper. The per-event `build` callback constructs the
55
+ * payload; everything else (enabled check, try/catch, swallow-and-log)
56
+ * lives here so the wrapping cannot drift between event types.
57
+ */
58
+ private emitWrapped;
59
+ emitConnectionOpen(data: {
60
+ sessionId: string;
61
+ workspaceId?: string;
62
+ /**
63
+ * The full driver-configuration block (~1KB). Static for the process —
64
+ * emit sites SHOULD pass it once per client and pass `undefined` on
65
+ * subsequent CONNECTION_OPEN events (one client may open many sessions).
66
+ * The aggregator and exporter both treat `undefined` as "no change since
67
+ * the last metric on the same session lineage".
68
+ */
69
+ driverConfig?: DriverConfiguration;
70
+ latencyMs: number;
71
+ }): void;
72
+ emitConnectionClose(data: {
73
+ sessionId: string;
74
+ latencyMs: number;
75
+ }): void;
76
+ emitStatementStart(data: {
77
+ statementId: string;
78
+ sessionId?: string;
79
+ operationType?: string;
80
+ }): void;
81
+ emitStatementComplete(data: {
82
+ statementId: string;
83
+ sessionId?: string;
84
+ latencyMs?: number;
85
+ resultFormat?: string;
86
+ chunkCount?: number;
87
+ bytesDownloaded?: number;
88
+ pollCount?: number;
89
+ }): void;
90
+ emitCloudFetchChunk(data: {
91
+ statementId: string;
92
+ chunkIndex: number;
93
+ latencyMs?: number;
94
+ bytes: number;
95
+ compressed?: boolean;
96
+ }): void;
97
+ /**
98
+ * Emit an error event.
99
+ *
100
+ * Redaction happens HERE — not at the exporter — so any in-process listener
101
+ * (this class extends `EventEmitter` and `getTelemetryEmitter()` is reachable
102
+ * from any consumer of `@databricks/sql`) sees the same redacted strings
103
+ * the export pipeline does. `redactSensitive` strips Bearer/Basic, Databricks
104
+ * token prefixes, JWTs, JSON-encoded secrets, URL userinfo, and common
105
+ * username-bearing filesystem paths, then caps length.
106
+ *
107
+ * `errorMessage` is also redacted, not only `errorStack` — operation error
108
+ * messages can carry query fragments, table names, parameter values that the
109
+ * SECRET_PATTERNS regex must scrub before they're emitted anywhere.
110
+ */
111
+ emitError(data: {
112
+ statementId?: string;
113
+ sessionId?: string;
114
+ errorName: string;
115
+ errorMessage: string;
116
+ errorStack?: string;
117
+ isTerminal: boolean;
118
+ }): void;
119
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Databricks Contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const events_1 = require("events");
19
+ const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
20
+ const types_1 = require("./types");
21
+ const telemetryUtils_1 = require("./telemetryUtils");
22
+ /**
23
+ * EventEmitter for driver telemetry.
24
+ * Emits events at key driver operations.
25
+ *
26
+ * CRITICAL REQUIREMENT: ALL exceptions must be caught and logged at LogLevel.debug ONLY
27
+ * (never warn/error) to avoid customer anxiety. NO console logging allowed - only IDBSQLLogger.
28
+ *
29
+ * All emit methods funnel through `emitWrapped`, which holds the
30
+ * try/catch/debug-log scaffold. The per-method bodies do nothing but build
31
+ * the event shape — adding a new event type is a one-method change.
32
+ */
33
+ class TelemetryEventEmitter extends events_1.EventEmitter {
34
+ constructor(context) {
35
+ var _a;
36
+ super();
37
+ this.context = context;
38
+ // Check if telemetry is enabled from config
39
+ // Default to false for safe rollout
40
+ const config = context.getConfig();
41
+ this.enabled = (_a = config.telemetryEnabled) !== null && _a !== void 0 ? _a : false;
42
+ }
43
+ // Typed event subscription. EventEmitter's native types use `any` payloads;
44
+ // these overrides give consumers a typed `event` parameter without forcing
45
+ // a wholesale rewrite of the EventEmitter contract.
46
+ on(eventName, listener) {
47
+ return super.on(eventName, listener);
48
+ }
49
+ off(eventName, listener) {
50
+ return super.off(eventName, listener);
51
+ }
52
+ once(eventName, listener) {
53
+ return super.once(eventName, listener);
54
+ }
55
+ /**
56
+ * Build-and-emit helper. The per-event `build` callback constructs the
57
+ * payload; everything else (enabled check, try/catch, swallow-and-log)
58
+ * lives here so the wrapping cannot drift between event types.
59
+ */
60
+ emitWrapped(eventType, build) {
61
+ var _a;
62
+ if (!this.enabled)
63
+ return;
64
+ const logger = this.context.getLogger();
65
+ try {
66
+ this.emit(eventType, build());
67
+ }
68
+ catch (error) {
69
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error emitting ${eventType}: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
70
+ }
71
+ }
72
+ emitConnectionOpen(data) {
73
+ this.emitWrapped(types_1.TelemetryEventType.CONNECTION_OPEN, () => ({
74
+ eventType: types_1.TelemetryEventType.CONNECTION_OPEN,
75
+ timestamp: Date.now(),
76
+ sessionId: data.sessionId,
77
+ workspaceId: data.workspaceId,
78
+ driverConfig: data.driverConfig,
79
+ latencyMs: data.latencyMs,
80
+ }));
81
+ }
82
+ emitConnectionClose(data) {
83
+ this.emitWrapped(types_1.TelemetryEventType.CONNECTION_CLOSE, () => ({
84
+ eventType: types_1.TelemetryEventType.CONNECTION_CLOSE,
85
+ timestamp: Date.now(),
86
+ sessionId: data.sessionId,
87
+ latencyMs: data.latencyMs,
88
+ }));
89
+ }
90
+ emitStatementStart(data) {
91
+ this.emitWrapped(types_1.TelemetryEventType.STATEMENT_START, () => ({
92
+ eventType: types_1.TelemetryEventType.STATEMENT_START,
93
+ timestamp: Date.now(),
94
+ statementId: data.statementId,
95
+ sessionId: data.sessionId,
96
+ operationType: data.operationType,
97
+ }));
98
+ }
99
+ emitStatementComplete(data) {
100
+ this.emitWrapped(types_1.TelemetryEventType.STATEMENT_COMPLETE, () => ({
101
+ eventType: types_1.TelemetryEventType.STATEMENT_COMPLETE,
102
+ timestamp: Date.now(),
103
+ statementId: data.statementId,
104
+ sessionId: data.sessionId,
105
+ latencyMs: data.latencyMs,
106
+ resultFormat: data.resultFormat,
107
+ chunkCount: data.chunkCount,
108
+ bytesDownloaded: data.bytesDownloaded,
109
+ pollCount: data.pollCount,
110
+ }));
111
+ }
112
+ emitCloudFetchChunk(data) {
113
+ this.emitWrapped(types_1.TelemetryEventType.CLOUDFETCH_CHUNK, () => ({
114
+ eventType: types_1.TelemetryEventType.CLOUDFETCH_CHUNK,
115
+ timestamp: Date.now(),
116
+ statementId: data.statementId,
117
+ chunkIndex: data.chunkIndex,
118
+ latencyMs: data.latencyMs,
119
+ bytes: data.bytes,
120
+ compressed: data.compressed,
121
+ }));
122
+ }
123
+ /**
124
+ * Emit an error event.
125
+ *
126
+ * Redaction happens HERE — not at the exporter — so any in-process listener
127
+ * (this class extends `EventEmitter` and `getTelemetryEmitter()` is reachable
128
+ * from any consumer of `@databricks/sql`) sees the same redacted strings
129
+ * the export pipeline does. `redactSensitive` strips Bearer/Basic, Databricks
130
+ * token prefixes, JWTs, JSON-encoded secrets, URL userinfo, and common
131
+ * username-bearing filesystem paths, then caps length.
132
+ *
133
+ * `errorMessage` is also redacted, not only `errorStack` — operation error
134
+ * messages can carry query fragments, table names, parameter values that the
135
+ * SECRET_PATTERNS regex must scrub before they're emitted anywhere.
136
+ */
137
+ emitError(data) {
138
+ this.emitWrapped(types_1.TelemetryEventType.ERROR, () => ({
139
+ eventType: types_1.TelemetryEventType.ERROR,
140
+ timestamp: Date.now(),
141
+ statementId: data.statementId,
142
+ sessionId: data.sessionId,
143
+ errorName: data.errorName,
144
+ errorMessage: (0, telemetryUtils_1.redactSensitive)(data.errorMessage),
145
+ errorStack: data.errorStack === undefined ? undefined : (0, telemetryUtils_1.redactSensitive)(data.errorStack),
146
+ isTerminal: data.isTerminal,
147
+ }));
148
+ }
149
+ }
150
+ exports.default = TelemetryEventEmitter;
151
+ //# sourceMappingURL=TelemetryEventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TelemetryEventEmitter.js","sourceRoot":"","sources":["../../lib/telemetry/TelemetryEventEmitter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,mCAAsC;AAEtC,4DAAqD;AACrD,mCAAkF;AAClF,qDAAmD;AAkBnD;;;;;;;;;;GAUG;AACH,MAAqB,qBAAsB,SAAQ,qBAAY;IAG7D,YAAoB,OAAuB;;QACzC,KAAK,EAAE,CAAC;QADU,YAAO,GAAP,OAAO,CAAgB;QAEzC,4CAA4C;QAC5C,oCAAoC;QACpC,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,gBAAgB,mCAAI,KAAK,CAAC;IAClD,CAAC;IAED,4EAA4E;IAC5E,2EAA2E;IAC3E,oDAAoD;IACpD,EAAE,CAAoC,SAAY,EAAE,QAA8B;QAChF,OAAO,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,QAAwC,CAAC,CAAC;IACvE,CAAC;IAED,GAAG,CAAoC,SAAY,EAAE,QAA8B;QACjF,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,QAAwC,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,CAAoC,SAAY,EAAE,QAA8B;QAClF,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,QAAwC,CAAC,CAAC;IACzE,CAAC;IAED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G,EAAE,CAAC,CAAC;YAChD,SAAS,EAAE,0BAAkB,CAAC,KAAK;YACnC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,IAAA,gCAAe,EAAC,IAAI,CAAC,YAAY,CAAC;YAChD,UAAU,EAAE,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,gCAAe,EAAC,IAAI,CAAC,UAAU,CAAC;YACxF,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AA5JD,wCA4JC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) 2025 Databricks Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { TOperationType, TSparkRowSetType } from '../../thrift/TCLIService_types';
17
+ /**
18
+ * Map Thrift TOperationType to telemetry Operation.Type enum string.
19
+ * Returns 'TYPE_UNSPECIFIED' if operationType is undefined or unknown.
20
+ */
21
+ export declare function mapOperationTypeToTelemetryType(operationType?: TOperationType): string;
22
+ /**
23
+ * Map Thrift TSparkRowSetType to telemetry ExecutionResult.Format enum string.
24
+ */
25
+ export declare function mapResultFormatToTelemetryType(resultFormat?: TSparkRowSetType): string | undefined;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Databricks Contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.mapResultFormatToTelemetryType = exports.mapOperationTypeToTelemetryType = void 0;
19
+ const TCLIService_types_1 = require("../../thrift/TCLIService_types");
20
+ /**
21
+ * Map Thrift TOperationType to telemetry Operation.Type enum string.
22
+ * Returns 'TYPE_UNSPECIFIED' if operationType is undefined or unknown.
23
+ */
24
+ function mapOperationTypeToTelemetryType(operationType) {
25
+ if (operationType === undefined) {
26
+ return 'TYPE_UNSPECIFIED';
27
+ }
28
+ switch (operationType) {
29
+ case TCLIService_types_1.TOperationType.EXECUTE_STATEMENT:
30
+ return 'EXECUTE_STATEMENT';
31
+ case TCLIService_types_1.TOperationType.GET_TYPE_INFO:
32
+ return 'LIST_TYPE_INFO';
33
+ case TCLIService_types_1.TOperationType.GET_CATALOGS:
34
+ return 'LIST_CATALOGS';
35
+ case TCLIService_types_1.TOperationType.GET_SCHEMAS:
36
+ return 'LIST_SCHEMAS';
37
+ case TCLIService_types_1.TOperationType.GET_TABLES:
38
+ return 'LIST_TABLES';
39
+ case TCLIService_types_1.TOperationType.GET_TABLE_TYPES:
40
+ return 'LIST_TABLE_TYPES';
41
+ case TCLIService_types_1.TOperationType.GET_COLUMNS:
42
+ return 'LIST_COLUMNS';
43
+ case TCLIService_types_1.TOperationType.GET_FUNCTIONS:
44
+ return 'LIST_FUNCTIONS';
45
+ case TCLIService_types_1.TOperationType.UNKNOWN:
46
+ default:
47
+ return 'TYPE_UNSPECIFIED';
48
+ }
49
+ }
50
+ exports.mapOperationTypeToTelemetryType = mapOperationTypeToTelemetryType;
51
+ /**
52
+ * Map Thrift TSparkRowSetType to telemetry ExecutionResult.Format enum string.
53
+ */
54
+ function mapResultFormatToTelemetryType(resultFormat) {
55
+ if (resultFormat === undefined) {
56
+ return undefined;
57
+ }
58
+ switch (resultFormat) {
59
+ case TCLIService_types_1.TSparkRowSetType.ARROW_BASED_SET:
60
+ return 'INLINE_ARROW';
61
+ case TCLIService_types_1.TSparkRowSetType.COLUMN_BASED_SET:
62
+ return 'COLUMNAR_INLINE';
63
+ case TCLIService_types_1.TSparkRowSetType.ROW_BASED_SET:
64
+ return 'INLINE_JSON';
65
+ case TCLIService_types_1.TSparkRowSetType.URL_BASED_SET:
66
+ return 'EXTERNAL_LINKS';
67
+ default:
68
+ return 'FORMAT_UNSPECIFIED';
69
+ }
70
+ }
71
+ exports.mapResultFormatToTelemetryType = mapResultFormatToTelemetryType;
72
+ //# sourceMappingURL=telemetryTypeMappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryTypeMappers.js","sourceRoot":"","sources":["../../lib/telemetry/telemetryTypeMappers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,sEAAkF;AAElF;;;GAGG;AACH,SAAgB,+BAA+B,CAAC,aAA8B;IAC5E,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,OAAO,kBAAkB,CAAC;KAC3B;IAED,QAAQ,aAAa,EAAE;QACrB,KAAK,kCAAc,CAAC,iBAAiB;YACnC,OAAO,mBAAmB,CAAC;QAC7B,KAAK,kCAAc,CAAC,aAAa;YAC/B,OAAO,gBAAgB,CAAC;QAC1B,KAAK,kCAAc,CAAC,YAAY;YAC9B,OAAO,eAAe,CAAC;QACzB,KAAK,kCAAc,CAAC,WAAW;YAC7B,OAAO,cAAc,CAAC;QACxB,KAAK,kCAAc,CAAC,UAAU;YAC5B,OAAO,aAAa,CAAC;QACvB,KAAK,kCAAc,CAAC,eAAe;YACjC,OAAO,kBAAkB,CAAC;QAC5B,KAAK,kCAAc,CAAC,WAAW;YAC7B,OAAO,cAAc,CAAC;QACxB,KAAK,kCAAc,CAAC,aAAa;YAC/B,OAAO,gBAAgB,CAAC;QAC1B,KAAK,kCAAc,CAAC,OAAO,CAAC;QAC5B;YACE,OAAO,kBAAkB,CAAC;KAC7B;AACH,CAAC;AA1BD,0EA0BC;AAED;;GAEG;AACH,SAAgB,8BAA8B,CAAC,YAA+B;IAC5E,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IAED,QAAQ,YAAY,EAAE;QACpB,KAAK,oCAAgB,CAAC,eAAe;YACnC,OAAO,cAAc,CAAC;QACxB,KAAK,oCAAgB,CAAC,gBAAgB;YACpC,OAAO,iBAAiB,CAAC;QAC3B,KAAK,oCAAgB,CAAC,aAAa;YACjC,OAAO,aAAa,CAAC;QACvB,KAAK,oCAAgB,CAAC,aAAa;YACjC,OAAO,gBAAgB,CAAC;QAC1B;YACE,OAAO,oBAAoB,CAAC;KAC/B;AACH,CAAC;AAjBD,wEAiBC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) 2025 Databricks Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type IClientContext from '../contracts/IClientContext';
17
+ import type TelemetryEventEmitter from './TelemetryEventEmitter';
18
+ /**
19
+ * Build an HTTPS telemetry URL from a host and a path.
20
+ *
21
+ * Refuses anything beyond a bare `host[:port]` so a compromised or mistyped
22
+ * host cannot redirect the authenticated request to an attacker-controlled
23
+ * endpoint. Defeated historical bypasses include:
24
+ * - protocol-relative prefix: `//attacker.com`
25
+ * - zero-width / ASCII whitespace in the host
26
+ * - userinfo (`user:pass@host`)
27
+ * - path/query/fragment
28
+ * - CRLF (header injection on some fetch backends)
29
+ * - loopback / link-local / RFC1918 / cloud-metadata addresses
30
+ *
31
+ * Returns `null` when the host fails any check; callers drop the batch.
32
+ */
33
+ export declare function buildTelemetryUrl(host: string, path: string): string | null;
34
+ /**
35
+ * Strips common secret shapes from a free-form error string and caps length.
36
+ * Applied before anything is shipped off-box. Redaction happens before
37
+ * truncation so a long stack cannot bury a secret past the cap; truncation
38
+ * then runs a second pass to catch anything that appeared only in the tail.
39
+ */
40
+ export declare function redactSensitive(value: string | undefined, maxLen?: number): string;
41
+ /**
42
+ * Normalises any `HeadersInit` shape (`Headers`, `[string,string][]`, or
43
+ * `Record<string, string>`) into a plain string dictionary. Non-string
44
+ * values are dropped. Shared by the exporter and FeatureFlagCache so there
45
+ * is one source of truth for auth-header handling.
46
+ */
47
+ export declare function normalizeHeaders(raw: unknown): Record<string, string>;
48
+ /**
49
+ * Case-insensitive check for a non-empty `Authorization` header.
50
+ */
51
+ export declare function hasAuthorization(headers: Record<string, string>): boolean;
52
+ /**
53
+ * Returns a safe `process_name` value: the basename of the first whitespace-
54
+ * delimited token, with trailing whitespace trimmed. This defeats both the
55
+ * absolute-path PII leak (`/home/<user>/app.js`) and the argv-leak shape
56
+ * (`node --db-password=X app.js`) that some producers pass in.
57
+ */
58
+ export declare function sanitizeProcessName(name: string | undefined): string;
59
+ /**
60
+ * Run a telemetry emit at a call site, swallowing all exceptions and logging
61
+ * at debug level. Replaces the copy-pasted try/catch + getTelemetryEmitter?.()
62
+ * scaffold at every emit site. Telemetry must never break the driver.
63
+ *
64
+ * The type-only imports keep this helper free of runtime cycles:
65
+ * `IClientContext` imports `TelemetryEventEmitter` only as a type, and this
66
+ * helper does the same, so there's no value-level cycle. A typo like
67
+ * `emitter.emiitConnectionOpen(...)` is now a TS compile error instead of a
68
+ * swallowed runtime exception.
69
+ */
70
+ export declare function safeEmit(context: IClientContext, fn: (emitter: TelemetryEventEmitter) => void): void;