Skip to content

Commit 81e6a87

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 81e6a87

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { AsyncLocalStorage } from "node:async_hooks";
2-
import { type sql, WorkspaceClient } from "@databricks/sdk-experimental";
2+
import {
3+
type ClientOptions,
4+
type ConfigOptions,
5+
type sql,
6+
WorkspaceClient,
7+
} from "@databricks/sdk-experimental";
38
import type express from "express";
9+
import { version } from "../../package.json";
410

511
export type RequestContext = {
612
userDatabricksClient?: WorkspaceClient;
@@ -14,9 +20,17 @@ export type RequestContext = {
1420

1521
const asyncLocalStorage = new AsyncLocalStorage<RequestContext>();
1622

17-
export async function databricksClientMiddleware(): Promise<express.RequestHandler> {
18-
const serviceDatabricksClient = new WorkspaceClient({});
23+
function getClientOptions(): ClientOptions {
24+
const isDev = process.env.NODE_ENV === "development";
25+
return {
26+
product: "appkit",
27+
productVersion: version as ClientOptions["productVersion"],
28+
...(isDev && { userAgentExtra: { mode: "dev" } }),
29+
};
30+
}
1931

32+
export async function databricksClientMiddleware(): Promise<express.RequestHandler> {
33+
const serviceDatabricksClient = new WorkspaceClient({}, getClientOptions());
2034
const warehouseId = getWarehouseId(serviceDatabricksClient);
2135
const workspaceId = getWorkspaceId(serviceDatabricksClient);
2236
const serviceUserId = (await serviceDatabricksClient.currentUser.me()).id;
@@ -34,11 +48,14 @@ export async function databricksClientMiddleware(): Promise<express.RequestHandl
3448
let userDatabricksClient: WorkspaceClient | undefined;
3549
const host = process.env.DATABRICKS_HOST;
3650
if (userToken && host) {
37-
userDatabricksClient = new WorkspaceClient({
38-
token: userToken,
39-
host,
40-
authType: "pat",
41-
});
51+
userDatabricksClient = new WorkspaceClient(
52+
{
53+
token: userToken,
54+
host,
55+
authType: "pat",
56+
},
57+
getClientOptions(),
58+
);
4259
} else if (process.env.NODE_ENV === "development") {
4360
// in local development service and no user token are the same
4461
// TODO: use `databricks apps run-local` to fix this

0 commit comments

Comments
 (0)