You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(web): add MCP and API key usage tracking to analytics (#950)
* feat(web): add MCP and API key usage tracking to analytics
Move audit event creation from client-side to service functions for search, repos, file source, and file tree endpoints. Add source metadata to distinguish MCP requests from other API calls. Extend analytics SQL to include new actions and display MCP request and API request counts on the analytics dashboard.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
* chore: update CHANGELOG for MCP analytics tracking (#948)
* feat: add audit log retention policy, update analytics UI and docs
- Add SOURCEBOT_EE_AUDIT_RETENTION_DAYS env var (default 180) and AuditLogPruner background job that prunes old audit records daily in batches
- Surface retention period and oldest record date in analytics page header
- Update audit action types table in docs (remove 4 stale, add 11 missing)
- Add audit log storage section to sizing guide with enterprise callout and storage estimates
- Update mock data script with mixed-usage user profiles and new audit actions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: update CHANGELOG for audit log retention policy (#950)
* feat(web): add sourceOverride to getFileSource and getTree
Extend the sourceOverride pattern to getFileSource and getTree so
internal callers (chat AI agent) can tag audit events with the correct
source instead of relying on the HTTP header.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat(web): restructure analytics by source and add global active users
- Tag all audit events with source metadata (sourcebot-web-client,
sourcebot-ask-agent, sourcebot-ui-codenav, mcp) via sourceOverride
- Restructure analytics SQL to segment by Web App (sourcebot-*),
MCP, and API (everything else)
- Add global active users chart at top of analytics page
- Add info hover tooltips explaining each chart
- Prefix chart names with their section (Web/MCP/API) for clarity
- Update inject-audit-data script to use correct source values
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat(db): backfill audit source metadata and add v2 inject script
Add a migration that backfills the 'source' field in audit metadata for
historical events created before source tracking was introduced. All
old events were web-only, so code searches and chats get
'sourcebot-web-client' and navigations get 'sourcebot-ui-codenav'.
Also restore the original inject-audit-data script and add
inject-audit-data-v2 with source-aware mock data generation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat(web): add source-segmented analytics with MCP/API tracking
Restructure analytics dashboard to segment metrics by source (web, MCP,
API). Add audit events for file source, file tree, and repo listing
actions. Pass source metadata through all audit event paths including
MCP server, chat blocking API, and code navigation. Backfill historical
audit events with sourcebot-web-client source.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* shift migrations
* new docs and news data
* update readme to point to new demo site
* fix(web): Log audit failures instead of silently swallowing errors
Replace empty .catch(() => {}) on getAuditService().createAudit() in
askCodebase with a handler that logs the error and audit context
(action, actorId, orgId, source) for debugging and alerting.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(web): Use UTC timezone for "Data since" date display
Adds timeZone: "UTC" to toLocaleDateString() call so the oldest record
date doesn't shift by a day depending on the client's local timezone.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: use type-only imports and update import source in inject-audit-data-v2
Convert Script, PrismaClient, and Prisma imports to type-only imports since
they are only used in type positions. Update PrismaClient/Prisma import source
from "../../dist" to "@sourcebot/db" to match the pattern in scriptRunner.ts.
Also fix broken API reference link in sizing guide docs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(web): Remove redundant .catch() on createAudit calls
createAudit already catches errors internally and logs them with
context, so the .catch(() => {}) at each call site was redundant.
Removed from all 6 call sites: askCodebase, getFileSourceApi,
getTreeApi, searchApi (x2), and listReposApi.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor(web): Rename sourceOverride param to source
The "override" suffix is redundant — callers are simply providing the
source value. Renamed across all 9 files (function signatures, types,
and call sites). No behavioral changes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* changelog typo
* fix news data
* fix(web): Resolve variable shadowing in getFileSourceApi
Rename local `source` variable (git file content) to `fileContent` to
avoid shadowing the `source` parameter, which caused a TypeScript
"Block-scoped variable used before declaration" error.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
### Added
13
13
- Added support a MCP streamable http transport hosted at `/api/mcp`. [#976](https://github.com/sourcebot-dev/sourcebot/pull/976)
14
14
-[EE] Added support for Oauth 2.1 to the remote MCP server hosted at `/api/mcp`. [#977](https://github.com/sourcebot-dev/sourcebot/pull/977)
15
+
- Added MCP and API key usage tracking to analytics dashboard and added audit retention system [#950](https://github.com/sourcebot-dev/sourcebot/pull/950)
To configure Sourcebot (index your own repos, connect your LLMs, etc), check out our [docs](https://docs.sourcebot.dev/docs/configuration/config-file).
109
109
110
110
> [!NOTE]
111
-
> Sourcebot collects <ahref="https://demo.sourcebot.dev/~/search?query=captureEvent%5C(%20repo%3Asourcebot">anonymous usage data</a> by default to help us improve the product. No sensitive data is collected, but if you'd like to disable this you can do so by setting the `SOURCEBOT_TELEMETRY_DISABLED` environment
111
+
> Sourcebot collects <ahref="https://app.sourcebot.dev/~/search?query=captureEvent%5C(%20repo%3Asourcebot">anonymous usage data</a> by default to help us improve the product. No sensitive data is collected, but if you'd like to disable this you can do so by setting the `SOURCEBOT_TELEMETRY_DISABLED` environment
112
112
> variable to `true`. Please refer to our [telemetry docs](https://docs.sourcebot.dev/docs/overview#telemetry) for more information.
Copy file name to clipboardExpand all lines: docs/docs/configuration/audit-logs.mdx
+30-19Lines changed: 30 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,9 @@ This feature gives security and compliance teams the necessary information to en
15
15
## Enabling/Disabling Audit Logs
16
16
Audit logs are enabled by default and can be controlled with the `SOURCEBOT_EE_AUDIT_LOGGING_ENABLED`[environment variable](/docs/configuration/environment-variables).
17
17
18
+
## Retention Policy
19
+
By default, audit logs older than 180 days are automatically pruned daily. You can configure the retention period using the `SOURCEBOT_EE_AUDIT_RETENTION_DAYS`[environment variable](/docs/configuration/environment-variables). Set it to `0` to disable automatic pruning and retain logs indefinitely.
20
+
18
21
## Fetching Audit Logs
19
22
Audit logs are stored in the [postgres database](/docs/overview#architecture) connected to Sourcebot. To fetch all of the audit logs, you can use the following API:
20
23
@@ -110,30 +113,37 @@ curl --request GET '$SOURCEBOT_URL/api/ee/audit' \
Copy file name to clipboardExpand all lines: docs/docs/configuration/environment-variables.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,7 @@ The following environment variables allow you to configure your Sourcebot deploy
42
42
|`HTTPS_PROXY`| - | <p>HTTPS proxy URL for routing SSL requests through a proxy server (e.g., `http://proxy.company.com:8080`). Requires `NODE_USE_ENV_PROXY=1`.</p> |
43
43
|`NO_PROXY`| - | <p>Comma-separated list of hostnames or domains that should bypass the proxy (e.g., `localhost,127.0.0.1,.internal.domain`). Requires `NODE_USE_ENV_PROXY=1`.</p> |
|`SOURCEBOT_EE_AUDIT_RETENTION_DAYS`|`180`| <p>The number of days to retain audit logs. Audit log records older than this will be automatically pruned daily. Set to `0` to disable pruning and retain logs indefinitely.</p> |
45
46
|`AUTH_EE_GCP_IAP_ENABLED`|`false`| <p>When enabled, allows Sourcebot to automatically register/login from a successful GCP IAP redirect</p> |
46
47
|`AUTH_EE_GCP_IAP_AUDIENCE`| - | <p>The GCP IAP audience to use when verifying JWT tokens. Must be set to enable GCP IAP JIT provisioning</p> |
Copy file name to clipboardExpand all lines: docs/docs/deployment/sizing-guide.mdx
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,34 @@ If your instance is resource-constrained, you can reduce the concurrency of back
45
45
46
46
Lowering these values reduces peak resource usage at the cost of slower initial indexing.
47
47
48
+
## Audit log storage
49
+
50
+
<Info>
51
+
Audit logging is an enterprise feature and is only available with an [enterprise license](/docs/overview#license-key). If you are not on an enterprise plan, audit logs are not stored and this section does not apply.
52
+
</Info>
53
+
54
+
[Audit logs](/docs/configuration/audit-logs) are stored in the Postgres database connected to your Sourcebot deployment. Each audit record captures the action performed, the actor, the target, a timestamp, and optional metadata (e.g., request source). There are three database indexes on the audit table to support analytics and lookup queries.
55
+
56
+
**Estimated storage per audit event: ~350 bytes** (including row data and indexes).
57
+
58
+
<Info>
59
+
The table below assumes 50 events per user per day. The actual number depends on usage patterns — each user action (code search, file view, navigation, Ask chat, etc.) creates one audit event. Users who interact via [MCP](/docs/features/mcp-server) or the API tend to generate significantly more events than web-only users, so your real usage may vary.
60
+
</Info>
61
+
62
+
| Team size | Avg events / user / day | Daily events | Monthly storage | 6-month storage |
63
+
|---|---|---|---|---|
64
+
| 10 users | 50 | 500 |~5 MB |~30 MB |
65
+
| 50 users | 50 | 2,500 |~25 MB |~150 MB |
66
+
| 100 users | 50 | 5,000 |~50 MB |~300 MB |
67
+
| 500 users | 50 | 25,000 |~250 MB |~1.5 GB |
68
+
| 1,000 users | 50 | 50,000 |~500 MB |~3 GB |
69
+
70
+
### Retention policy
71
+
72
+
By default, audit logs older than **180 days** are automatically pruned daily by a background job. You can adjust this with the `SOURCEBOT_EE_AUDIT_RETENTION_DAYS`[environment variable](/docs/configuration/environment-variables). Set it to `0` to disable pruning and retain logs indefinitely.
73
+
74
+
For most deployments, the default 180-day retention keeps database size manageable. If you have a large team with heavy MCP/API usage and need longer retention, plan your Postgres disk allocation accordingly using the estimates above.
75
+
48
76
## Monitoring
49
77
50
78
We recommend monitoring the following metrics after deployment to validate your sizing:
Copy file name to clipboardExpand all lines: docs/docs/features/analytics.mdx
+33-11Lines changed: 33 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ import { Callout } from 'nextra/components'
14
14
Analytics provides comprehensive insights into your organization's usage of Sourcebot, helping you understand adoption patterns and
15
15
quantify the value of time saved.
16
16
17
-
This dashboard is backed by [audit log](/docs/configuration/audit-logs) events. Please ensure you have audit logging enabled in order to see these insights.
17
+
This dashboard is backed by [audit log](/docs/configuration/audit-logs) events. Please ensure you have audit logging enabled in order to see these insights. Analytics data is subject to the audit log [retention policy](/docs/configuration/audit-logs#retention-policy). By default, data older than 180 days is automatically pruned.
18
18
19
19
<video
20
20
autoPlay
@@ -25,18 +25,40 @@ This dashboard is backed by [audit log](/docs/configuration/audit-logs) events.
25
25
src="/images/analytics_demo.mp4"
26
26
></video>
27
27
28
-
## Data Metrics
28
+
The analytics dashboard segments usage by source so you can understand how your team interacts with Sourcebot across different interfaces. Each chart supports daily, weekly, and monthly time periods.
29
+
30
+
## Global
29
31
30
32
### Active Users
31
-
Tracks the number of unique users who performed any Sourcebot operation within each time period. This metric helps you understand team adoption
32
-
and engagement with Sourcebot.
33
+
Tracks the number of unique users who performed any tracked action across all sources (web app, MCP, and API). This includes code searches, navigations, Ask chats, file views, and tree browsing. Web repo listings are excluded to reduce noise from passive page loads.
34
+
35
+
## Web App
36
+
37
+
Metrics from the Sourcebot web interface.
38
+
39
+
### Web Active Users
40
+
Shows unique users who interacted with the web interface, broken down by activity type:
41
+
-**All**: Users who performed any web action (code searches, navigations, Ask chats, or file views), excluding repo listings.
42
+
-**Search**: The subset of users who performed code searches.
43
+
-**Ask**: The subset of users who created Ask chat sessions.
44
+
45
+
### Web Activity
46
+
Total event counts for web interface activity:
47
+
-**Code Searches**: Searches performed in the web search bar.
48
+
-**Ask Chats**: Conversations created through the web interface.
49
+
-**Navigations**: "Go to Definition" and "Find All References" actions in the code viewer.
50
+
51
+
## API
33
52
34
-
### Code Searches
35
-
Counts the number of code search operations performed by your team.
53
+
Metrics from MCP integrations and direct API access.
36
54
37
-
### Code Navigation
38
-
Tracks "Go to Definition" and "Find All References" navigation actions. Navigation actions help developers quickly move
39
-
between code locations and understand code relationships.
55
+
### API Active Users
56
+
Shows unique users who interacted via non-web sources:
57
+
-**Any**: Users who used either MCP or the API.
58
+
-**MCP**: Users from IDE extensions and other MCP clients.
59
+
-**API**: Users from direct HTTP API access (e.g., via API keys), excluding web app and MCP traffic.
40
60
41
-
### Ask Chats
42
-
Tracks the number of new Ask chat sessions created by your team.
61
+
### API Requests
62
+
Total request counts:
63
+
-**MCP**: Code searches, file reads, tree listings, repo listings, and Ask chats from MCP clients.
64
+
-**API**: Direct HTTP API requests, excluding web app and MCP traffic.
0 commit comments