Skip to content

Add github.ref_name and github.head_ref to OTLP span resource attributes#27903

Merged
pelikhan merged 4 commits intomainfrom
copilot/otel-advisor-add-github-ref-name
Apr 22, 2026
Merged

Add github.ref_name and github.head_ref to OTLP span resource attributes#27903
pelikhan merged 4 commits intomainfrom
copilot/otel-advisor-add-github-ref-name

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

Current OTLP spans only expose github.ref (full ref path), which makes branch-level filtering/grouping difficult in common observability UIs. This change adds first-class short ref/source-branch attributes so spans can be queried directly by branch semantics.

  • Telemetry resource attributes

    • Updated actions/setup/js/send_otlp_span.cjs to read and emit:
      • GITHUB_REF_NAMEgithub.ref_name
      • GITHUB_HEAD_REFgithub.head_ref
    • Applied in both span emitters:
      • sendJobSetupSpan
      • sendJobConclusionSpan
    • Existing github.ref behavior is preserved.
  • Test coverage for new attributes

    • Extended actions/setup/js/send_otlp_span.test.cjs for both setup/conclusion paths to verify:
      • attributes are included when env vars are present
      • attributes are omitted when env vars are absent
    • Added env cleanup keys for GITHUB_REF_NAME and GITHUB_HEAD_REF to keep test isolation consistent.
const ref = process.env.GITHUB_REF || "";
const refName = process.env.GITHUB_REF_NAME || "";
const headRef = process.env.GITHUB_HEAD_REF || "";

if (ref) resourceAttributes.push(buildAttr("github.ref", ref));
if (refName) resourceAttributes.push(buildAttr("github.ref_name", refName));
if (headRef) resourceAttributes.push(buildAttr("github.head_ref", headRef));

Copilot AI changed the title [WIP] Add github.ref_name to span resource attributes Add github.ref_name and github.head_ref to OTLP span resource attributes Apr 22, 2026
Copilot AI requested a review from pelikhan April 22, 2026 21:51
@github-actions github-actions Bot mentioned this pull request Apr 22, 2026
@pelikhan pelikhan marked this pull request as ready for review April 22, 2026 22:52
Copilot AI review requested due to automatic review settings April 22, 2026 22:52
@pelikhan pelikhan merged commit be3b09c into main Apr 22, 2026
9 checks passed
@pelikhan pelikhan deleted the copilot/otel-advisor-add-github-ref-name branch April 22, 2026 22:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds short GitHub ref metadata to OTLP span resource attributes so traces can be filtered/grouped by branch semantics (e.g., main, PR head branch) without parsing github.ref.

Changes:

  • Emit github.ref_name from GITHUB_REF_NAME and github.head_ref from GITHUB_HEAD_REF in both job setup and job conclusion OTLP payloads.
  • Extend unit tests to assert presence/absence of the new resource attributes and ensure env var cleanup includes the new keys.
Show a summary per file
File Description
actions/setup/js/send_otlp_span.cjs Adds github.ref_name / github.head_ref resource attributes sourced from GITHUB_REF_NAME / GITHUB_HEAD_REF for setup and conclusion spans.
actions/setup/js/send_otlp_span.test.cjs Adds tests for inclusion/omission of the new resource attributes and updates env var cleanup lists.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

actions/setup/js/send_otlp_span.cjs:706

  • The sendJobConclusionSpan JSDoc lists the environment variables consumed, but it doesn’t include the newly added GITHUB_REF_NAME / GITHUB_HEAD_REF inputs. Please update the doc comment to reflect these additional env vars.
  const refName = process.env.GITHUB_REF_NAME || "";
  const headRef = process.env.GITHUB_HEAD_REF || "";
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +495 to +496
const refName = process.env.GITHUB_REF_NAME || "";
const headRef = process.env.GITHUB_HEAD_REF || "";
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sendJobSetupSpan JSDoc lists the environment variables consumed, but it doesn’t mention the newly added GITHUB_REF_NAME / GITHUB_HEAD_REF inputs. Please update the doc comment so it stays accurate for users debugging or integrating this script.

This issue also appears on line 705 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines 524 to +532
if (ref) {
resourceAttributes.push(buildAttr("github.ref", ref));
}
if (refName) {
resourceAttributes.push(buildAttr("github.ref_name", refName));
}
if (headRef) {
resourceAttributes.push(buildAttr("github.head_ref", headRef));
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resource attribute construction is now duplicated in both sendJobSetupSpan and sendJobConclusionSpan (including the new ref_name/head_ref additions). Consider extracting this into a shared helper to reduce the risk of the two code paths drifting over time when new GitHub resource attributes are added.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 75/100

⚠️ Acceptable — minor suggestions below

Metric Value
New/modified tests analyzed 4
✅ Design tests (behavioral contracts) 4 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 2 (50%)
Duplicate test clusters 0
Test inflation detected ✅ Yes — 66 test lines added vs. 16 production lines (4.1:1 ratio, threshold: 2:1)
🚨 Coding-guideline violations None

Test Classification Details

Test File Classification Issues Detected
"includes github.ref_name and github.head_ref as resource attributes when set" (Setup) send_otlp_span.test.cjs:1216 ✅ Design None — verifies OTLP payload content
"omits github.ref_name and github.head_ref resource attributes when not set" (Setup) send_otlp_span.test.cjs:1246 ✅ Design None — covers absent-env-var edge case
"includes github.ref_name and github.head_ref as resource attributes when set" (Conclusion) send_otlp_span.test.cjs:2011 ✅ Design None — verifies OTLP payload content
"omits github.ref_name and github.head_ref resource attributes when not set" (Conclusion) send_otlp_span.test.cjs:2041 ✅ Design None — covers absent-env-var edge case

Test Inflation Note

The test file added 66 lines versus 16 production lines (4.1:1). In this case the inflation is not a quality concern — each new attribute (github.ref_name, github.head_ref) is covered with both a positive test and a negative test across both public functions (sendJobSetupSpan and sendJobConclusionSpan). That results in 4 tests × ~16 lines each, which is appropriate coverage. The 2:1 threshold rule triggered here, but the tests themselves are well-structured and non-redundant.

One minor suggestion: the positive tests (present-when-set) could be made slightly more robust by also asserting that only one entry per key is present (no duplicates), e.g. expect(resourceAttrs.filter(a => a.key === "github.ref_name")).toHaveLength(1). Not required for this PR.


Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): 0 tests
  • 🟨 JavaScript (*.test.cjs, *.test.js): 4 tests (vitest)

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%). All 4 new tests verify observable OTLP wire-format output — they enforce the behavioral contract that github.ref_name and github.head_ref are included (or absent) in span resource attributes based on environment variables.


📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct
  • Give false assurance: they pass even when the system is wrong

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.


References: §24806787562

🧪 Test quality analysis by Test Quality Sentinel · ● 1M ·

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Test Quality Sentinel: 75/100. Test quality is acceptable — 0% of new tests are implementation tests (threshold: 30%). All 4 new tests verify observable OTLP payload content, covering both the positive case (attributes present when env vars set) and the negative case (attributes absent when env vars not set) for both sendJobSetupSpan and sendJobConclusionSpan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[otel-advisor] add github.ref_name to span resource attributes for branch-level filtering

3 participants