@databricks/sql 1.12.0 → 1.14.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 (95) hide show
  1. package/dist/DBSQLClient.d.ts +13 -0
  2. package/dist/DBSQLClient.js +58 -1
  3. package/dist/DBSQLClient.js.map +1 -1
  4. package/dist/DBSQLOperation.d.ts +1 -0
  5. package/dist/DBSQLOperation.js +23 -2
  6. package/dist/DBSQLOperation.js.map +1 -1
  7. package/dist/DBSQLSession.js +5 -1
  8. package/dist/DBSQLSession.js.map +1 -1
  9. package/dist/connection/auth/tokenProvider/CachedTokenProvider.d.ts +37 -0
  10. package/dist/connection/auth/tokenProvider/CachedTokenProvider.js +79 -0
  11. package/dist/connection/auth/tokenProvider/CachedTokenProvider.js.map +1 -0
  12. package/dist/connection/auth/tokenProvider/ExternalTokenProvider.d.ts +28 -0
  13. package/dist/connection/auth/tokenProvider/ExternalTokenProvider.js +37 -0
  14. package/dist/connection/auth/tokenProvider/ExternalTokenProvider.js.map +1 -0
  15. package/dist/connection/auth/tokenProvider/FederationProvider.d.ts +57 -0
  16. package/dist/connection/auth/tokenProvider/FederationProvider.js +218 -0
  17. package/dist/connection/auth/tokenProvider/FederationProvider.js.map +1 -0
  18. package/dist/connection/auth/tokenProvider/ITokenProvider.d.ts +17 -0
  19. package/dist/connection/auth/tokenProvider/ITokenProvider.js +3 -0
  20. package/dist/connection/auth/tokenProvider/ITokenProvider.js.map +1 -0
  21. package/dist/connection/auth/tokenProvider/StaticTokenProvider.d.ts +24 -0
  22. package/dist/connection/auth/tokenProvider/StaticTokenProvider.js +43 -0
  23. package/dist/connection/auth/tokenProvider/StaticTokenProvider.js.map +1 -0
  24. package/dist/connection/auth/tokenProvider/Token.d.ts +75 -0
  25. package/dist/connection/auth/tokenProvider/Token.js +120 -0
  26. package/dist/connection/auth/tokenProvider/Token.js.map +1 -0
  27. package/dist/connection/auth/tokenProvider/TokenProviderAuthenticator.d.ts +21 -0
  28. package/dist/connection/auth/tokenProvider/TokenProviderAuthenticator.js +38 -0
  29. package/dist/connection/auth/tokenProvider/TokenProviderAuthenticator.js.map +1 -0
  30. package/dist/connection/auth/tokenProvider/index.d.ts +8 -0
  31. package/dist/connection/auth/tokenProvider/index.js +23 -0
  32. package/dist/connection/auth/tokenProvider/index.js.map +1 -0
  33. package/dist/connection/auth/tokenProvider/utils.d.ts +24 -0
  34. package/dist/connection/auth/tokenProvider/utils.js +83 -0
  35. package/dist/connection/auth/tokenProvider/utils.js.map +1 -0
  36. package/dist/contracts/IClientContext.d.ts +15 -0
  37. package/dist/contracts/IDBSQLClient.d.ts +24 -0
  38. package/dist/contracts/IDBSQLSession.d.ts +6 -0
  39. package/dist/index.d.ts +9 -0
  40. package/dist/index.js +15 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/result/ArrowResultHandler.js +2 -2
  43. package/dist/result/ArrowResultHandler.js.map +1 -1
  44. package/dist/result/CloudFetchResultHandler.js +2 -2
  45. package/dist/result/CloudFetchResultHandler.js.map +1 -1
  46. package/dist/telemetry/CircuitBreaker.d.ts +73 -0
  47. package/dist/telemetry/CircuitBreaker.js +176 -0
  48. package/dist/telemetry/CircuitBreaker.js.map +1 -0
  49. package/dist/telemetry/DatabricksTelemetryExporter.d.ts +76 -0
  50. package/dist/telemetry/DatabricksTelemetryExporter.js +324 -0
  51. package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -0
  52. package/dist/telemetry/ExceptionClassifier.d.ts +48 -0
  53. package/dist/telemetry/ExceptionClassifier.js +112 -0
  54. package/dist/telemetry/ExceptionClassifier.js.map +1 -0
  55. package/dist/telemetry/FeatureFlagCache.d.ts +61 -0
  56. package/dist/telemetry/FeatureFlagCache.js +208 -0
  57. package/dist/telemetry/FeatureFlagCache.js.map +1 -0
  58. package/dist/telemetry/MetricsAggregator.d.ts +72 -0
  59. package/dist/telemetry/MetricsAggregator.js +375 -0
  60. package/dist/telemetry/MetricsAggregator.js.map +1 -0
  61. package/dist/telemetry/TelemetryClient.d.ts +41 -0
  62. package/dist/telemetry/TelemetryClient.js +64 -0
  63. package/dist/telemetry/TelemetryClient.js.map +1 -0
  64. package/dist/telemetry/TelemetryClientProvider.d.ts +67 -0
  65. package/dist/telemetry/TelemetryClientProvider.js +148 -0
  66. package/dist/telemetry/TelemetryClientProvider.js.map +1 -0
  67. package/dist/telemetry/TelemetryEventEmitter.d.ts +93 -0
  68. package/dist/telemetry/TelemetryEventEmitter.js +172 -0
  69. package/dist/telemetry/TelemetryEventEmitter.js.map +1 -0
  70. package/dist/telemetry/telemetryUtils.d.ts +56 -0
  71. package/dist/telemetry/telemetryUtils.js +222 -0
  72. package/dist/telemetry/telemetryUtils.js.map +1 -0
  73. package/dist/telemetry/types.d.ts +209 -0
  74. package/dist/telemetry/types.js +52 -0
  75. package/dist/telemetry/types.js.map +1 -0
  76. package/dist/telemetry/urlUtils.d.ts +22 -0
  77. package/dist/telemetry/urlUtils.js +35 -0
  78. package/dist/telemetry/urlUtils.js.map +1 -0
  79. package/dist/utils/agentDetector.d.ts +20 -0
  80. package/dist/utils/agentDetector.js +39 -0
  81. package/dist/utils/agentDetector.js.map +1 -0
  82. package/dist/utils/buildUserAgentString.js +7 -1
  83. package/dist/utils/buildUserAgentString.js.map +1 -1
  84. package/dist/utils/index.d.ts +2 -1
  85. package/dist/utils/index.js +3 -1
  86. package/dist/utils/index.js.map +1 -1
  87. package/dist/utils/lz4.d.ts +2 -2
  88. package/dist/utils/lz4.js +13 -1
  89. package/dist/utils/lz4.js.map +1 -1
  90. package/dist/utils/queryTags.d.ts +12 -0
  91. package/dist/utils/queryTags.js +35 -0
  92. package/dist/utils/queryTags.js.map +1 -0
  93. package/dist/version.d.ts +1 -1
  94. package/dist/version.js +1 -1
  95. package/package.json +1 -1
