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

AttributeDescription
git_repoRepository in owner/repo format
git_refCommit SHA, tag, or branch name
source_fileFile path of the decorated function
source_lineLine number
source_functionFunction name
git_repo and git_ref are set at the trace level. source_file, source_line, and source_function are set per span automatically by @observe.

Configuration

TraceRoot resolves git context in this order: explicit init args → TRACEROOT_GIT_REPO / TRACEROOT_GIT_REF env vars → GitHub Actions env vars (GITHUB_REPOSITORY / GITHUB_SHA) → local .git auto-detection. 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:
TRACEROOT_GIT_REPO=your-org/your-repo
TRACEROOT_GIT_REF=9c1e4f2

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
ARG GIT_SHA
ENV TRACEROOT_GIT_REPO=your-org/your-repo   # static
ENV TRACEROOT_GIT_REF=$GIT_SHA              # dynamic, per build
.github/workflows/deploy.yml
- name: Build image
  run: docker build --build-arg GIT_SHA=${{ github.sha }} -t myapp:${{ github.sha }} .
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.