Skip to content

fix: respect user-defined OTEL_SERVICE_NAME when OTLP observability is enabled#46779

Merged
pelikhan merged 3 commits into
mainfrom
copilot/override-otel-service-name
Jul 20, 2026
Merged

fix: respect user-defined OTEL_SERVICE_NAME when OTLP observability is enabled#46779
pelikhan merged 3 commits into
mainfrom
copilot/override-otel-service-name

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

When a user sets OTEL_SERVICE_NAME in their workflow env: block alongside observability.otlp, the compiler unconditionally appended its own OTEL_SERVICE_NAME entry, producing a duplicate YAML key and failing compilation.

Changes

  • pkg/workflow/observability_otlp.go: Skip injecting OTEL_SERVICE_NAME when the key is already present in workflowData.Env. Detection uses a compiled multiline regex ((?m)^\s*OTEL_SERVICE_NAME:) anchored to line-start to avoid false positives from comments or values that happen to contain the key name.
  • pkg/workflow/observability_otlp_test.go: New test case asserting that a user-defined OTEL_SERVICE_NAME is preserved verbatim and appears exactly once after injection.

Example

Previously this workflow would fail to compile:

observability:
  otlp:
    endpoint:
      - url: ${{ secrets.GH_AW_OTEL_ENDPOINT }}
env:
  OTEL_SERVICE_NAME: my-service   # ← compiler added a second copy → duplicate key error

After this change the user-supplied value is honoured and no duplicate is emitted.

Copilot AI and others added 2 commits July 20, 2026 09:30
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to override OTEL_SERVICE_NAME in observability fix: respect user-defined OTEL_SERVICE_NAME when OTLP observability is enabled Jul 20, 2026
Copilot AI requested a review from pelikhan July 20, 2026 09:39
@pelikhan
pelikhan marked this pull request as ready for review July 20, 2026 09:41
Copilot AI review requested due to automatic review settings July 20, 2026 09:41
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #46779 does not have the 'implementation' label and has only 26 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Prevents duplicate OTEL_SERVICE_NAME keys when OTLP observability is enabled.

Changes:

  • Preserves user-defined service names.
  • Adds regression coverage for duplicate-key prevention.
Show a summary per file
File Description
pkg/workflow/observability_otlp.go Conditionally injects the service name.
pkg/workflow/observability_otlp_test.go Tests user-defined service-name preservation.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium


var sentryEndpointExpressionPattern = regexp.MustCompile(`(?i)^\$\{\{\s*secrets\.` + regexp.QuoteMeta(constants.OTELSentryEndpointSecretName) + `\s*\}\}$`)
var otlpResourceAttributeSecretRefPattern = regexp.MustCompile(`\$\{\{\s*(secrets|vars)\.`)
var otelServiceNameKeyPattern = regexp.MustCompile(`(?m)^\s*OTEL_SERVICE_NAME:`)
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix is correct and well-scoped. The multiline regex (?m)^\s*OTEL_SERVICE_NAME: reliably detects an existing user-defined key (comment lines beginning with # are not matched since # is not \s). The new test case covers preservation of user-defined values and the no-duplicate invariant. No blocking issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 14 AIC · ⌖ 4.31 AIC · ⊞ 5K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — approving with one minor test-coverage suggestion.

📋 Key Themes & Highlights

Findings

  • The test asserts the user value is preserved and not duplicated ✅ — but does not assert OTEL_RESOURCE_ATTRIBUTES is still injected in the same code path (see inline comment)

Positive Highlights

  • ✅ Root cause is properly addressed: duplicate key avoided by checking before injecting, not patching after
  • ✅ Regex (?m)^\s*OTEL_SERVICE_NAME: correctly ignores commented-out keys and value occurrences
  • ✅ Regression test is well-structured and readable
  • ✅ Minimal, surgical change — no collateral modifications

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 16.7 AIC · ⌖ 4.47 AIC · ⊞ 6.7K
Comment /matt to run again

assert.Equal(t, 1, strings.Count(wd.Env, "OTEL_SERVICE_NAME:"), "OTEL_SERVICE_NAME should appear exactly once")
assert.Contains(t, wd.Env, "OTEL_EXPORTER_OTLP_ENDPOINT: https://traces.example.com", "endpoint should still be injected")
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] The test verifies OTEL_SERVICE_NAME is preserved and not duplicated, but doesn't assert that OTEL_RESOURCE_ATTRIBUTES is still injected when the user supplies their own service name.

💡 Suggested addition
assert.Contains(t, wd.Env, "OTEL_RESOURCE_ATTRIBUTES:", "resource attributes should still be injected when user defines OTEL_SERVICE_NAME")