@@ -0,0 +1,324 @@
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
+ this.authenticatedUserAgent = (0, buildUserAgentString_1.default)(config.userAgentEntry);
86
+ this.unauthenticatedUserAgent = (0, buildUserAgentString_1.default)(undefined);
87
+ }
88
+ /**
89
+ * Release the per-host circuit breaker. Intended for the owning client's
90
+ * close() path.
91
+ *
92
+ * NOTE: `CircuitBreakerRegistry` currently shares one breaker per host
93
+ * across consumers; calling this while another consumer is active will
94
+ * reset their failure-count memory. The owning-client is expected to be
95
+ * the last consumer on its host; multi-consumer refcounting on the
96
+ * registry will land in the consumer-wiring PR.
97
+ */
98
+ dispose() {
99
+ this.circuitBreakerRegistry.removeCircuitBreaker(this.host);
100
+ }
101
+ async export(metrics) {
102
+ var _a;
103
+ if (!metrics || metrics.length === 0) {
104
+ return;
105
+ }
106
+ const logger = this.context.getLogger();
107
+ try {
108
+ await this.circuitBreaker.execute(() => this.exportWithRetry(metrics));
109
+ }
110
+ catch (error) {
111
+ if (error instanceof CircuitBreaker_1.CircuitBreakerOpenError) {
112
+ logger.log(IDBSQLLogger_1.LogLevel.debug, 'Circuit breaker OPEN - dropping telemetry');
113
+ }
114
+ else if (error instanceof AuthenticationError_1.default) {
115
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry export auth failure: ${error.message}`);
116
+ }
117
+ else if (error instanceof TelemetryTerminalError) {
118
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry export refused: ${error.message}`);
119
+ }
120
+ else {
121
+ 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}`);
122
+ }
123
+ }
124
+ }
125
+ /**
126
+ * Retry wrapper shaped after HttpRetryPolicy: retries only on errors
127
+ * classified as retryable by ExceptionClassifier, stops on terminal ones,
128
+ * surfaces the last error to the circuit breaker.
129
+ *
130
+ * `maxRetries` is the number of retries *after* the first attempt (i.e.
131
+ * attempts = maxRetries + 1), matching HttpRetryPolicy's semantics.
132
+ */
133
+ async exportWithRetry(metrics) {
134
+ var _a, _b, _c, _d, _e, _f;
135
+ const config = this.context.getConfig();
136
+ const logger = this.context.getLogger();
137
+ const rawMaxRetries = (_a = config.telemetryMaxRetries) !== null && _a !== void 0 ? _a : types_1.DEFAULT_TELEMETRY_CONFIG.maxRetries;
138
+ const maxRetries = Number.isFinite(rawMaxRetries) && rawMaxRetries >= 0 ? rawMaxRetries : types_1.DEFAULT_TELEMETRY_CONFIG.maxRetries;
139
+ const baseMs = (_b = config.telemetryBackoffBaseMs) !== null && _b !== void 0 ? _b : types_1.DEFAULT_TELEMETRY_CONFIG.backoffBaseMs;
140
+ const maxMs = (_c = config.telemetryBackoffMaxMs) !== null && _c !== void 0 ? _c : types_1.DEFAULT_TELEMETRY_CONFIG.backoffMaxMs;
141
+ const jitterMs = (_d = config.telemetryBackoffJitterMs) !== null && _d !== void 0 ? _d : types_1.DEFAULT_TELEMETRY_CONFIG.backoffJitterMs;
142
+ const totalAttempts = maxRetries + 1;
143
+ let lastError = null;
144
+ /* eslint-disable no-await-in-loop */
145
+ for (let attempt = 0; attempt < totalAttempts; attempt += 1) {
146
+ try {
147
+ await this.exportInternal(metrics);
148
+ return;
149
+ }
150
+ catch (error) {
151
+ lastError = error;
152
+ if (error instanceof AuthenticationError_1.default ||
153
+ error instanceof TelemetryTerminalError ||
154
+ ExceptionClassifier_1.default.isTerminal(error)) {
155
+ throw error;
156
+ }
157
+ if (!ExceptionClassifier_1.default.isRetryable(error)) {
158
+ throw error;
159
+ }
160
+ if (attempt >= totalAttempts - 1) {
161
+ throw error;
162
+ }
163
+ const base = Math.min(baseMs * 2 ** attempt, maxMs);
164
+ const jitter = Math.random() * jitterMs;
165
+ const delay = Math.min(base + jitter, maxMs);
166
+ // Include the failing error so ops can see what's being retried,
167
+ // not just the cadence.
168
+ 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 : '')}`);
169
+ await this.sleep(delay);
170
+ }
171
+ }
172
+ /* eslint-enable no-await-in-loop */
173
+ if (lastError) {
174
+ throw lastError;
175
+ }
176
+ }
177
+ async exportInternal(metrics) {
178
+ var _a;
179
+ const config = this.context.getConfig();
180
+ const logger = this.context.getLogger();
181
+ const authenticatedExport = (_a = config.telemetryAuthenticatedExport) !== null && _a !== void 0 ? _a : types_1.DEFAULT_TELEMETRY_CONFIG.authenticatedExport;
182
+ const endpoint = (0, telemetryUtils_1.buildTelemetryUrl)(this.host, authenticatedExport ? '/telemetry-ext' : '/telemetry-unauth');
183
+ if (!endpoint) {
184
+ // Malformed / deny-listed host — drop the batch rather than letting
185
+ // it target an attacker-controlled destination.
186
+ throw new TelemetryTerminalError('Refusing telemetry export: host failed validation');
187
+ }
188
+ const userAgent = authenticatedExport ? this.authenticatedUserAgent : this.unauthenticatedUserAgent;
189
+ let headers = {
190
+ 'Content-Type': 'application/json',
191
+ 'User-Agent': userAgent,
192
+ };
193
+ if (authenticatedExport) {
194
+ headers = { ...headers, ...(await this.getAuthHeaders()) };
195
+ if (!(0, telemetryUtils_1.hasAuthorization)(headers)) {
196
+ if (!this.authMissingWarned) {
197
+ this.authMissingWarned = true;
198
+ logger.log(IDBSQLLogger_1.LogLevel.warn, 'Telemetry: Authorization header missing — metrics will be dropped');
199
+ }
200
+ throw new AuthenticationError_1.default('Telemetry export: missing Authorization header');
201
+ }
202
+ }
203
+ const protoLogs = metrics.map((m) => this.toTelemetryLog(m, authenticatedExport, userAgent));
204
+ const body = JSON.stringify({
205
+ uploadTime: Date.now(),
206
+ items: [],
207
+ protoLogs: protoLogs.map((log) => JSON.stringify(log)),
208
+ });
209
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Exporting ${metrics.length} telemetry metrics to ${authenticatedExport ? 'authenticated' : 'unauthenticated'} endpoint`);
210
+ const response = await this.sendRequest(endpoint, {
211
+ method: 'POST',
212
+ headers,
213
+ body,
214
+ timeout: 10000,
215
+ });
216
+ if (!response.ok) {
217
+ await response.text().catch(() => { });
218
+ const error = new Error(`Telemetry export failed: ${response.status} ${response.statusText}`);
219
+ error.statusCode = response.status;
220
+ throw error;
221
+ }
222
+ await response.text().catch(() => { });
223
+ // Successful round-trip re-arms the "auth missing" warn so operators see
224
+ // a fresh signal the next time auth breaks.
225
+ this.authMissingWarned = false;
226
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Successfully exported ${metrics.length} telemetry metrics`);
227
+ }
228
+ async getAuthHeaders() {
229
+ var _a;
230
+ if (!this.authProvider) {
231
+ return {};
232
+ }
233
+ const logger = this.context.getLogger();
234
+ try {
235
+ return (0, telemetryUtils_1.normalizeHeaders)(await this.authProvider.authenticate());
236
+ }
237
+ catch (error) {
238
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Telemetry: auth provider threw: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
239
+ return {};
240
+ }
241
+ }
242
+ async sendRequest(url, init) {
243
+ const connectionProvider = await this.context.getConnectionProvider();
244
+ const agent = await connectionProvider.getAgent();
245
+ const retryPolicy = await connectionProvider.getRetryPolicy();
246
+ const requestConfig = { agent, ...init };
247
+ const result = await retryPolicy.invokeWithRetry(() => {
248
+ const request = new node_fetch_1.Request(url, requestConfig);
249
+ return (0, node_fetch_1.default)(request).then((response) => ({ request, response }));
250
+ });
251
+ return result.response;
252
+ }
253
+ toTelemetryLog(metric, authenticatedExport, userAgent) {
254
+ var _a, _b;
255
+ // Unauthenticated export must not ship correlation IDs, fingerprint
256
+ // data, or raw error detail — an on-path observer could otherwise link
257
+ // sessions → workspaces → user activity without any auth.
258
+ const includeCorrelation = authenticatedExport;
259
+ const log = {
260
+ workspace_id: includeCorrelation ? metric.workspaceId : undefined,
261
+ frontend_log_event_id: (0, uuid_1.v4)(),
262
+ context: {
263
+ client_context: {
264
+ timestamp_millis: metric.timestamp,
265
+ user_agent: userAgent,
266
+ },
267
+ },
268
+ entry: {
269
+ sql_driver_log: {
270
+ session_id: includeCorrelation ? metric.sessionId : undefined,
271
+ sql_statement_id: includeCorrelation ? metric.statementId : undefined,
272
+ },
273
+ },
274
+ };
275
+ if (metric.metricType === 'connection' && metric.driverConfig && includeCorrelation) {
276
+ // system_configuration is a high-entropy client fingerprint (OS, arch,
277
+ // locale, process, runtime). Only ship on the authenticated path.
278
+ log.entry.sql_driver_log.system_configuration = {
279
+ driver_version: metric.driverConfig.driverVersion,
280
+ driver_name: metric.driverConfig.driverName,
281
+ runtime_name: 'Node.js',
282
+ runtime_version: metric.driverConfig.nodeVersion,
283
+ runtime_vendor: metric.driverConfig.runtimeVendor,
284
+ os_name: metric.driverConfig.platform,
285
+ os_version: metric.driverConfig.osVersion,
286
+ os_arch: metric.driverConfig.osArch,
287
+ locale_name: metric.driverConfig.localeName,
288
+ char_set_encoding: metric.driverConfig.charSetEncoding,
289
+ process_name: (0, telemetryUtils_1.sanitizeProcessName)(metric.driverConfig.processName) || undefined,
290
+ };
291
+ }
292
+ else if (metric.metricType === 'statement') {
293
+ log.entry.sql_driver_log.operation_latency_ms = metric.latencyMs;
294
+ if (metric.resultFormat || metric.chunkCount) {
295
+ log.entry.sql_driver_log.sql_operation = {
296
+ execution_result: metric.resultFormat,
297
+ };
298
+ if (metric.chunkCount && metric.chunkCount > 0) {
299
+ log.entry.sql_driver_log.sql_operation.chunk_details = {
300
+ total_chunks_present: metric.chunkCount,
301
+ total_chunks_iterated: metric.chunkCount,
302
+ };
303
+ }
304
+ }
305
+ }
306
+ else if (metric.metricType === 'error') {
307
+ const stackOrMessage = (_b = (_a = metric.errorStack) !== null && _a !== void 0 ? _a : metric.errorMessage) !== null && _b !== void 0 ? _b : '';
308
+ log.entry.sql_driver_log.error_info = {
309
+ error_name: metric.errorName || 'UnknownError',
310
+ // Redact common secret shapes and cap length. On the unauth path we
311
+ // keep only the error class — no message body.
312
+ stack_trace: includeCorrelation ? (0, telemetryUtils_1.redactSensitive)(stackOrMessage) : '',
313
+ };
314
+ }
315
+ return log;
316
+ }
317
+ sleep(ms) {
318
+ return new Promise((resolve) => {
319
+ setTimeout(resolve, ms);
320
+ });
321
+ }
322
+ }
323
+ exports.default = DatabricksTelemetryExporter;
324
+ //# sourceMappingURL=DatabricksTelemetryExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabricksTelemetryExporter.js","sourceRoot":"","sources":["../../lib/telemetry/DatabricksTelemetryExporter.ts"],"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AG;gBACpC,UAAU,EAAE,MAAM,CAAC,SAAS,IAAI,cAAc;gBAC9C,oEAAoE;gBACpE,+CAA+C;gBAC/C,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAC,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;AApSD,8CAoSC"}
@@ -0,0 +1,48 @@
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
+ /**
17
+ * Classifies exceptions as terminal (unrecoverable) vs retryable.
18
+ *
19
+ * Terminal exceptions should be flushed immediately to telemetry,
20
+ * while retryable exceptions are buffered until statement completion.
21
+ *
22
+ * This follows the JDBC driver pattern of smart exception flushing
23
+ * to optimize telemetry export efficiency while ensuring critical
24
+ * errors are reported immediately.
25
+ */
26
+ export default class ExceptionClassifier {
27
+ /**
28
+ * Determines if an exception is terminal (non-retryable).
29
+ *
30
+ * Terminal exceptions indicate unrecoverable failures that should
31
+ * be reported immediately, such as authentication failures, invalid
32
+ * requests, or resource not found errors.
33
+ *
34
+ * @param error - The error to classify
35
+ * @returns true if the error is terminal, false otherwise
36
+ */
37
+ static isTerminal(error: Error): boolean;
38
+ /**
39
+ * Determines if an exception is retryable.
40
+ *
41
+ * Retryable exceptions indicate transient failures that may succeed
42
+ * on retry, such as rate limiting, server errors, or network timeouts.
43
+ *
44
+ * @param error - The error to classify
45
+ * @returns true if the error is retryable, false otherwise
46
+ */
47
+ static isRetryable(error: Error): boolean;
48
+ }
@@ -0,0 +1,112 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const AuthenticationError_1 = __importDefault(require("../errors/AuthenticationError"));
22
+ const RetryError_1 = __importDefault(require("../errors/RetryError"));
23
+ /**
24
+ * Classifies exceptions as terminal (unrecoverable) vs retryable.
25
+ *
26
+ * Terminal exceptions should be flushed immediately to telemetry,
27
+ * while retryable exceptions are buffered until statement completion.
28
+ *
29
+ * This follows the JDBC driver pattern of smart exception flushing
30
+ * to optimize telemetry export efficiency while ensuring critical
31
+ * errors are reported immediately.
32
+ */
33
+ class ExceptionClassifier {
34
+ /**
35
+ * Determines if an exception is terminal (non-retryable).
36
+ *
37
+ * Terminal exceptions indicate unrecoverable failures that should
38
+ * be reported immediately, such as authentication failures, invalid
39
+ * requests, or resource not found errors.
40
+ *
41
+ * @param error - The error to classify
42
+ * @returns true if the error is terminal, false otherwise
43
+ */
44
+ static isTerminal(error) {
45
+ var _a;
46
+ // Check for AuthenticationError (terminal)
47
+ if (error instanceof AuthenticationError_1.default) {
48
+ return true;
49
+ }
50
+ // Check for HTTP status codes in error properties
51
+ // Supporting both 'statusCode' and 'status' property names for flexibility
52
+ const statusCode = (_a = error.statusCode) !== null && _a !== void 0 ? _a : error.status;
53
+ if (typeof statusCode === 'number') {
54
+ // Terminal HTTP status codes:
55
+ // 400 - Bad Request (invalid request format)
56
+ // 401 - Unauthorized (authentication required)
57
+ // 403 - Forbidden (permission denied)
58
+ // 404 - Not Found (resource does not exist)
59
+ return statusCode === 400 || statusCode === 401 || statusCode === 403 || statusCode === 404;
60
+ }
61
+ // Default to false for unknown error types
62
+ return false;
63
+ }
64
+ /**
65
+ * Determines if an exception is retryable.
66
+ *
67
+ * Retryable exceptions indicate transient failures that may succeed
68
+ * on retry, such as rate limiting, server errors, or network timeouts.
69
+ *
70
+ * @param error - The error to classify
71
+ * @returns true if the error is retryable, false otherwise
72
+ */
73
+ static isRetryable(error) {
74
+ var _a;
75
+ // Check for RetryError (explicitly retryable)
76
+ if (error instanceof RetryError_1.default) {
77
+ return true;
78
+ }
79
+ // Check for network timeout errors
80
+ if (error.name === 'TimeoutError' || error.message.includes('timeout')) {
81
+ return true;
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
+ }
95
+ // Check for HTTP status codes in error properties
96
+ // Supporting both 'statusCode' and 'status' property names for flexibility
97
+ const statusCode = (_a = error.statusCode) !== null && _a !== void 0 ? _a : error.status;
98
+ if (typeof statusCode === 'number') {
99
+ // Retryable HTTP status codes:
100
+ // 429 - Too Many Requests (rate limiting)
101
+ // 500 - Internal Server Error
102
+ // 502 - Bad Gateway
103
+ // 503 - Service Unavailable
104
+ // 504 - Gateway Timeout
105
+ return statusCode === 429 || statusCode === 500 || statusCode === 502 || statusCode === 503 || statusCode === 504;
106
+ }
107
+ // Default to false for unknown error types
108
+ return false;
109
+ }
110
+ }
111
+ exports.default = ExceptionClassifier;
112
+ //# sourceMappingURL=ExceptionClassifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExceptionClassifier.js","sourceRoot":"","sources":["../../lib/telemetry/ExceptionClassifier.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,wFAAgE;AAChE,sEAA8C;AAE9C;;;;;;;;;GASG;AACH,MAAqB,mBAAmB;IACtC;;;;;;;;;OASG;IACH,MAAM,CAAC,UAAU,CAAC,KAAY;;QAC5B,2CAA2C;QAC3C,IAAI,KAAK,YAAY,6BAAmB,EAAE;YACxC,OAAO,IAAI,CAAC;SACb;QAED,kDAAkD;QAClD,2EAA2E;QAC3E,MAAM,UAAU,GAAG,MAAC,KAAa,CAAC,UAAU,mCAAK,KAAa,CAAC,MAAM,CAAC;QAEtE,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,8BAA8B;YAC9B,6CAA6C;YAC7C,+CAA+C;YAC/C,sCAAsC;YACtC,4CAA4C;YAC5C,OAAO,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,CAAC;SAC7F;QAED,2CAA2C;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAAC,KAAY;;QAC7B,8CAA8C;QAC9C,IAAI,KAAK,YAAY,oBAAU,EAAE;YAC/B,OAAO,IAAI,CAAC;SACb;QAED,mCAAmC;QACnC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACtE,OAAO,IAAI,CAAC;SACb;QAED,kEAAkE;QAClE,0EAA0E;QAC1E,yEAAyE;QACzE,sEAAsE;QACtE,MAAM,SAAS,GAAI,KAAa,CAAC,IAAI,CAAC;QACtC,IACE,SAAS,KAAK,cAAc;YAC5B,SAAS,KAAK,YAAY;YAC1B,SAAS,KAAK,cAAc;YAC5B,SAAS,KAAK,WAAW;YACzB,SAAS,KAAK,WAAW,EACzB;YACA,OAAO,IAAI,CAAC;SACb;QAED,kDAAkD;QAClD,2EAA2E;QAC3E,MAAM,UAAU,GAAG,MAAC,KAAa,CAAC,UAAU,mCAAK,KAAa,CAAC,MAAM,CAAC;QAEtE,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,+BAA+B;YAC/B,0CAA0C;YAC1C,8BAA8B;YAC9B,oBAAoB;YACpB,4BAA4B;YAC5B,wBAAwB;YACxB,OAAO,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,CAAC;SACnH;QAED,2CAA2C;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtFD,sCAsFC"}
@@ -0,0 +1,61 @@
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
+ export interface FeatureFlagContext {
19
+ telemetryEnabled?: boolean;
20
+ lastFetched?: Date;
21
+ refCount: number;
22
+ cacheDuration: number;
23
+ }
24
+ /**
25
+ * Per-host feature-flag cache used to gate telemetry emission. Responsibilities:
26
+ * - dedupe in-flight fetches (thundering-herd protection);
27
+ * - ref-count so context goes away when the last consumer closes;
28
+ * - clamp server-provided TTL into a safe band.
29
+ *
30
+ * Shares HTTP plumbing (agent, user agent) with DatabricksTelemetryExporter.
31
+ * Consumer wiring lands in a later PR in this stack (see PR description).
32
+ */
33
+ export default class FeatureFlagCache {
34
+ private context;
35
+ private authProvider?;
36
+ private contexts;
37
+ private fetchPromises;
38
+ private readonly userAgent;
39
+ private readonly CACHE_DURATION_MS;
40
+ private readonly MIN_CACHE_DURATION_S;
41
+ private readonly MAX_CACHE_DURATION_S;
42
+ private readonly FEATURE_FLAG_NAME;
43
+ constructor(context: IClientContext, authProvider?: IAuthentication | undefined);
44
+ getOrCreateContext(host: string): FeatureFlagContext;
45
+ releaseContext(host: string): void;
46
+ isTelemetryEnabled(host: string): Promise<boolean>;
47
+ /**
48
+ * Strips the `-oss` suffix the feature-flag API does not accept. The server
49
+ * keys off the SemVer triplet only, so anything appended would 404.
50
+ */
51
+ private getDriverVersion;
52
+ private fetchFeatureFlag;
53
+ /**
54
+ * Retries transient network errors once before giving up. Without a retry
55
+ * a single hiccup would leave telemetry disabled for the full cache TTL
56
+ * (15 min). One retry gives an ephemeral DNS / connection-reset failure
57
+ * a second chance without pushing sustained load at a broken endpoint.
58
+ */
59
+ private fetchWithRetry;
60
+ private getAuthHeaders;
61
+ }