Code Insights is available on Enterprise plans.
What you can track
Anything searchable in Sourcegraph is trackable in Code Insights:- The number of files still using a deprecated API
- How many repositories have migrated to a new framework version
- The count of open
TODOcomments across your codebase - Which language makes up what percentage of your repositories
- Whether a known vulnerable dependency version still exists anywhere
Insight types
- Search-based insights
- Language statistics
- Version tracking (detect and track)
Track the count of any pattern expressed as a Sourcegraph search query. Each data series corresponds to one search query, and multiple series can be overlaid on a single chart.Example uses:
- Count of
TODOcomments over time - Adoption rate of a new logging library (number of files importing it)
- Number of repositories still calling a deprecated function
Creating your first insight
This walkthrough creates a search-based insight that tracks the number ofTODO comments in your codebase over the past year.
Navigate to Insights
Open your Sourcegraph instance and click Insights in the main navigation bar. If you do not see this item, ask your site administrator to enable Code Insights.
Select insight type
On the insight type selection page, choose Track changes. This creates a search-based insight where you define one or more search queries to track over time.Choose Detect and track instead if you want to automatically generate separate series for each distinct captured value (for example, each version of a dependency).
Select repositories
Choose which repositories to include:
- Enter specific repository URLs (e.g.,
github.com/myorg/myrepo) separated by commas, or - Check Run over all repositories to track the pattern across your entire Sourcegraph instance
Define a data series
A data series becomes a line on the chart.
- Name: Enter a descriptive label such as
TODO count - Search query: Enter the search expression to count — for this example,
TODO - Color: Choose a line color for the chart
Configure the chart
- Title: Enter a descriptive chart title, such as
TODO comments in myrepo - Data point interval: Choose the time between data points (e.g., 1 month). Sourcegraph provides 12 data points per series, so monthly intervals show one year of history.
Create and view the insight
Click Create code insight. You are taken to the Insights dashboard where your new chart appears immediately, with historical data already populated from your Git history.
Use cases
Migration tracking
Track the progress of a large-scale migration — for example, from one framework to another — by charting the number of files still using the old pattern alongside the number using the new one.
Vulnerability remediation
After a CVE disclosure, create an insight to track how many repositories still contain a vulnerable version. Watch the count drop as teams apply patches.
Dependency version adoption
Use detect-and-track to chart which versions of a key dependency are in use across your organization. Identify which teams are behind and by how much.
Code health over time
Track proxy metrics for code health:
TODO count, FIXME count, or the number of files exceeding a line length threshold. Use these as a signal for technical debt accumulation.Test coverage growth
Count the number of test files or test functions over time to verify that testing practices are improving alongside feature development.
API surface area
Track how many public API endpoints exist across your services to understand whether the surface area is growing or being consolidated.
Dashboards
Insights are organized into dashboards. You can create multiple dashboards to group related insights — for example, a dashboard for security metrics, a dashboard for a specific team’s migration work, or a dashboard for platform health. Each dashboard has configurable visibility: private to you, shared with your organization, or visible to your entire Sourcegraph instance. From the Insights home page, click + Create dashboard to create a new dashboard and then add insights to it. Insights can appear on multiple dashboards simultaneously.Frequently asked questions
How far back does backfilling go?
How far back does backfilling go?
Sourcegraph backfills 12 data points at the configured interval. At a monthly interval, this gives you one year of history. At a weekly interval, about three months. The backfill reads from your Git history, so data is available immediately without waiting for new commits.
Can I track patterns across all repositories?
Can I track patterns across all repositories?
Yes. When you enable Run over all repositories, the insight runs against every repository indexed in your Sourcegraph instance. For very large instances (thousands of repositories), there may be a short delay for initial backfill.
What is the difference between Track changes and Detect and track?
What is the difference between Track changes and Detect and track?
Track changes requires you to define each data series manually with a specific search query. Detect and track uses a capture group in a single query to automatically generate one series per distinct captured value — useful for tracking all versions of a dependency without manually creating a series for each version.
Can I export insight data?
Can I export insight data?
Yes. Insight data is accessible via the Sourcegraph API, and you can download chart data in CSV format from the insight card menu. This lets you import metrics into external dashboards or spreadsheets.
Do insights respect repository permissions?
Do insights respect repository permissions?
Yes. Each user sees only data from repositories they have access to. If you share a dashboard with another user, they see the insight filtered to their accessible repositories, which may differ from what you see.
Related features
Code Search
Write and test the search queries that power your insights before creating the chart.
Batch Changes
Use Batch Changes to act on the patterns surfaced by Code Insights — for example, automatically opening PRs to fix the issues you are tracking.
Deep Search
Ask questions about the patterns Code Insights reveals — for example, “Why are there so many TODOs in this module?”
Admin overview
Configure Code Insights for your Sourcegraph instance and manage access controls.