How to Instrument a GitHub Actions Pipeline With OpenTelemetry
A workflow run maps cleanly onto a trace: the run is the root span, each job a child span, each step a grandchild.
Run an exporter after the pipeline finishes that reads the run via the GitHub API and pushes spans over OTLP. inception-health/otel-export-trace-action and corentinmusard/otel-cicd-action both turn a completed run into a trace with one job.
Steps
- Add a trigger on
workflow_run(completed) so the exporter runs after your CI workflow. - Point the exporter at your OTLP endpoint with
OTLP_ENDPOINTand any auth headers. - Pass the finished run id so the action can fetch jobs and steps.
- Open your tracing backend and find the trace named after the workflow.
Exporter workflow
.github/workflows/otel.yml
on:
workflow_run:
workflows: ["CI"]
types: [completed]
jobs:
export-trace:
runs-on: ubuntu-latest
steps:
- uses: corentinmusard/otel-cicd-action@v2
with:
otlpEndpoint: ${{ secrets.OTLP_ENDPOINT }}
otlpHeaders: ${{ secrets.OTLP_HEADERS }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
runId: ${{ github.event.workflow_run.id }}Gotchas
- Trace after the run completes; steps that are still in progress have no end timestamp yet.
- The
workflow_runevent only fires for workflows on the default branch.