[Repo Assist] fix(cmd): apply OTEL_SERVICE_NAME env var override to tracing config#6344
Merged
lpcox merged 3 commits intoMay 23, 2026
Merged
Conversation
When OTEL_EXPORTER_OTLP_ENDPOINT is set in the environment, the otlp-endpoint flag correctly propagates that value into the tracing config via the 'otlpEndpoint != ""' check. However, OTEL_SERVICE_NAME was only applied when --otlp-service-name was explicitly passed on the CLI (cmd.Flags().Changed), meaning the env var was silently ignored. Fix: use applyFlagOrEnv for both otlp-endpoint and otlp-service-name, consistent with the payload flags (lines 256-258). Pre-fetch the TracingConfig pointer once to avoid repeated ensureTracingConfig calls. Add two new tests in flags_tracing_test.go: - TestApplyTracingFlags_ServiceNameEnvVar: OTEL_SERVICE_NAME overrides config - TestApplyTracingFlags_ServiceNameDefaultDoesNotOverrideConfig: TOML config is preserved when neither env var nor CLI flag is set Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the gateway CLI config merge where OTEL_SERVICE_NAME (picked up via the --otlp-service-name flag default) was not being written into cfg.Gateway.Tracing.ServiceName unless the CLI flag was explicitly passed, causing tracing to fall back to config.DefaultTracingServiceName even when the env var was set.
Changes:
- Update tracing flag application in
internal/cmd/root.goto useapplyFlagOrEnvforotlp-service-name(and refactor to reuse a single tracing config pointer). - Add tests to verify
OTEL_SERVICE_NAMEpropagates into config when the flag is not explicitly set, and that defaults do not overwrite an existing config value.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/root.go | Uses applyFlagOrEnv to correctly apply env-var overrides to tracing config (service name). |
| internal/cmd/flags_tracing_test.go | Adds regression tests covering env-var override propagation and default non-overwrite behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Problem
OTEL_SERVICE_NAMEenvironment variable was silently ignored when configuring the OTLP tracing service name.Root cause
In
internal/cmd/root.go, the three tracing flags were applied inconsistently:When
OTEL_SERVICE_NAME=my-serviceis set in the environment,otlpServiceNamepicks up the value via the flag's default (envutil.GetEnvString("OTEL_SERVICE_NAME", ...)), butcmd.Flags().Changed("otlp-service-name")isfalsesince no explicit CLI flag was passed. The env var value was therefore never written to the config, andresolveServiceNamefell back to"mcp-gateway".The config documentation explicitly states
OTEL_SERVICE_NAME — overrides ServiceName, so this is a bug.Fix
Use
applyFlagOrEnvfor bothotlp-endpointandotlp-service-name, consistent with the payload flag block (lines 256–258). Pre-fetch theTracingConfigpointer once to avoid repeatedensureTracingConfig(cfg)calls:otlp-sample-rateretains theChanged-only check since it has no env var override.Tests added
Two new tests in
internal/cmd/flags_tracing_test.go:TestApplyTracingFlags_ServiceNameEnvVar— verifiesOTEL_SERVICE_NAMEpropagates to tracing config when flag is not explicitly setTestApplyTracingFlags_ServiceNameDefaultDoesNotOverrideConfig— verifies TOML config service name is preserved when env var is unset and flag is unchangedTest Status
go.mod). Build and tests could not be executed locally. The changes are syntactically verified; the logic follows the same pattern as the existingapplyFlagOrEnvcalls on lines 256–258 which are already covered by passing tests.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.