Skip to content

refactor: use pickEnvVars for OTEL environment variable forwarding#3752

Merged
lpcox merged 1 commit into
mainfrom
fix/otel-env-use-pickEnvVars
May 25, 2026
Merged

refactor: use pickEnvVars for OTEL environment variable forwarding#3752
lpcox merged 1 commit into
mainfrom
fix/otel-env-use-pickEnvVars

Conversation

@lpcox

@lpcox lpcox commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace verbose ...(process.env.X && { X: process.env.X }) patterns for OTEL/trace environment variables with the existing pickEnvVars() helper.

This reduces 12 lines of repetitive conditional spreads to a single 5-line pickEnvVars() call while preserving identical semantics (only set vars are forwarded).

Verification

  • tsc --noEmit passes
  • All 112 api-proxy-service tests pass

Closes #3612

Replace verbose spread-operator patterns for OTEL/trace env vars
with the existing pickEnvVars() helper in api-proxy-service.ts.

Before (12 lines):
  ...(process.env.OTEL_EXPORTER_OTLP_ENDPOINT && { ... }),
  ...(process.env.OTEL_EXPORTER_OTLP_HEADERS && { ... }),
  ...(process.env.GITHUB_AW_OTEL_TRACE_ID && { ... }),
  ...(process.env.GITHUB_AW_OTEL_PARENT_SPAN_ID && { ... }),

After (5 lines):
  ...pickEnvVars('OTEL_EXPORTER_OTLP_ENDPOINT', 'OTEL_EXPORTER_OTLP_HEADERS',
    'GITHUB_AW_OTEL_TRACE_ID', 'GITHUB_AW_OTEL_PARENT_SPAN_ID'),

Closes #3612

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

This PR refactors OpenTelemetry (OTEL) / tracing environment variable forwarding in buildApiProxyService to use the existing pickEnvVars() helper, replacing repetitive conditional spread patterns while preserving the same “only forward non-empty env vars” semantics.

Changes:

  • Replaces multiple ...(process.env.X && { X: process.env.X }) spreads with a single ...pickEnvVars(...) call for OTEL/trace-related variables.
  • Keeps OTEL_SERVICE_NAME behavior unchanged (still defaults to awf-api-proxy when unset).
