Skip to content

Fix OTel dev env port resolution and API key#2025

Open
wrn14897 wants to merge 3 commits intomainfrom
warren/fix-otel-dev-env-port-resolution
Open

Fix OTel dev env port resolution and API key#2025
wrn14897 wants to merge 3 commits intomainfrom
warren/fix-otel-dev-env-port-resolution

Conversation

@wrn14897
Copy link
Copy Markdown
Member

@wrn14897 wrn14897 commented Apr 1, 2026

Summary

  • Fix dotenv-expand infinite recursion caused by self-referential ${VAR:-default} patterns in .env files, which prevented OTEL_EXPORTER_OTLP_ENDPOINT from resolving to the isolated collector port
  • Set correct HYPERDX_API_KEY in app dev env so the collector accepts telemetry
  • Fix HDX_COLLECTOR_URL to fall back to OTEL_EXPORTER_OTLP_ENDPOINT for browser-side telemetry

Changes

Root .env

  • Replace self-referential HDX_DEV_* vars (e.g., HDX_DEV_OTEL_HTTP_PORT=${HDX_DEV_OTEL_HTTP_PORT:-4318}) with plain default values to prevent dotenv-expand recursion
  • Keep HYPERDX_* vars with ${VAR:-default} syntax to preserve existing override behavior

packages/app/.env.development

  • Set HYPERDX_API_KEY to super-secure-ingestion-api-key (matching the API/collector) instead of placeholder
  • Remove self-referential port declarations; ports now come from dev-env.sh exports or root .env defaults
  • Remove :-default syntax from ${HDX_DEV_OTEL_HTTP_PORT} reference

packages/api/.env.development

  • Remove self-referential port declarations (HYPERDX_API_PORT=${HYPERDX_API_PORT}, etc.) and redundant re-assignments (HYPERDX_API_KEY=${HYPERDX_API_KEY}, HYPERDX_LOG_LEVEL=${HYPERDX_LOG_LEVEL})
  • Remove :-default syntax from ${HDX_DEV_*} variable references

packages/app/src/config.ts

  • Add process.env.OTEL_EXPORTER_OTLP_ENDPOINT as fallback for HDX_COLLECTOR_URL so the browser OTel SDK picks up the correct collector endpoint from .env.development

Self-referential ${VAR:-default} patterns in .env files caused
dotenv-expand infinite recursion, preventing OTEL_EXPORTER_OTLP_ENDPOINT
from resolving to the isolated collector port. Also fix HDX_COLLECTOR_URL
to fall back to OTEL_EXPORTER_OTLP_ENDPOINT for browser-side telemetry,
and set the correct HYPERDX_API_KEY in the app dev env.
Keep ${VAR:-default} for HYPERDX_API_PORT, HYPERDX_APP_PORT, and
HYPERDX_OPAMP_PORT to avoid breaking existing consumers (docker-compose,
Makefile). Only HDX_DEV_* vars needed plain values to fix dotenv-expand
recursion.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

⚠️ No Changeset found

Latest commit: 681736e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperdx-oss Building Building Preview, Comment Apr 1, 2026 4:45pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Knip - Unused Code Analysis

⚪ No changes detected (1 issues on both main and PR)

What is this?

Knip finds unused files, dependencies, and exports in your codebase.
This comment compares the PR branch against main to detect regressions.

Run yarn knip locally to see full details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

PR Review

  • ⚠️ packages/api/.env.development line 1 has dead HYPERDX_API_KEY placeholderHYPERDX_API_KEY="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" is set at the top then immediately overridden at line 24 by HYPERDX_API_KEY=$INGESTION_API_KEY. Remove line 1 to avoid confusion.

  • ⚠️ packages/app/src/config.ts: process.env.OTEL_EXPORTER_OTLP_ENDPOINT fallback is server-side only — In Next.js, non-NEXT_PUBLIC_* env vars are not available in the browser bundle. HDX_COLLECTOR_URL appears to be used for client-side OTel export. The fallback will silently be undefined in the browser, falling through to the hardcoded http://localhost:4318 default. This is fine for dev but misleading — a comment clarifying it's a SSR/build-time fallback only would help. Not a blocker if the hardcoded default is acceptable.

  • ⚠️ .env hardcoded port defaults break override-before-load patterns — Changing HDX_DEV_MONGO_PORT=${HDX_DEV_MONGO_PORT:-27017} to HDX_DEV_MONGO_PORT=27017 means if dotenv loads this file in override mode (before dev-env.sh sets the vars), isolation ports get clobbered. This is the intentional fix for the dotenv-expand recursion, but verify dotenv is configured in non-override mode (or that dev-env.sh always runs before dotenv loads). If dotenv uses override mode anywhere, MONGO_URI and OTEL_EXPORTER_OTLP_ENDPOINT in packages/api/.env.development (which now use bare ${HDX_DEV_MONGO_PORT} without fallbacks) could expand to empty strings and produce malformed URIs like mongodb://localhost:/hyperdx.

✅ Core fix (self-referential dotenv-expand recursion) is correct. Shell script clone-dev-state.sh is well-written with proper safeguards.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

E2E Test Results

All tests passed • 122 passed • 3 skipped • 1091s

Status Count
✅ Passed 122
❌ Failed 0
⚠️ Flaky 4
⏭️ Skipped 3

Tests ran across 4 shards in parallel.

View full report →

Add wt project config and clone-dev-state.sh script so new worktrees
automatically inherit MongoDB data (accounts, teams, config) from the
primary worktree. This eliminates the need to re-register when spinning
up a new worktree.

- .config/wt.toml: pre-start hook clones MongoDB volume, post-start
  copies node_modules/.env.local and installs deps, post-remove tears
  down all Docker stacks for the slot
- scripts/clone-dev-state.sh: copies db_dev_<slot> with proper slot
  renaming, supports --force, warns if source stack is running
- .worktreeinclude: limits wt step copy-ignored to node_modules and
  .env.local (excludes .volumes which needs slot renaming)
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.

1 participant