@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
package/README.md CHANGED
@@ -51,6 +51,18 @@ client
51
51
  });
52
52
  ```
53
53
 
54
+ ## Telemetry
55
+
56
+ The driver emits connection, statement, and CloudFetch metrics plus
57
+ redacted error events to help Databricks improve driver reliability. No
58
+ SQL text, parameter values, or row data is ever collected. Emission is
59
+ gated by a server-side feature flag and can be disabled per-connection
60
+ with `telemetryEnabled: false` or globally with the
61
+ `DATABRICKS_TELEMETRY_DISABLED` env var.
62
+
63
+ See [docs/TELEMETRY.md](docs/TELEMETRY.md) for the full event payloads,
64
+ tuning knobs, multi-tenant guidance, and troubleshooting.
65
+
54
66
  ## Run Tests
55
67
 
56
68
  ### Unit tests
@@ -9,6 +9,8 @@ import IDBSQLSession from './contracts/IDBSQLSession';
9
9
  import IAuthentication from './connection/contracts/IAuthentication';
10
10
  import IDBSQLLogger from './contracts/IDBSQLLogger';
11
11
  import IConnectionProvider from './connection/contracts/IConnectionProvider';
12
+ import TelemetryEventEmitter from './telemetry/TelemetryEventEmitter';
13
+ import MetricsAggregator from './telemetry/MetricsAggregator';
12
14
  export type ThriftLibrary = Pick<typeof thrift, 'createClient'>;
13
15
  export default class DBSQLClient extends EventEmitter implements IDBSQLClient, IClientContext {
14
16
  private static defaultLogger?;
@@ -20,6 +22,12 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
20
22
  private readonly logger;
21
23
  private thrift;
22
24
  private readonly sessions;
25
+ private host?;
26
+ private httpPath?;
27
+ private authType?;
28
+ private telemetryClient?;
29
+ private telemetryEmitter?;
30
+ private driverConfigShipped;
23
31
  private static getDefaultLogger;
24
32
  private static getDefaultConfig;
25
33
  constructor(options?: ClientOptions);
@@ -31,6 +39,66 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
31
39
  */
32
40
  private wrapTokenProvider;
33
41
  private createConnectionProvider;
42
+ /**
43
+ * Extract the numeric workspace ID for telemetry.
44
+ *
45
+ * Two URL shapes carry the workspace ID today:
46
+ * - Warehouse, query form: `/sql/1.0/warehouses/<id>?o=<wsId>`
47
+ * - All-purpose cluster, path form: `sql/protocolv1/o/<wsId>/<cluster-id>`
48
+ *
49
+ * Host-based extraction was tried previously but produced confidently-wrong
50
+ * values:
51
+ * - AWS `dbc-XXXXX-YYYY.cloud.databricks.com` → `dbc-XXXXX-YYYY`
52
+ * is the deployment shard prefix, not the workspace ID.
53
+ * - Azure `adb-NNNNNNNNNNNNN.NN.azuredatabricks.net` → the workspace ID is
54
+ * the numeric portion after the `adb-` prefix (and before the form-factor
55
+ * digit), not `adb-NNN`.
56
+ *
57
+ * Returns `undefined` when no workspace ID can be derived. Server-side
58
+ * attribution is better off seeing a missing field than a wrong value.
59
+ */
60
+ private static extractWorkspaceId;
61
+ private static hasMalformedOrgParam;
62
+ /**
63
+ * Build the customHeaders map applied to telemetry POSTs and feature-flag
64
+ * GETs (SPOG / Single Panel of Glass support). When `httpPath` carries a
65
+ * workspace ID — either as a `?o=<wsId>` query (warehouse) or a
66
+ * `/o/<wsId>/<cluster-id>` path segment (all-purpose cluster) — endpoints
67
+ * that don't include the workspace in their URL path need it conveyed via
68
+ * the `x-databricks-org-id` header instead. A user-supplied value in
69
+ * `userHeaders` (case-insensitively keyed) wins over the parsed value.
70
+ *
71
+ * `httpPath` is passed explicitly (rather than read off `this.httpPath`) so
72
+ * the SPOG-routing dependency is visible in the signature — a future
73
+ * refactor that reorders connect() can't silently break injection.
74
+ */
75
+ private buildCustomHeaders;
76
+ /**
77
+ * Build driver configuration for telemetry reporting.
78
+ * @returns DriverConfiguration object with current driver settings
79
+ */
80
+ private buildDriverConfiguration;
81
+ /**
82
+ * Map Node.js auth type to telemetry auth enum string.
83
+ * Distinguishes between U2M and M2M OAuth flows.
84
+ */
85
+ private mapAuthType;
86
+ /**
87
+ * Get locale name in format language_country (e.g., en_US).
88
+ * Matches JDBC format: user.language + '_' + user.country
89
+ */
90
+ private getLocaleName;
91
+ /**
92
+ * Get process name, similar to JDBC's ProcessNameUtil.
93
+ * Returns the script name or process title.
94
+ */
95
+ private getProcessName;
96
+ /**
97
+ * Initialize telemetry components if enabled.
98
+ * CRITICAL: All errors swallowed and logged at LogLevel.debug ONLY.
99
+ * Driver NEVER throws exceptions due to telemetry.
100
+ */
101
+ private initializeTelemetry;
34
102
  /**
35
103
  * Connects DBSQLClient to endpoint
36
104
  * @public
@@ -51,10 +119,49 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
51
119
  * const session = await client.openSession();
52
120
  */
53
121
  openSession(request?: OpenSessionRequest): Promise<IDBSQLSession>;
122
+ /**
123
+ * Closes the client, releasing sessions and telemetry resources.
124
+ *
125
+ * The internal telemetry flush timer uses `setInterval(...).unref()` so it
126
+ * cannot keep the Node.js process alive on its own. As a consequence, any
127
+ * telemetry buffered between flush ticks is lost if the process exits
128
+ * without calling `close()`. Long-lived applications should `await` this
129
+ * method on shutdown so the aggregator drains its remaining metrics.
130
+ */
54
131
  close(): Promise<void>;
55
132
  getConfig(): ClientConfig;
56
133
  getLogger(): IDBSQLLogger;
57
134
  getConnectionProvider(): Promise<IConnectionProvider>;
58
135
  getClient(): Promise<IThriftClient>;
59
136
  getDriver(): Promise<IDriver>;
137
+ /**
138
+ * Returns the authentication provider associated with this client, if any.
139
+ * Intended for internal telemetry/feature-flag call sites that need to
140
+ * obtain auth headers directly without routing through `IClientContext`.
141
+ *
142
+ * @internal Not part of the public API. May change without notice.
143
+ */
144
+ getAuthProvider(): IAuthentication | undefined;
145
+ /** @internal */
146
+ getTelemetryEmitter(): TelemetryEventEmitter | undefined;
147
+ /** @internal */
148
+ getTelemetryAggregator(): MetricsAggregator | undefined;
149
+ /**
150
+ * Operator-visible snapshot of the client's telemetry state: current
151
+ * buffer depth, in-flight statement aggregations, cumulative drops/
152
+ * evictions, and circuit-breaker state. Returns `undefined` when
153
+ * telemetry is disabled (config, env-kill, or feature-flag).
154
+ *
155
+ * Use this in health-check endpoints or shutdown banners to verify that
156
+ * telemetry is flowing. A non-zero `droppedMetrics` between observations
157
+ * means buffer overflow — raise `telemetryMaxPendingMetrics`.
158
+ */
159
+ getTelemetryStats(): {
160
+ host: string;
161
+ pendingMetricsCount: number;
162
+ inFlightStatements: number;
163
+ droppedMetrics: number;
164
+ evictedStatements: number;
165
+ circuitBreakerState: string;
166
+ } | undefined;
60
167
  }