Show a summary per file
File Description
src/services/api-proxy-service.ts Uses pickEnvVars() to forward OTEL/trace env vars into the api-proxy container environment, reducing duplication without changing behavior.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.36% 96.41% 📈 +0.05%
Statements 96.21% 96.25% 📈 +0.04%
Functions 97.98% 97.98% ➡️ +0.00%
Branches 90.50% 90.67% 📈 +0.17%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/config-writer.ts 83.9% → 85.5% (+1.61%) 83.9% → 85.5% (+1.61%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

Status: PASS — All smoke test checks passed.

💥 [THE END] — Illustrated by Smoke Claude

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

GitHub MCP: Retrieved PR #3704 "Reduce Documentation Maintainer workflow prompt/tool overhead"
File Write/Read: Test file not found at expected path
GitHub.com HTTP: Pre-step data missing (HTTP code not provided)
BYOK Inference: Successfully responding via api-proxy → api.githubcopilot.com

Mode: BYOK offline (COPILOT_OFFLINE=true) via api-proxy sidecar
Status: PARTIAL PASS (2/4 tests passed)
Author: @lpcox | Assignees: None

Note: File and HTTP test data from pre-step appears to be missing from workflow context.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

✅ GitHub MCP: Fetched PR #3704 "Reduce Documentation Maintainer workflow prompt/tool overhead"
❌ File Test: /tmp/smoke-test-copilot.txt not found
⚠️ GitHub.com: HTTP code not provided (pre-step variable missing)

Status: FAIL (1 test failed, 1 inconclusive)

cc: @lpcox

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke test: FAIL
✅ Merged PRs: Reduce Documentation Maintainer workflow prompt/tool overhead; refactor(api-proxy): extract nested callbacks from proxyRequest into focused module-level functions
❌ Safeinputs GH: unavailable; gh returned PR titles
✅ Playwright: GitHub title verified
❌ Tavily: search tool unavailable
✅ File/bash, discussion comment, build: passed
Overall status: FAIL

Warning

Firewall blocked 1 domain

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

  • registry.npmjs.org

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

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: API Proxy OpenTelemetry Tracing

✅ Scenario 1: Module Loading

Status: PASS
The otel.js module loads successfully and exports all expected functions: startRequestSpan, setTokenAttributes, endSpan, endSpanError, shutdown, isEnabled.

✅ Scenario 2: Test Suite

Status: PASS
All 32 OTEL tests pass:

  • Module initialization (2 tests)
  • OTLP header parsing (5 tests)
  • Span creation with attributes (4 tests)
  • Token usage tracking (3 tests)
  • Span status handling (6 tests)
  • OTLP/JSON serialization (1 test)
  • ProxyAwareOtlpExporter (7 tests)
  • FileSpanExporter (2 tests)
  • Shutdown (2 tests)

✅ Scenario 3: Env Var Forwarding

Status: PASS
The refactored code in src/services/api-proxy-service.ts correctly uses pickEnvVars() to forward OTEL environment variables:

  • OTEL_EXPORTER_OTLP_ENDPOINT
  • OTEL_EXPORTER_OTLP_HEADERS
  • GITHUB_AW_OTEL_TRACE_ID
  • GITHUB_AW_OTEL_PARENT_SPAN_ID
  • OTEL_SERVICE_NAME

✅ Scenario 4: Token Tracker Integration

Status: PASS
The onUsage callback exists in proxy-request.js at line 492, providing the integration hook for OTEL token tracking.

✅ Scenario 5: OTEL Diagnostics

Status: PASS (Expected Development State)
No OTLP export observed during this test run — expected behavior when OTEL_EXPORTER_OTLP_ENDPOINT is not configured. The system gracefully falls back to file-based logging.


Summary

Result: ✅ All scenarios pass

The PR successfully refactors OTEL environment variable forwarding from verbose conditional spreads to the cleaner pickEnvVars() helper while maintaining full functionality. All 32 OTEL unit tests pass, confirming:

  1. Module loads and initializes correctly
  2. Span creation with GenAI semantic conventions works
  3. Token usage attributes are tracked
  4. Parent context propagation is functional
  5. Both OTLP export and file fallback are implemented
  6. Graceful degradation when OTEL is unconfigured

The refactoring reduces code from 12 lines to 5 lines with identical semantics.

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • 127.0.0.1
  • api.example.com
  • api.openai.com

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

network:
  allowed:
    - defaults
    - "127.0.0.1"
    - "api.example.com"
    - "api.openai.com"

See Network Configuration for more information.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Gemini Smoke Test Results

  • GitHub MCP: ❌ (mcpscripts missing)
  • Connectivity: ❌ (Squid 400 Bad Request)
  • File Writing: ✅
  • Bash Tool: ✅

Overall status: FAIL

Warning

Firewall blocked 1 domain

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

  • localhost

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

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions

Copy link
Copy Markdown
Contributor

Service Connectivity Results

❌ Redis: TIMEOUT/FAIL
❌ PostgreSQL (pg_isready): no response
❌ PostgreSQL (SELECT): not tested (pg_isready failed)

Overall: FAIL - Services not reachable via host.docker.internal

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx 1/1 passed ✅ PASS
Node.js execa 1/1 passed ✅ PASS
Node.js p-limit 1/1 passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

All build and test operations completed successfully across all ecosystems.

Generated by Build Test Suite for issue #3752 · ● 12.1M ·

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

The chroot environment version tests have completed with some mismatches:

Runtime Host Version Chroot Version Match?
Python 3.12.13 3.12.3 ❌ NO
Node.js v24.15.0 v22.22.3 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Summary

  • Python: Minor version mismatch (3.12.13 vs 3.12.3)
  • Node.js: Major version mismatch (v24 vs v22)
  • Go: Version match ✓

Overall Result: ⚠️ Not all tests passed

The smoke-chroot label will not be added due to version mismatches.

Tested by Smoke Chroot

@lpcox lpcox merged commit 49cfed7 into main May 25, 2026
68 of 69 checks passed
@lpcox lpcox deleted the fix/otel-env-use-pickEnvVars branch May 25, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Duplicate Code] OTEL environment variable forwarding not using pickEnvVars helper

2 participants