Skip to content

Commit 0cbc3e1

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 0cbc3e1

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

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

Lines changed: 26 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 as productName, version as productVersion } from "../../package.json";
49

510
export type RequestContext = {
611
userDatabricksClient?: WorkspaceClient;
@@ -14,9 +19,19 @@ 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+
const normalizedVersion = productVersion.split(".").slice(0, 3).join(".") as ClientOptions["productVersion"];
25+
26+
return {
27+
product: productName,
28+
productVersion: normalizedVersion,
29+
...(isDev && { userAgentExtra: { mode: "dev" } }),
30+
};
31+
}
1932

33+
export async function databricksClientMiddleware(): Promise<express.RequestHandler> {
34+
const serviceDatabricksClient = new WorkspaceClient({}, getClientOptions());
2035
const warehouseId = getWarehouseId(serviceDatabricksClient);
2136
const workspaceId = getWorkspaceId(serviceDatabricksClient);
2237
const serviceUserId = (await serviceDatabricksClient.currentUser.me()).id;
@@ -34,11 +49,14 @@ export async function databricksClientMiddleware(): Promise<express.RequestHandl
3449
let userDatabricksClient: WorkspaceClient | undefined;
3550
const host = process.env.DATABRICKS_HOST;
3651
if (userToken && host) {
37-
userDatabricksClient = new WorkspaceClient({
38-
token: userToken,
39-
host,
40-
authType: "pat",
41-
});
52+
userDatabricksClient = new WorkspaceClient(
53+
{
54+
token: userToken,
55+
host,
56+
authType: "pat",
57+
},
58+
getClientOptions(),
59+
);
4260
} else if (process.env.NODE_ENV === "development") {
4361
// in local development service and no user token are the same
4462
// TODO: use `databricks apps run-local` to fix this

0 commit comments

Comments
 (0)