Skip to main content
TraceRoot automatically captures the git repository, commit, and the exact source file and line number for each instrumented function. This powers the Show Code feature in the trace viewer and enables the AI agent to jump directly from a failing trace to the relevant code.

What Gets Captured

traceroot.git.repo and traceroot.git.ref are set at the trace level. The traceroot.git.source_* attributes are set per span automatically by @observe.

Configuration

TraceRoot resolves the repository and ref independently, filling each unset value in this order:
  1. Explicit initialization arguments.
  2. TRACEROOT_GIT_REPO / TRACEROOT_GIT_REF environment variables.
  3. GitHub Actions variables (GITHUB_REPOSITORY / GITHUB_SHA).
  4. Files in <current working directory>/.git (config and HEAD). This step does not need the git binary and does not search parent directories.
  5. A git subprocess (git remote get-url origin and git rev-parse HEAD). This step needs the binary but works when the process starts in a repository subdirectory.
Automatic repository parsing recognizes only github.com remotes. For GitLab, Bitbucket, or self-hosted remotes, set TRACEROOT_GIT_REPO explicitly. Because the repository and ref resolve independently, one may be present while the other is missing. In that case the SDK logs git context incomplete; set the missing value explicitly so source correlation has both fields. Local .git auto-detection is a development convenience only. Production containers usually ship without a .git directory or the git binary, so auto-detection silently finds nothing and the AI agent cannot correlate traces to source. In production, always inject git context explicitly (see below). Set them explicitly via environment variables:

Git context in production

Use build-time injection: inject the repo (static) and commit SHA (per-build) as environment variables at build time. The SDK reads them automatically — no code change required.
Dockerfile
.github/workflows/deploy.yml
In GitHub Actions, TraceRoot reads the standard GITHUB_REPOSITORY and GITHUB_SHA automatically — no Dockerfile change needed. On other CI/platform providers, use the build-time injection above. Apply this to every traced service, including background workers and cron/queue consumers — not just your API server. Each process resolves git context independently. For setups that reuse one image across commits, set TRACEROOT_GIT_REPO / TRACEROOT_GIT_REF in the Kubernetes pod spec or ECS task definition at deploy time instead.

Why It Matters

Source code correlation is what enables the AI agent to perform accurate root cause analysis — it can read the exact function that produced a failing span, not just the trace data. See Root Cause Analysis.