11import { AsyncLocalStorage } from "node:async_hooks" ;
2- import { type sql , WorkspaceClient } from "@databricks/sdk-experimental" ;
2+ import {
3+ type ClientOptions ,
4+ type sql ,
5+ WorkspaceClient ,
6+ } from "@databricks/sdk-experimental" ;
37import type express from "express" ;
8+ import { name , version } from "../../package.json" ;
49
510export type RequestContext = {
611 userDatabricksClient ?: WorkspaceClient ;
@@ -14,9 +19,17 @@ export type RequestContext = {
1419
1520const asyncLocalStorage = new AsyncLocalStorage < RequestContext > ( ) ;
1621
17- export async function databricksClientMiddleware ( ) : Promise < express . RequestHandler > {
18- const serviceDatabricksClient = new WorkspaceClient ( { } ) ;
22+ function getClientOptions ( ) : ClientOptions {
23+ const isDev = process . env . NODE_ENV === "development" ;
24+ return {
25+ product : name ,
26+ productVersion : version as ClientOptions [ "productVersion" ] ,
27+ ...( isDev && { userAgentExtra : { mode : "dev" } } ) ,
28+ } ;
29+ }
1930
31+ export async function databricksClientMiddleware ( ) : Promise < express . RequestHandler > {
32+ const serviceDatabricksClient = new WorkspaceClient ( { } , getClientOptions ( ) ) ;
2033 const warehouseId = getWarehouseId ( serviceDatabricksClient ) ;
2134 const workspaceId = getWorkspaceId ( serviceDatabricksClient ) ;
2235 const serviceUserId = ( await serviceDatabricksClient . currentUser . me ( ) ) . id ;
@@ -34,11 +47,14 @@ export async function databricksClientMiddleware(): Promise<express.RequestHandl
3447 let userDatabricksClient : WorkspaceClient | undefined ;
3548 const host = process . env . DATABRICKS_HOST ;
3649 if ( userToken && host ) {
37- userDatabricksClient = new WorkspaceClient ( {
38- token : userToken ,
39- host,
40- authType : "pat" ,
41- } ) ;
50+ userDatabricksClient = new WorkspaceClient (
51+ {
52+ token : userToken ,
53+ host,
54+ authType : "pat" ,
55+ } ,
56+ getClientOptions ( ) ,
57+ ) ;
4258 } else if ( process . env . NODE_ENV === "development" ) {
4359 // in local development service and no user token are the same
4460 // TODO: use `databricks apps run-local` to fix this
0 commit comments