Skip to content

feat(appkit-ui): export App Analytics from the beta barrels - #613

Draft
ditadi wants to merge 2 commits into
stack/app-analytics/02-relayfrom
stack/app-analytics/03-ui
Draft

ditadi wants to merge 2 commits into
stack/app-analytics/02-relayfrom
stack/app-analytics/03-ui

Conversation

@ditadi

@ditadi ditadi commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Why the change

AppKit apps already depend on @databricks/appkit-ui, so exporting App Analytics from its beta barrels lets an app turn it on with one <AppAnalytics /> and no new dependency.

Special things to note

  • appkit-ui bundles @databricks/app-analytics inline, the same way it bundles shared, because the SDK isn't published on its own yet. dist-appkit.ts drops the workspace dependency, and web-vitals becomes a direct dependency of appkit-ui. The bundle-size-baseline.json update reflects the added code.
  • appAnalytics is now a lazy facade over one client stored on globalThis. Importing it creates nothing, so bundlers can drop it. Every copy of the module in a tab (appkit-ui's inline copy, a direct install, and later the auto-start script in feat(appkit): start App Analytics automatically when App telemetry is on #614) configures and records through the same client.
  • The exports live under /beta, so the API can still change between minor releases.

Change outline

New exports from the two beta barrels:

 // @databricks/appkit-ui/react/beta
+export { appAnalytics } from "@databricks/app-analytics";
+export { AppAnalytics, type AppAnalyticsProps } from "@databricks/app-analytics/react";

 // @databricks/appkit-ui/js/beta
+export { appAnalytics, createAppAnalytics, type AppAnalyticsClient, type AppAnalyticsOptions,
+         type AppAnalyticsEvent, type AppAnalyticsDiagnostic, … } from "@databricks/app-analytics";

The default client becomes a shared singleton created on first use:

-export const appAnalytics = new BrowserAppAnalyticsClient({ … });
+const CLIENT_KEY = Symbol.for("@databricks/app-analytics/client-v1");
+function sharedClient() {
+  return (globalThis[CLIENT_KEY] ??= new BrowserAppAnalyticsClient({ … }));
+}
+export const appAnalytics: AppAnalyticsClient = {
+  init: (o) => sharedClient().init(o),
+  track: (n, p) => sharedClient().track(n, p),
+  page, flush, shutdown  // same pattern
+};

Build and packaging:

 packages/appkit-ui/tsdown.config.ts
-  noExternal: ["shared"],
+  noExternal: ["shared", /^@databricks\/app-analytics(\/|$)/],
 packages/appkit-ui/package.json
+  "@databricks/app-analytics": "workspace:*",   # removed by dist-appkit.ts at pack time
+  "web-vitals": "6.1.1",
 packages/app-analytics/package.json
+  "sideEffects": false,

dev-playground mounts the component once and adds a page for trying it out:

 <RootComponent> (apps/dev-playground/client/src/routes/__root.tsx)
   <TooltipProvider>
+    <AppAnalytics webVitals autocapture onDiagnostic={pushDiagnostic} />
     …
+<AppAnalyticsRoute> (routes/app-analytics.route.tsx)
+  useDiagnostics()                # diagnostics pushed from the root component
+  Track / Page view / Queue burst / Flush buttons → appAnalytics.*
+  annotated button → [data-app-analytics-event] autocapture

apps/dev-playground/tests/app-analytics.spec.ts loads the page, then checks that Track followed by Flush posts OTLP JSON through the relay from #612.

This pull request and its description were written by Isaac.

@ditadi
ditadi added this pull request to stack #616 September 26, 2026 21:42
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle size report

Compared against bundle-size-baseline.json (main).

@databricks/appkit

npm tarball (packed): 1.2 MB (+19 KB) — gzipped download (dist + bin; excludes release-only docs/NOTICE).

dist raw gzip
JS (runtime) 1.2 MB (+18 KB) 433 KB (+6.4 KB)
Type declarations 446 KB (+3.1 KB) 162 KB (-56 B)
Source maps 2.4 MB (+34 KB) 810 KB (+14 KB)
Other 11 KB 3.7 KB (+16 B)
Total 4.0 MB (+56 KB) 1.4 MB (+21 KB)
Per-entry composition (own code — deps external (as shipped))
Entry Initial (gz) Lazy (gz) Total (gz) node_modules (min) Own code (min)
. 98 KB (+2.3 KB) 2.5 KB (-8 B) 101 KB (+2.3 KB) external 321 KB (+5.8 KB)
./beta 93 KB (+236 B) 479 B (+22 B) 94 KB (+258 B) external 282 KB (+618 B)
./testing 39 KB (+49 B) 33 KB (+2.1 KB) 71 KB (+2.2 KB) external 207 KB (+5.8 KB)
./tsdown 520 B (+1 B) 0 B 520 B (+1 B) external 813 B
./type-generator 23 KB (+125 B) 0 B 23 KB (+125 B) external 65 KB (+82 B)

Chunks:

Entry Chunk Load Size (gz)
. index.js initial 94 KB
. utils.js initial 4.0 KB
. remote-tunnel-manager.js lazy 2.5 KB
./beta beta.js initial 77 KB
./beta stream-manager.js initial 5.8 KB
./beta databricks.js initial 3.3 KB
./beta wide-event-emitter.js initial 3.3 KB
./beta configuration.js initial 2.3 KB
./beta service-context.js initial 1.3 KB
./beta client.js initial 434 B
./beta client-options.js initial 219 B
./beta supervisor-api.js lazy 191 B
./beta databricks.js lazy 165 B
./beta index.js lazy 123 B
./testing manifest.js initial 26 KB
./testing index.js initial 10.0 KB
./testing wide-event-emitter.js initial 3.0 KB
./testing index.js lazy 29 KB
./testing remote-tunnel-manager.js lazy 2.5 KB
./testing utils.js lazy 1.2 KB
./tsdown index.js initial 520 B
./type-generator index.js initial 23 KB

@databricks/appkit-ui

npm tarball (packed): 409 KB (+13 KB) — gzipped download (dist + bin; excludes release-only docs/NOTICE).

dist raw gzip
JS (runtime) 464 KB (+10 KB) 156 KB (+4.9 KB)
Type declarations 240 KB (+5.4 KB) 88 KB (+2.0 KB)
Source maps 882 KB (+16 KB) 292 KB (+8.3 KB)
CSS 16 KB 3.2 KB (-10 B)
Total 1.6 MB (+32 KB) 540 KB (+15 KB)
Per-entry composition (consumer bundle — deps bundled, peerDeps external)
Entry Initial (gz) Lazy (gz) Total (gz) node_modules (min) Own code (min)
./js 5.3 KB (+9 B) 49 KB (+49 B) 55 KB (+58 B) 208 KB 14 KB
./js/beta 13 KB (+1.2 KB) 0 B 13 KB (+1.2 KB) 8.5 KB (+4 B) 32 KB (+3.3 KB)
./react 432 KB (+1.8 KB) 49 KB (+32 B) 481 KB (+1.8 KB) 1.3 MB 177 KB
./react/beta 14 KB (+1.2 KB) 0 B 14 KB (+1.2 KB) 8.5 KB 34 KB (+3.4 KB)

Chunks:

Entry Chunk Load Size (gz)
./js index.js initial 5.2 KB
./js chunk initial 120 B
./js apache-arrow lazy 49 KB
./js/beta beta.js initial 13 KB
./react index.js initial 430 KB
./react tslib initial 2.1 KB
./react apache-arrow lazy 49 KB
./react/beta beta.js initial 14 KB

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 36460968676 -R databricks/appkit -n appkit-template-0.78.0-pr.52a54dc-stack-app-analytics-03-ui-613 -D appkit-pr-613 \
  && unzip -o "appkit-pr-613/appkit-template-0.78.0-pr.52a54dc-stack-app-analytics-03-ui-613.zip" -d "appkit-pr-613" \
  && databricks apps init --template "appkit-pr-613"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

@ditadi
ditadi force-pushed the stack/app-analytics/03-ui branch from bce5021 to b2687a7 Compare September 28, 2026 13:55
ditadi and others added 2 commits September 28, 2026 18:32
appkit-ui now bundles @databricks/app-analytics inline and re-exports it
from react/beta (AppAnalytics, appAnalytics) and js/beta. The published
package depends only on web-vitals, and dist-appkit.ts drops the
workspace dependency until @databricks/app-analytics is published on its
own.

The library is side-effect free: appAnalytics creates one shared client
on first use, keyed on globalThis, so every copy of the module in a tab
shares it.

dev-playground mounts <AppAnalytics /> in the root layout and adds an
App Analytics page, covered by a Playwright spec.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: ditadi <victordperd@gmail.com>
…oreSend types

Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi
ditadi force-pushed the stack/app-analytics/03-ui branch from b2687a7 to b11f56b Compare September 28, 2026 17:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant