-
Notifications
You must be signed in to change notification settings - Fork 50
Forward kernel telemetry options #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,16 @@ | |
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import os from 'os'; | ||
| import { ConnectionOptions } from '../contracts/IDBSQLClient'; | ||
| import { ClientConfig } from '../contracts/IClientContext'; | ||
| import { InternalConnectionOptions } from '../contracts/InternalConnectionOptions'; | ||
| import AuthenticationError from '../errors/AuthenticationError'; | ||
| import HiveDriverError from '../errors/HiveDriverError'; | ||
| import { buildUserAgentString, normalizePemBytes } from '../utils'; | ||
| import driverVersion from '../version'; | ||
| import { DRIVER_NAME } from '../telemetry/types'; | ||
| import { sanitizeProcessName } from '../telemetry/telemetryUtils'; | ||
|
|
||
| /** | ||
| * Default local listener port for the U2M authorization-code callback. | ||
|
|
@@ -127,6 +132,25 @@ export interface KernelSessionDefaults { | |
| retryOverallTimeoutSecs?: number; | ||
| } | ||
|
|
||
| export interface KernelTelemetryOptions { | ||
| /** Driver/runtime identity forwarded to kernel-owned telemetry. */ | ||
| driverName?: string; | ||
| driverVersion?: string; | ||
| runtimeName?: string; | ||
| runtimeVersion?: string; | ||
| runtimeVendor?: string; | ||
| osName?: string; | ||
| osVersion?: string; | ||
| osArch?: string; | ||
| clientAppName?: string; | ||
| localeName?: string; | ||
| charSetEncoding?: string; | ||
| processName?: string; | ||
| /** Kernel-owned telemetry switch and batching. */ | ||
| telemetryEnabled?: boolean; | ||
| telemetryBatchSize?: number; | ||
| } | ||
|
|
||
| /** | ||
| * TLS options shared across all auth-mode variants. Mirror the napi | ||
| * binding's `ConnectionOptions.checkServerCertificate` / `.customCaCert` | ||
|
|
@@ -215,6 +239,7 @@ export interface KernelProxyOptions { | |
| export type KernelNativeConnectionOptions = KernelSessionDefaults & | ||
| KernelTlsOptions & | ||
| KernelHttpOptions & | ||
| KernelTelemetryOptions & | ||
| KernelProxyOptions & | ||
| ( | ||
| | { | ||
|
|
@@ -520,6 +545,61 @@ export function buildKernelRetryOptions(config: { | |
| return out; | ||
| } | ||
|
|
||
| function getLocaleName(env: NodeJS.ProcessEnv = process.env): string { | ||
| try { | ||
| const lang = env.LANG || env.LC_ALL || env.LC_MESSAGES || ''; | ||
| const match = lang.match(/^([a-z]{2}_[A-Z]{2})/); | ||
| return match?.[1] ?? 'en_US'; | ||
| } catch { | ||
| return 'en_US'; | ||
| } | ||
| } | ||
|
|
||
| function getProcessName(): string { | ||
| try { | ||
| if (process.title && process.title !== 'node') { | ||
| return sanitizeProcessName(process.title) || 'node'; | ||
| } | ||
| const scriptPath = process.argv?.[1]; | ||
| if (scriptPath) { | ||
| return sanitizeProcessName(scriptPath).replace(/\.[^.]*$/, '') || 'node'; | ||
| } | ||
| return 'node'; | ||
| } catch { | ||
| return 'node'; | ||
| } | ||
| } | ||
|
|
||
| export function isTelemetryDisabledByEnv(env: NodeJS.ProcessEnv = process.env): boolean { | ||
| const raw = env.DATABRICKS_TELEMETRY_DISABLED; | ||
| const trimmed = typeof raw === 'string' ? raw.trim() : ''; | ||
| return trimmed.length > 0 && /^(1|true|yes|on)$/i.test(trimmed); | ||
| } | ||
|
|
||
| export function buildKernelTelemetryOptions(config: Pick<ClientConfig, 'telemetryEnabled' | 'telemetryBatchSize'>) { | ||
| const telemetry: KernelTelemetryOptions = { | ||
| driverName: DRIVER_NAME, | ||
| driverVersion, | ||
| runtimeName: 'Node.js', | ||
| runtimeVersion: process.version, | ||
| runtimeVendor: 'Node.js Foundation', | ||
| osName: process.platform, | ||
| osVersion: os.release(), | ||
| osArch: os.arch(), | ||
| clientAppName: undefined, | ||
| localeName: getLocaleName(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — |
||
| charSetEncoding: 'UTF-8', | ||
| processName: getProcessName(), | ||
| telemetryEnabled: (config.telemetryEnabled ?? true) && !isTelemetryDisabledByEnv(), | ||
| }; | ||
|
|
||
| if (Number.isFinite(config.telemetryBatchSize)) { | ||
| telemetry.telemetryBatchSize = config.telemetryBatchSize; | ||
| } | ||
|
|
||
| return telemetry; | ||
| } | ||
|
|
||
| /** | ||
| * Map the public `ConnectionOptions.proxy` (`{protocol, host, port, auth}` — | ||
| * the same shape the Thrift backend accepts) onto the kernel's structured napi | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium — Locale env precedence is inverted. POSIX resolution order is
LC_ALL(overrides everything) → the specific category (LC_MESSAGES) →LANG(fallback default). Here the fallback (LANG) is checked first:Because
LANGis set in almost every environment, anLC_ALL/LC_MESSAGESoverride is silently ignored and the reportedlocaleNamewill be wrong for any user who overrides the category vars on top of a baseLANG. Reorder toenv.LC_ALL || env.LC_MESSAGES || env.LANG || ''to match POSIX. This only affects telemetry metadata (not query behavior), hence medium, and the new test (localeNamejust.to.be.a('string')) does not exercise precedence.