fix(probe): use protocol-aware default port for endpoint probing#4
fix(probe): use protocol-aware default port for endpoint probing#4John-Lin wants to merge 1 commit intoDEVtheOPS:mainfrom
Conversation
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan for PR comments
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/probe.ts (1)
6-18:⚠️ Potential issue | 🟡 MinorJSDoc comment is misplaced.
The JSDoc at lines 6-9 describes
probeEndpoint("Opens a TCP connection...") but is positioned directly aboveparseEndpoint. Move this comment to directly precedeprobeEndpoint, and consider adding a separate JSDoc forparseEndpoint.📝 Proposed fix
-/** Result of a TCP connectivity probe against the OTLP endpoint. */ -export type ProbeResult = { ok: boolean; ms: number; error?: string } - -/** - * Opens a TCP connection to the host and port parsed from `endpoint` to verify - * reachability before the OTel SDK initialises. Resolves within 5 seconds. - */ -export function parseEndpoint(endpoint: string): { host: string; port: number } | null { +/** Result of a TCP connectivity probe against the OTLP endpoint. */ +export type ProbeResult = { ok: boolean; ms: number; error?: string } + +/** Parses an endpoint URL and returns the host and port, applying protocol-aware defaults. */ +export function parseEndpoint(endpoint: string): { host: string; port: number } | null { try { const url = new URL(endpoint) const defaultPort = url.protocol === "http:" ? 80 : url.protocol === "https:" ? 443 : 4317 return { host: url.hostname, port: url.port ? parseInt(url.port, 10) : defaultPort } } catch { return null } } + +/** + * Opens a TCP connection to the host and port parsed from `endpoint` to verify + * reachability before the OTel SDK initialises. Resolves within 5 seconds. + */ +export function probeEndpoint(endpoint: string): Promise<ProbeResult> {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/probe.ts` around lines 6 - 18, Move the misplaced JSDoc that currently precedes parseEndpoint so it directly precedes probeEndpoint (the comment about opening a TCP connection and 5s timeout belongs to probeEndpoint), and add a short JSDoc above parseEndpoint describing its purpose and return value (parses an endpoint string into host and numeric port or returns null). Ensure the comment text matches the functions: keep the TCP/reachability text with probeEndpoint and a concise parse description for parseEndpoint.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/probe.ts`:
- Around line 6-18: Move the misplaced JSDoc that currently precedes
parseEndpoint so it directly precedes probeEndpoint (the comment about opening a
TCP connection and 5s timeout belongs to probeEndpoint), and add a short JSDoc
above parseEndpoint describing its purpose and return value (parses an endpoint
string into host and numeric port or returns null). Ensure the comment text
matches the functions: keep the TCP/reachability text with probeEndpoint and a
concise parse description for parseEndpoint.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 63d1f8fa-4119-46af-82e4-46f68475640b
📒 Files selected for processing (2)
src/probe.tstests/probe.test.ts
fix #3
Previously the probe always fell back to port 4317 when no explicit port was provided, even for http:// (80) and https:// (443) URLs. This caused the probe to check a different port than the OTel SDK would actually connect to. Extract parseEndpoint to make the parsing logic independently testable.
See also https://opentelemetry.io/docs/specs/otel/protocol/exporter/#endpoint-urls-for-otlphttp
Summary by CodeRabbit
New Features
Refactor