@@ -418,13 +418,13 @@ function makeBinding(connection: KernelConnection): KernelNativeBinding & {
418418 return Object . assign ( binding , { openSessionStub } ) ;
419419}
420420
421- function makeContext ( logger ?: IDBSQLLogger ) : IClientContext {
421+ function makeContext ( logger ?: IDBSQLLogger , configOverrides : Partial < ClientConfig > = { } ) : IClientContext {
422422 const log : IDBSQLLogger = logger ?? {
423423 log ( _level : LogLevel , _message : string ) : void {
424424 // no-op
425425 } ,
426426 } ;
427- const config = { } as ClientConfig ;
427+ const config = configOverrides as ClientConfig ;
428428 return {
429429 getConfig : ( ) => config ,
430430 getLogger : ( ) => log ,
@@ -551,6 +551,79 @@ describe('KernelBackend', () => {
551551 } ) ;
552552 } ) ;
553553
554+ it ( 'openSession() forwards kernel-owned telemetry config and runtime identity to napi binding' , async ( ) => {
555+ const savedEnv = process . env . DATABRICKS_TELEMETRY_DISABLED ;
556+ delete process . env . DATABRICKS_TELEMETRY_DISABLED ;
557+
558+ const connection = new FakeNativeConnection ( ) ;
559+ const binding = makeBinding ( connection ) ;
560+ const backend = new KernelBackend ( {
561+ context : makeContext ( undefined , { telemetryEnabled : false , telemetryBatchSize : 17 } ) ,
562+ nativeBinding : binding ,
563+ } ) ;
564+
565+ try {
566+ await backend . connect ( {
567+ host : 'workspace.example' ,
568+ path : '/sql/1.0/warehouses/xyz' ,
569+ token : 'dapi-token' ,
570+ } as ConnectionOptions ) ;
571+
572+ await backend . openSession ( { } ) ;
573+
574+ const args = binding . openSessionStub . firstCall . args [ 0 ] as Record < string , unknown > ;
575+ expect ( args . driverName ) . to . equal ( 'nodejs-sql-driver' ) ;
576+ expect ( args . driverVersion ) . to . be . a ( 'string' ) . and . not . equal ( '' ) ;
577+ expect ( args . runtimeName ) . to . equal ( 'Node.js' ) ;
578+ expect ( args . runtimeVersion ) . to . equal ( process . version ) ;
579+ expect ( args . runtimeVendor ) . to . equal ( 'Node.js Foundation' ) ;
580+ expect ( args . osName ) . to . equal ( process . platform ) ;
581+ expect ( args . osVersion ) . to . be . a ( 'string' ) . and . not . equal ( '' ) ;
582+ expect ( args . osArch ) . to . be . a ( 'string' ) . and . not . equal ( '' ) ;
583+ expect ( args . localeName ) . to . be . a ( 'string' ) . and . not . equal ( '' ) ;
584+ expect ( args . charSetEncoding ) . to . equal ( 'UTF-8' ) ;
585+ expect ( args . processName ) . to . be . a ( 'string' ) . and . not . equal ( '' ) ;
586+ expect ( args . telemetryEnabled ) . to . equal ( false ) ;
587+ expect ( args . telemetryBatchSize ) . to . equal ( 17 ) ;
588+ } finally {
589+ if ( savedEnv === undefined ) {
590+ delete process . env . DATABRICKS_TELEMETRY_DISABLED ;
591+ } else {
592+ process . env . DATABRICKS_TELEMETRY_DISABLED = savedEnv ;
593+ }
594+ }
595+ } ) ;
596+
597+ it ( 'openSession() forwards env-disabled kernel telemetry even when config enables telemetry' , async ( ) => {
598+ const savedEnv = process . env . DATABRICKS_TELEMETRY_DISABLED ;
599+ process . env . DATABRICKS_TELEMETRY_DISABLED = 'true' ;
600+
601+ const connection = new FakeNativeConnection ( ) ;
602+ const binding = makeBinding ( connection ) ;
603+ const backend = new KernelBackend ( {
604+ context : makeContext ( undefined , { telemetryEnabled : true } ) ,
605+ nativeBinding : binding ,
606+ } ) ;
607+
608+ try {
609+ await backend . connect ( {
610+ host : 'workspace.example' ,
611+ path : '/sql/1.0/warehouses/xyz' ,
612+ token : 'dapi-token' ,
613+ } as ConnectionOptions ) ;
614+ await backend . openSession ( { } ) ;
615+
616+ const args = binding . openSessionStub . firstCall . args [ 0 ] as { telemetryEnabled ?: boolean } ;
617+ expect ( args . telemetryEnabled ) . to . equal ( false ) ;
618+ } finally {
619+ if ( savedEnv === undefined ) {
620+ delete process . env . DATABRICKS_TELEMETRY_DISABLED ;
621+ } else {
622+ process . env . DATABRICKS_TELEMETRY_DISABLED = savedEnv ;
623+ }
624+ }
625+ } ) ;
626+
554627 it ( 'openSession() serializes session-level queryTags into sessionConf.QUERY_TAGS' , async ( ) => {
555628 const connection = new FakeNativeConnection ( ) ;
556629 const binding = makeBinding ( connection ) ;
0 commit comments