Skip to content

Commit e0cc628

Browse files
authored
Merge pull request #322 from gitpod-io/wv/add-github-head-ref-to-otel
Add GITHUB_HEAD_REF to OTEL tracing attributes
2 parents 326bef4 + f61011c commit e0cc628

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/leeway/reporter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,9 @@ func (r *OTelReporter) addGitHubAttributes(span trace.Span) {
930930
if val := os.Getenv("GITHUB_REF"); val != "" {
931931
span.SetAttributes(attribute.String("github.ref", val))
932932
}
933+
if val := os.Getenv("GITHUB_HEAD_REF"); val != "" {
934+
span.SetAttributes(attribute.String("github.head_ref", val))
935+
}
933936
if val := os.Getenv("GITHUB_SHA"); val != "" {
934937
span.SetAttributes(attribute.String("github.sha", val))
935938
}

pkg/leeway/reporter_otel_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ func TestOTelReporter_GitHubAttributes(t *testing.T) {
389389
_ = os.Setenv("GITHUB_JOB", "test-job")
390390
_ = os.Setenv("GITHUB_ACTOR", "test-user")
391391
_ = os.Setenv("GITHUB_REPOSITORY", "test-org/test-repo")
392-
_ = os.Setenv("GITHUB_REF", "refs/heads/main")
392+
_ = os.Setenv("GITHUB_REF", "refs/pull/123/merge")
393+
_ = os.Setenv("GITHUB_HEAD_REF", "feature-branch")
393394
_ = os.Setenv("GITHUB_SHA", "abc123def456")
394395
_ = os.Setenv("GITHUB_SERVER_URL", "https://github.com")
395396
_ = os.Setenv("GITHUB_WORKFLOW_REF", "test-org/test-repo/.github/workflows/test.yml@refs/heads/main")
@@ -453,7 +454,8 @@ func TestOTelReporter_GitHubAttributes(t *testing.T) {
453454
"github.job": "test-job",
454455
"github.actor": "test-user",
455456
"github.repository": "test-org/test-repo",
456-
"github.ref": "refs/heads/main",
457+
"github.ref": "refs/pull/123/merge",
458+
"github.head_ref": "feature-branch",
457459
"github.sha": "abc123def456",
458460
"github.server_url": "https://github.com",
459461
"github.workflow_ref": "test-org/test-repo/.github/workflows/test.yml@refs/heads/main",

0 commit comments

Comments
 (0)