This guards against a future regression where skipping OTEL_SERVICE_NAME injection accidentally skips the OTEL_RESOURCE_ATTRIBUTES line too. The current code is correct, but a test assertion makes the invariant explicit.

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 85/100 — Excellent

Analyzed 1 test(s): 1 design, 0 implementation, 0 violation(s).

📊 Metrics (1 test)
Metric Value
Analyzed 1 (Go: 1, JS: 0)
✅ Design 1 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 1 (100%)
Duplicate clusters 0
Inflation No (1.89:1 ratio)
🚨 Violations 0
Test File Classification Assessment
preserves user-defined OTEL_SERVICE_NAME and does not inject duplicate observability_otlp_test.go:588 design_test Tests critical behavior: prevents YAML key duplication when user defines OTEL_SERVICE_NAME. Three assertions with descriptive failure messages verify: value preservation, no-duplicate constraint, and endpoint injection. Covers valid edge case (pre-existing user value).

Verdict

Passed. 0% implementation tests (threshold: 30%). No violations detected.

Quality notes:

  • Single well-focused test covering an important fix (user-defined OTEL_SERVICE_NAME respect)
  • Proper build tag present (//go:build !integration)
  • Assertions have descriptive context
  • Test inflation ratio 1.89:1 is acceptable
  • No mock libraries used; straightforward function-behavior verification

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🧪 Test quality analysis by Test Quality Sentinel · 13 AIC · ⌖ 9.56 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 85/100. 0% implementation tests (threshold: 30%). Single well-focused design test covering critical YAML key deduplication behavior with proper edge-case coverage and descriptive assertions.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested — one medium-severity correctness issue must be addressed

The fix is sound in intent, but the regex-based detection method has a correctness gap.

Blocking issue summary

The pattern (?m)^\s*OTEL_SERVICE_NAME: is too broad — it matches any line beginning with optional whitespace followed by that key, including lines embedded inside YAML block scalar values. A user env block like:

env:
  SOME_TEMPLATE: |
    OTEL_SERVICE_NAME: placeholder

would silently suppress injection of the real OTEL_SERVICE_NAME mapping key, leaving telemetry un-tagged with no error or warning. The test covers only the straightforward case and misses this edge.

Minimum fix: tighten the pattern to (?m)^ OTEL_SERVICE_NAME: (exactly two leading spaces matching the env block indentation convention). Preferred fix: parse the env block as YAML and check keys structurally.

🔎 Code quality review by PR Code Quality Reviewer · 47.1 AIC · ⌖ 4.67 AIC · ⊞ 5.6K
Comment /review to run again

Comments that could not be inline-anchored

pkg/workflow/observability_otlp.go:9

False-positive risk: regex fires inside YAML multiline string values, not just mapping keys.

<details>
<summary>💡 Details and suggested fix</summary>

The pattern (?m)^\s*OTEL_SERVICE_NAME: uses multiline mode, meaning ^ matches the start of any embedded line — including lines inside block scalar values. For example, this env block would incorrectly suppress injection:

env:
  SOME_TEMPLATE: |
    OTEL_SERVICE_NAME: placeholder

The match would fire on the indented `OTEL_S…

pkg/workflow/observability_otlp.go:22

Printf with no format arguments — use Print to avoid accidental misinterpretation of % characters.

<details>
<summary>💡 Suggested fix</summary>

// before
otlpLog.Printf(&quot;Skipping OTEL_SERVICE_NAME injection: already defined by user&quot;)

// after
otlpLog.Print(&quot;Skipping OTEL_SERVICE_NAME injection: already defined by user&quot;)

Using Printf with a string that contains no format verbs compiles today but is a latent bug: if the message is ever extended to interpolate e.g. `serviceN…

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add a fallback env var with the expression that can be used in JavaScript if the model expression resolves to empty. That way it handles any syntax.

@github-actions

Copy link
Copy Markdown
Contributor

Great work! 🎯 This fix elegantly solves the duplicate OTEL_SERVICE_NAME key problem by detecting when users define their own service name and skipping injection. The regex-based detection is robust against false positives, and the test case thoroughly validates the fix.

Key strengths:

This PR is ready for review and merge!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • patchdiff.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by ✅ Contribution Check · 64.1 AIC · ⌖ 8.09 AIC · ⊞ 6.2K ·

@pelikhan
pelikhan merged commit a751a5a into main Jul 20, 2026
69 of 81 checks passed
@pelikhan
pelikhan deleted the copilot/override-otel-service-name branch July 20, 2026 09:54
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.14

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.

Feature Request: override OTEL_SERVICE_NAME when using the observability feature

3 participants