@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,176 @@
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.CircuitBreakerRegistry = exports.CircuitBreaker = exports.CircuitBreakerOpenError = exports.CIRCUIT_BREAKER_OPEN_CODE = exports.DEFAULT_CIRCUIT_BREAKER_CONFIG = exports.CircuitBreakerState = void 0;
19
+ const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
20
+ var CircuitBreakerState;
21
+ (function (CircuitBreakerState) {
22
+ CircuitBreakerState["CLOSED"] = "CLOSED";
23
+ CircuitBreakerState["OPEN"] = "OPEN";
24
+ CircuitBreakerState["HALF_OPEN"] = "HALF_OPEN";
25
+ })(CircuitBreakerState = exports.CircuitBreakerState || (exports.CircuitBreakerState = {}));
26
+ exports.DEFAULT_CIRCUIT_BREAKER_CONFIG = Object.freeze({
27
+ failureThreshold: 5,
28
+ timeout: 60000,
29
+ successThreshold: 2,
30
+ });
31
+ exports.CIRCUIT_BREAKER_OPEN_CODE = 'CIRCUIT_BREAKER_OPEN';
32
+ /**
33
+ * Thrown when execute() is called while the breaker is OPEN or a HALF_OPEN
34
+ * probe is already in flight. Callers identify the condition via
35
+ * `instanceof CircuitBreakerOpenError` or `err.code === CIRCUIT_BREAKER_OPEN_CODE`
36
+ * rather than string-matching the message.
37
+ */
38
+ class CircuitBreakerOpenError extends Error {
39
+ constructor(message = 'Circuit breaker OPEN') {
40
+ super(message);
41
+ this.code = exports.CIRCUIT_BREAKER_OPEN_CODE;
42
+ this.name = 'CircuitBreakerOpenError';
43
+ }
44
+ }
45
+ exports.CircuitBreakerOpenError = CircuitBreakerOpenError;
46
+ class CircuitBreaker {
47
+ constructor(context, config) {
48
+ this.context = context;
49
+ this.state = CircuitBreakerState.CLOSED;
50
+ this.failureCount = 0;
51
+ this.successCount = 0;
52
+ this.halfOpenInflight = 0;
53
+ this.config = {
54
+ ...exports.DEFAULT_CIRCUIT_BREAKER_CONFIG,
55
+ ...config,
56
+ };
57
+ }
58
+ async execute(operation) {
59
+ const admitted = this.tryAdmit();
60
+ if (!admitted) {
61
+ throw new CircuitBreakerOpenError();
62
+ }
63
+ const { wasHalfOpenProbe } = admitted;
64
+ try {
65
+ const result = await operation();
66
+ this.onSuccess();
67
+ return result;
68
+ }
69
+ catch (error) {
70
+ this.onFailure();
71
+ throw error;
72
+ }
73
+ finally {
74
+ if (wasHalfOpenProbe && this.halfOpenInflight > 0) {
75
+ this.halfOpenInflight -= 1;
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ * Synchronous admission check. Returning `null` means "reject". Returning
81
+ * an object means the caller is admitted; `wasHalfOpenProbe` indicates
82
+ * whether this admission consumed the single HALF_OPEN probe slot so the
83
+ * caller can decrement it in `finally`.
84
+ *
85
+ * Running this as a single synchronous block is what prevents the
86
+ * concurrent-probe race that existed in the previous implementation.
87
+ */
88
+ tryAdmit() {
89
+ const logger = this.context.getLogger();
90
+ if (this.state === CircuitBreakerState.OPEN) {
91
+ if (this.nextAttempt && Date.now() < this.nextAttempt.getTime()) {
92
+ return null;
93
+ }
94
+ this.state = CircuitBreakerState.HALF_OPEN;
95
+ this.successCount = 0;
96
+ this.halfOpenInflight = 0;
97
+ logger.log(IDBSQLLogger_1.LogLevel.debug, 'Circuit breaker transitioned to HALF_OPEN');
98
+ }
99
+ if (this.state === CircuitBreakerState.HALF_OPEN) {
100
+ if (this.halfOpenInflight > 0) {
101
+ return null;
102
+ }
103
+ this.halfOpenInflight += 1;
104
+ return { wasHalfOpenProbe: true };
105
+ }
106
+ return { wasHalfOpenProbe: false };
107
+ }
108
+ getState() {
109
+ return this.state;
110
+ }
111
+ getFailureCount() {
112
+ return this.failureCount;
113
+ }
114
+ getSuccessCount() {
115
+ return this.successCount;
116
+ }
117
+ onSuccess() {
118
+ const logger = this.context.getLogger();
119
+ this.failureCount = 0;
120
+ if (this.state === CircuitBreakerState.HALF_OPEN) {
121
+ this.successCount += 1;
122
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Circuit breaker success in HALF_OPEN (${this.successCount}/${this.config.successThreshold})`);
123
+ if (this.successCount >= this.config.successThreshold) {
124
+ this.state = CircuitBreakerState.CLOSED;
125
+ this.successCount = 0;
126
+ this.nextAttempt = undefined;
127
+ logger.log(IDBSQLLogger_1.LogLevel.debug, 'Circuit breaker transitioned to CLOSED');
128
+ }
129
+ }
130
+ }
131
+ onFailure() {
132
+ const logger = this.context.getLogger();
133
+ this.failureCount += 1;
134
+ this.successCount = 0;
135
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Circuit breaker failure (${this.failureCount}/${this.config.failureThreshold})`);
136
+ if (this.state === CircuitBreakerState.HALF_OPEN || this.failureCount >= this.config.failureThreshold) {
137
+ this.state = CircuitBreakerState.OPEN;
138
+ this.nextAttempt = new Date(Date.now() + this.config.timeout);
139
+ logger.log(IDBSQLLogger_1.LogLevel.warn, `Telemetry circuit breaker OPEN after ${this.failureCount} failures (will retry after ${this.config.timeout}ms)`);
140
+ }
141
+ }
142
+ }
143
+ exports.CircuitBreaker = CircuitBreaker;
144
+ class CircuitBreakerRegistry {
145
+ constructor(context) {
146
+ this.context = context;
147
+ this.breakers = new Map();
148
+ }
149
+ getCircuitBreaker(host, config) {
150
+ let breaker = this.breakers.get(host);
151
+ if (!breaker) {
152
+ breaker = new CircuitBreaker(this.context, config);
153
+ this.breakers.set(host, breaker);
154
+ const logger = this.context.getLogger();
155
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Created circuit breaker for host: ${host}`);
156
+ }
157
+ else if (config) {
158
+ const logger = this.context.getLogger();
159
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Circuit breaker for host ${host} already exists; provided config will be ignored`);
160
+ }
161
+ return breaker;
162
+ }
163
+ getAllBreakers() {
164
+ return new Map(this.breakers);
165
+ }
166
+ removeCircuitBreaker(host) {
167
+ this.breakers.delete(host);
168
+ const logger = this.context.getLogger();
169
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Removed circuit breaker for host: ${host}`);
170
+ }
171
+ clear() {
172
+ this.breakers.clear();
173
+ }
174
+ }
175
+ exports.CircuitBreakerRegistry = CircuitBreakerRegistry;
176
+ //# sourceMappingURL=CircuitBreaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CircuitBreaker.js","sourceRoot":"","sources":["../../lib/telemetry/CircuitBreaker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,4DAAqD;AAErD,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,oCAAa,CAAA;IACb,8CAAuB,CAAA;AACzB,CAAC,EAJW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAI9B;AAQY,QAAA,8BAA8B,GAAmC,MAAM,CAAC,MAAM,CAAC;IAC1F,gBAAgB,EAAE,CAAC;IACnB,OAAO,EAAE,KAAK;IACd,gBAAgB,EAAE,CAAC;CACpB,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;GAKG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAGhD,YAAY,OAAO,GAAG,sBAAsB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAG,iCAAyB,CAAC;QAIxC,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAPD,0DAOC;AAED,MAAa,cAAc;IAazB,YAAoB,OAAuB,EAAE,MAAs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CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACjC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,qCAAqC,IAAI,EAAE,CAAC,CAAC;SACzE;aAAM,IAAI,MAAM,EAAE;YACjB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,4BAA4B,IAAI,kDAAkD,CAAC,CAAC;SAChH;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,oBAAoB,CAAC,IAAY;QAC/B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACxC,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,qCAAqC,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AAlCD,wDAkCC"}
@@ -0,0 +1,76 @@
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 IClientContext from '../contracts/IClientContext';
17
+ import IAuthentication from '../connection/contracts/IAuthentication';
18
+ import HiveDriverError from '../errors/HiveDriverError';
19
+ import { TelemetryMetric } from './types';
20
+ import { CircuitBreakerRegistry } from './CircuitBreaker';
21
+ /**
22
+ * Thrown for non-credential terminal telemetry failures (e.g. refusal to
23
+ * export to an invalid host). Separate from `AuthenticationError` so the
24
+ * classifier can keep the "short-circuit, don't retry, count as breaker
25
+ * failure" contract without muddying the auth taxonomy used by the rest of
26
+ * the driver.
27
+ */
28
+ export declare class TelemetryTerminalError extends HiveDriverError {
29
+ readonly terminal: true;
30
+ }
31
+ /**
32
+ * Exports telemetry metrics to the Databricks telemetry service.
33
+ *
34
+ * CRITICAL: export() never throws — all errors are swallowed and logged at
35
+ * LogLevel.debug (the one exception is a single warn on the first observed
36
+ * auth-missing, re-armed on recovery).
37
+ */
38
+ export default class DatabricksTelemetryExporter {
39
+ private context;
40
+ private host;
41
+ private circuitBreakerRegistry;
42
+ private authProvider?;
43
+ private readonly circuitBreaker;
44
+ private readonly authenticatedUserAgent;
45
+ /** User-Agent used for the unauthenticated endpoint; strips any
46
+ * caller-supplied `userAgentEntry` that could identify the customer. */
47
+ private readonly unauthenticatedUserAgent;
48
+ private authMissingWarned;
49
+ constructor(context: IClientContext, host: string, circuitBreakerRegistry: CircuitBreakerRegistry, authProvider?: IAuthentication | undefined);
50
+ /**
51
+ * Release the per-host circuit breaker. Intended for the owning client's
52
+ * close() path.
53
+ *
54
+ * NOTE: `CircuitBreakerRegistry` currently shares one breaker per host
55
+ * across consumers; calling this while another consumer is active will
56
+ * reset their failure-count memory. The owning-client is expected to be
57
+ * the last consumer on its host; multi-consumer refcounting on the
58
+ * registry will land in the consumer-wiring PR.
59
+ */
60
+ dispose(): void;
61
+ export(metrics: TelemetryMetric[]): Promise<void>;
62
+ /**
63
+ * Retry wrapper shaped after HttpRetryPolicy: retries only on errors
64
+ * classified as retryable by ExceptionClassifier, stops on terminal ones,
65
+ * surfaces the last error to the circuit breaker.
66
+ *
67
+ * `maxRetries` is the number of retries *after* the first attempt (i.e.
68
+ * attempts = maxRetries + 1), matching HttpRetryPolicy's semantics.
69
+ */
70
+ private exportWithRetry;
71
+ private exportInternal;
72
+ private getAuthHeaders;
73
+ private sendRequest;
74
+ private toTelemetryLog;
75
+ private sleep;
76
+ }
@@ -0,0 +1,358 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.TelemetryTerminalError = void 0;
45
+ const uuid_1 = require("uuid");
46
+ const node_fetch_1 = __importStar(require("node-fetch"));
47
+ const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
48
+ const AuthenticationError_1 = __importDefault(require("../errors/AuthenticationError"));
49
+ const HiveDriverError_1 = __importDefault(require("../errors/HiveDriverError"));
50
+ const types_1 = require("./types");
51
+ const CircuitBreaker_1 = require("./CircuitBreaker");
52
+ const ExceptionClassifier_1 = __importDefault(require("./ExceptionClassifier"));
53
+ const telemetryUtils_1 = require("./telemetryUtils");
54
+ const buildUserAgentString_1 = __importDefault(require("../utils/buildUserAgentString"));
55
+ /**
56
+ * Thrown for non-credential terminal telemetry failures (e.g. refusal to
57
+ * export to an invalid host). Separate from `AuthenticationError` so the
58
+ * classifier can keep the "short-circuit, don't retry, count as breaker
59
+ * failure" contract without muddying the auth taxonomy used by the rest of
60
+ * the driver.
61
+ */
62
+ class TelemetryTerminalError extends HiveDriverError_1.default {
63
+ constructor() {
64
+ super(...arguments);
65
+ this.terminal = true;
66
+ }
67
+ }
68
+ exports.TelemetryTerminalError = TelemetryTerminalError;
69
+ /**
70
+ * Exports telemetry metrics to the Databricks telemetry service.
71
+ *
72
+ * CRITICAL: export() never throws — all errors are swallowed and logged at
73
+ * LogLevel.debug (the one exception is a single warn on the first observed
74
+ * auth-missing, re-armed on recovery).
75
+ */
76
+ class DatabricksTelemetryExporter {
77
+ constructor(context, host, circuitBreakerRegistry, authProvider) {
78
+ this.context = context;
79
+ this.host = host;
80
+ this.circuitBreakerRegistry = circuitBreakerRegistry;
81
+ this.authProvider = authProvider;
82
+ this.authMissingWarned = false;
83
+ this.circuitBreaker = circuitBreakerRegistry.getCircuitBreaker(host);
84
+ const config = this.context.getConfig();
85
+ // Telemetry-default-on means anything in `userAgentEntry` ships to the
86
+ // telemetry endpoint on every POST. `buildUserAgentString` redacts
87
+ // Databricks token *prefixes* (dapi, dose, …) but not the broader secret
88
+ // shapes — JWTs, OAuth `client_secret`, JSON-encoded credentials, URL
89
+ // userinfo — that customers occasionally stuff into the user-agent.
90
+ // Run the full SECRET_PATTERNS sweep before the UA is built so the
91
+ // header value never carries an unredacted secret. The user's primary
92
+ // Thrift connection is unaffected.
93
+ const redactedEntry = config.userAgentEntry === undefined ? undefined : (0, telemetryUtils_1.redactSensitive)(config.userAgentEntry, 256);
94
+ this.authenticatedUserAgent = (0, buildUserAgentString_1.default)(redactedEntry);
95
+ this.unauthenticatedUserAgent = (0, buildUserAgentString_1.default)(undefined);
96
+ }
97
+ /**
98
+ * Release the per-host circuit breaker. Intended for the owning client's
99
+ * close() path.
100
+ *
101
+ * NOTE: `CircuitBreakerRegistry` currently shares one breaker per host
102
+ * across consumers; calling this while another consumer is active will
103
+ * reset their failure-count memory. The owning-client is expected to be
104
+ * the last consumer on its host; multi-consumer refcounting on the
105
+ * registry will land in the consumer-wiring PR.
106
+ */
107
+ dispose() {
108
+ this.circuitBreakerRegistry.removeCircuitBreaker(this.host);
109
+ }
110
+ async export(metrics) {
111
+ var _a;
112
+ if (!metrics || metrics.length === 0) {
113
+ return;
114
+ }
115
+ const logger = this.context.getLogger();
116
+ try {
117
+ await this.circuitBreaker.execute(() => this.exportWithRetry(metrics));
118
+ }
119
+ catch (error) {
120
+ if (error instanceof CircuitBreaker_1.CircuitBreakerOpenError) {
121
+ logger.log(IDBSQLLogger_1.LogLevel.debug, 'Circuit breaker OPEN - dropping telemetry');
122
+ }
123
+ else if (error instanceof AuthenticationError_1.default) {
124
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry export auth failure: ${error.message}`);
125
+ }
126
+ else if (error instanceof TelemetryTerminalError) {
127
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry export refused: ${error.message}`);
128
+ }
129
+ else {
130
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry export error: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
131
+ }
132
+ }
133
+ }
134
+ /**
135
+ * Retry wrapper shaped after HttpRetryPolicy: retries only on errors
136
+ * classified as retryable by ExceptionClassifier, stops on terminal ones,
137
+ * surfaces the last error to the circuit breaker.
138
+ *
139
+ * `maxRetries` is the number of retries *after* the first attempt (i.e.
140
+ * attempts = maxRetries + 1), matching HttpRetryPolicy's semantics.
141
+ */
142
+ async exportWithRetry(metrics) {
143
+ var _a, _b, _c, _d, _e, _f;
144
+ const config = this.context.getConfig();
145
+ const logger = this.context.getLogger();
146
+ const rawMaxRetries = (_a = config.telemetryMaxRetries) !== null && _a !== void 0 ? _a : types_1.DEFAULT_TELEMETRY_CONFIG.maxRetries;
147
+ const maxRetries = Number.isFinite(rawMaxRetries) && rawMaxRetries >= 0 ? rawMaxRetries : types_1.DEFAULT_TELEMETRY_CONFIG.maxRetries;
148
+ const baseMs = (_b = config.telemetryBackoffBaseMs) !== null && _b !== void 0 ? _b : types_1.DEFAULT_TELEMETRY_CONFIG.backoffBaseMs;
149
+ const maxMs = (_c = config.telemetryBackoffMaxMs) !== null && _c !== void 0 ? _c : types_1.DEFAULT_TELEMETRY_CONFIG.backoffMaxMs;
150
+ const jitterMs = (_d = config.telemetryBackoffJitterMs) !== null && _d !== void 0 ? _d : types_1.DEFAULT_TELEMETRY_CONFIG.backoffJitterMs;
151
+ const totalAttempts = maxRetries + 1;
152
+ let lastError = null;
153
+ /* eslint-disable no-await-in-loop */
154
+ for (let attempt = 0; attempt < totalAttempts; attempt += 1) {
155
+ try {
156
+ await this.exportInternal(metrics);
157
+ return;
158
+ }
159
+ catch (error) {
160
+ lastError = error;
161
+ if (error instanceof AuthenticationError_1.default ||
162
+ error instanceof TelemetryTerminalError ||
163
+ ExceptionClassifier_1.default.isTerminal(error)) {
164
+ throw error;
165
+ }
166
+ if (!ExceptionClassifier_1.default.isRetryable(error)) {
167
+ throw error;
168
+ }
169
+ if (attempt >= totalAttempts - 1) {
170
+ throw error;
171
+ }
172
+ const base = Math.min(baseMs * 2 ** attempt, maxMs);
173
+ const jitter = Math.random() * jitterMs;
174
+ const delay = Math.min(base + jitter, maxMs);
175
+ // Include the failing error so ops can see what's being retried,
176
+ // not just the cadence.
177
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Retrying telemetry export (attempt ${attempt + 1}/${totalAttempts}) after ${Math.round(delay)}ms: ${(_e = error === null || error === void 0 ? void 0 : error.statusCode) !== null && _e !== void 0 ? _e : ''} ${(0, telemetryUtils_1.redactSensitive)((_f = error === null || error === void 0 ? void 0 : error.message) !== null && _f !== void 0 ? _f : '')}`);
178
+ await this.sleep(delay);
179
+ }
180
+ }
181
+ /* eslint-enable no-await-in-loop */
182
+ if (lastError) {
183
+ throw lastError;
184
+ }
185
+ }
186
+ async exportInternal(metrics) {
187
+ var _a, _b;
188
+ const config = this.context.getConfig();
189
+ const logger = this.context.getLogger();
190
+ const authenticatedExport = (_a = config.telemetryAuthenticatedExport) !== null && _a !== void 0 ? _a : types_1.DEFAULT_TELEMETRY_CONFIG.authenticatedExport;
191
+ const endpoint = (0, telemetryUtils_1.buildTelemetryUrl)(this.host, authenticatedExport ? '/telemetry-ext' : '/telemetry-unauth');
192
+ if (!endpoint) {
193
+ // Malformed / deny-listed host — drop the batch rather than letting
194
+ // it target an attacker-controlled destination.
195
+ throw new TelemetryTerminalError('Refusing telemetry export: host failed validation');
196
+ }
197
+ const userAgent = authenticatedExport ? this.authenticatedUserAgent : this.unauthenticatedUserAgent;
198
+ let headers = {
199
+ 'Content-Type': 'application/json',
200
+ 'User-Agent': userAgent,
201
+ ...((_b = config.customHeaders) !== null && _b !== void 0 ? _b : {}),
202
+ };
203
+ if (authenticatedExport) {
204
+ headers = { ...headers, ...(await this.getAuthHeaders()) };
205
+ if (!(0, telemetryUtils_1.hasAuthorization)(headers)) {
206
+ if (!this.authMissingWarned) {
207
+ this.authMissingWarned = true;
208
+ logger.log(IDBSQLLogger_1.LogLevel.warn, 'Telemetry: Authorization header missing — metrics will be dropped');
209
+ }
210
+ throw new AuthenticationError_1.default('Telemetry export: missing Authorization header');
211
+ }
212
+ }
213
+ const protoLogs = metrics.map((m) => this.toTelemetryLog(m, authenticatedExport, userAgent));
214
+ const body = JSON.stringify({
215
+ uploadTime: Date.now(),
216
+ items: [],
217
+ protoLogs: protoLogs.map((log) => JSON.stringify(log)),
218
+ });
219
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Exporting ${metrics.length} telemetry metrics to ${authenticatedExport ? 'authenticated' : 'unauthenticated'} endpoint`);
220
+ const response = await this.sendRequest(endpoint, {
221
+ method: 'POST',
222
+ headers,
223
+ body,
224
+ timeout: 10000,
225
+ });
226
+ if (!response.ok) {
227
+ await response.text().catch(() => { });
228
+ const error = new Error(`Telemetry export failed: ${response.status} ${response.statusText}`);
229
+ error.statusCode = response.status;
230
+ throw error;
231
+ }
232
+ await response.text().catch(() => { });
233
+ // Successful round-trip re-arms the "auth missing" warn so operators see
234
+ // a fresh signal the next time auth breaks.
235
+ this.authMissingWarned = false;
236
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Successfully exported ${metrics.length} telemetry metrics`);
237
+ }
238
+ async getAuthHeaders() {
239
+ var _a, _b, _c, _d;
240
+ // Prefer the explicitly-injected auth provider; fall back to the context
241
+ // (used when a shared TelemetryClient resolves auth through its FIFO of
242
+ // registered DBSQLClients).
243
+ const authProvider = (_a = this.authProvider) !== null && _a !== void 0 ? _a : (_c = (_b = this.context).getAuthProvider) === null || _c === void 0 ? void 0 : _c.call(_b);
244
+ if (!authProvider) {
245
+ return {};
246
+ }
247
+ const logger = this.context.getLogger();
248
+ try {
249
+ return (0, telemetryUtils_1.normalizeHeaders)(await authProvider.authenticate());
250
+ }
251
+ catch (error) {
252
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry: auth provider threw: ${(_d = error === null || error === void 0 ? void 0 : error.message) !== null && _d !== void 0 ? _d : error}`);
253
+ return {};
254
+ }
255
+ }
256
+ async sendRequest(url, init) {
257
+ const connectionProvider = await this.context.getConnectionProvider();
258
+ const agent = await connectionProvider.getAgent();
259
+ // Do NOT route through `connectionProvider.getRetryPolicy()` here. That
260
+ // policy is bounded by the customer's `retriesTimeout` (15 min default)
261
+ // and `retryMaxAttempts` (5), so each call to `sendRequest` could spend
262
+ // up to ~15 min retrying on its own. Stacked under the exporter's outer
263
+ // `exportWithRetry` loop (`telemetryMaxRetries` default 3) the worst-case
264
+ // wall-clock per batch reaches ~45 min — during which `flushInFlight`
265
+ // blocks subsequent flushes and `addPendingMetric` silently drops past
266
+ // the buffer cap.
267
+ //
268
+ // Telemetry must be a polite background citizen: the outer loop is the
269
+ // single source of retry, and a single attempt here is the right shape.
270
+ // Connection-level errors that the customer retry policy would have
271
+ // bridged (transient socket errors, 5xx) are still classified by
272
+ // `ExceptionClassifier` and retried by `exportWithRetry` instead.
273
+ const requestConfig = { agent, ...init };
274
+ const request = new node_fetch_1.Request(url, requestConfig);
275
+ return (0, node_fetch_1.default)(request);
276
+ }
277
+ toTelemetryLog(metric, authenticatedExport, userAgent) {
278
+ var _a, _b, _c;
279
+ // Unauthenticated export must not ship correlation IDs, fingerprint
280
+ // data, or raw error detail — an on-path observer could otherwise link
281
+ // sessions → workspaces → user activity without any auth.
282
+ const includeCorrelation = authenticatedExport;
283
+ const log = {
284
+ workspace_id: includeCorrelation ? metric.workspaceId : undefined,
285
+ frontend_log_event_id: (0, uuid_1.v4)(),
286
+ context: {
287
+ client_context: {
288
+ timestamp_millis: metric.timestamp,
289
+ user_agent: userAgent,
290
+ },
291
+ },
292
+ entry: {
293
+ sql_driver_log: {
294
+ session_id: includeCorrelation ? metric.sessionId : undefined,
295
+ sql_statement_id: includeCorrelation ? metric.statementId : undefined,
296
+ },
297
+ },
298
+ };
299
+ if (metric.metricType === 'connection') {
300
+ if (metric.latencyMs !== undefined) {
301
+ log.entry.sql_driver_log.operation_latency_ms = metric.latencyMs;
302
+ }
303
+ if (metric.driverConfig && includeCorrelation) {
304
+ // system_configuration is a high-entropy client fingerprint (OS, arch,
305
+ // locale, process, runtime). Only ship on the authenticated path.
306
+ log.entry.sql_driver_log.system_configuration = {
307
+ driver_version: metric.driverConfig.driverVersion,
308
+ driver_name: metric.driverConfig.driverName,
309
+ runtime_name: 'Node.js',
310
+ runtime_version: metric.driverConfig.nodeVersion,
311
+ runtime_vendor: metric.driverConfig.runtimeVendor,
312
+ os_name: metric.driverConfig.platform,
313
+ os_version: metric.driverConfig.osVersion,
314
+ os_arch: metric.driverConfig.osArch,
315
+ locale_name: metric.driverConfig.localeName,
316
+ char_set_encoding: metric.driverConfig.charSetEncoding,
317
+ process_name: (0, telemetryUtils_1.sanitizeProcessName)(metric.driverConfig.processName) || undefined,
318
+ };
319
+ }
320
+ }
321
+ else if (metric.metricType === 'statement') {
322
+ log.entry.sql_driver_log.operation_latency_ms = metric.latencyMs;
323
+ if (metric.resultFormat || metric.chunkCount) {
324
+ log.entry.sql_driver_log.sql_operation = {
325
+ execution_result: metric.resultFormat,
326
+ };
327
+ if (((_a = metric.chunkCount) !== null && _a !== void 0 ? _a : 0) > 0) {
328
+ log.entry.sql_driver_log.sql_operation.chunk_details = {
329
+ total_chunks_present: metric.chunkCount,
330
+ total_chunks_iterated: metric.chunkCount,
331
+ initial_chunk_latency_millis: metric.chunkInitialLatencyMs,
332
+ slowest_chunk_latency_millis: metric.chunkSlowestLatencyMs,
333
+ sum_chunks_download_time_millis: metric.chunkSumLatencyMs,
334
+ };
335
+ }
336
+ }
337
+ }
338
+ else if (metric.metricType === 'error') {
339
+ const stackOrMessage = (_c = (_b = metric.errorStack) !== null && _b !== void 0 ? _b : metric.errorMessage) !== null && _c !== void 0 ? _c : '';
340
+ // Primary redaction site is TelemetryEventEmitter.emitError — this
341
+ // second pass is defence-in-depth in case a metric reached the
342
+ // exporter via a path that bypassed the emitter (programmatic injection
343
+ // in tests, future call sites). On the unauth path we ship nothing.
344
+ log.entry.sql_driver_log.error_info = {
345
+ error_name: metric.errorName || 'UnknownError',
346
+ stack_trace: includeCorrelation ? (0, telemetryUtils_1.redactSensitive)(stackOrMessage) : '',
347
+ };
348
+ }
349
+ return log;
350
+ }
351
+ sleep(ms) {
352
+ return new Promise((resolve) => {
353
+ setTimeout(resolve, ms);
354
+ });
355
+ }
356
+ }
357
+ exports.default = DatabricksTelemetryExporter;
358
+ //# sourceMappingURL=DatabricksTelemetryExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabricksTelemetryExporter.js","sourceRoot":"","sources":["../../lib/telemetry/DatabricksTelemetryExporter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+BAAoC;AACpC,yDAAmE;AAEnE,4DAAqD;AAErD,wFAAgE;AAChE,gFAAwD;AACxD,mCAAoE;AACpE,qDAAmG;AACnG,gFAAwD;AACxD,qDAM0B;AAC1B,yFAAiE;AAgDjE;;;;;;GAMG;AACH,MAAa,sBAAuB,SAAQ,yBAAe;IAA3D;;QACW,aAAQ,GAAG,IAAa,CAAC;IACpC,CAAC;CAAA;AAFD,wDAEC;AAED;;;;;;GAMG;AACH,MAAqB,2BAA2B;IAW9C,YACU,OAAuB,EACvB,IAAY,EACZ,sBAA8C,EAC9C,YAA8B;QAH9B,YAAO,GAAP,OAAO,CAAgB;QACvB,SAAI,GAAJ,IAAI,CAAQ;QACZ,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,iBAAY,GAAZ,YAAY,CAAkB;QANhC,sBAAiB,GAAG,KAAK,CAAC;QAQhC,IAAI,CAAC,cAAc,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACrE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACxC,uEAAuE;QACvE,mEAAmE;QACnE,yEAAyE;QACzE,sEAAsE;QACtE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IAAA,gCAAe,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE;aACvE,CAAC;SACH;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtUD,8CAsUC"}
@@ -80,6 +80,18 @@ class ExceptionClassifier {
80
80
  if (error.name === 'TimeoutError' || error.message.includes('timeout')) {
81
81
  return true;
82
82
  }
83
+ // Transient network errors. Notably does NOT include `ENOTFOUND`:
84
+ // DNS "not found" usually indicates a misconfigured host, not a transient
85
+ // fault. Retrying pushes load at the resolver without any expectation of
86
+ // success; circuit-breaker failure accounting is the better response.
87
+ const errorCode = error.code;
88
+ if (errorCode === 'ECONNREFUSED' ||
89
+ errorCode === 'ECONNRESET' ||
90
+ errorCode === 'EHOSTUNREACH' ||
91
+ errorCode === 'ETIMEDOUT' ||
92
+ errorCode === 'EAI_AGAIN') {
93
+ return true;
94
+ }
83
95
  // Check for HTTP status codes in error properties
84
96
  // Supporting both 'statusCode' and 'status' property names for flexibility
85
97
  const statusCode = (_a = error.statusCode) !== null && _a !== void 0 ? _a : error.status;