Skip to content

Commit b14f568

Browse files
committed
feat: configure Databricks client user agent
Add AppKit version and dev mode flag to Databricks client user agent. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]> Signed-off-by: Fabian Jakobs <[email protected]>
1 parent da150f2 commit b14f568

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

packages/app-kit/src/utils/databricks-client-middleware.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { 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";
37
import type express from "express";
8+
import { name, version } from "../../package.json";
49

510
export type RequestContext = {
611
userDatabricksClient?: WorkspaceClient;
@@ -14,9 +19,17 @@ export type RequestContext = {
1419

1520
const 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

Comments
 (0)