fix(agentex): build valid OTLP metrics URLs#346
Merged
Conversation
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.
Summary
DD_AGENT_HOSTvalues likelocalhost, service names, and IPv4 literalsCloses #313. Supersedes stale external PR #323 with the same underlying fix on a fresh branch.
Tests
uv run ruff check agentex/src/temporal/run_worker.py agentex/tests/unit/temporal/test_run_worker_metrics_url.pyuv run --package agentex-backend --group test pytest agentex/tests/unit/temporal/test_run_worker_metrics_url.py -m unit -quv run --package agentex-backend --group test pytest agentex/tests/unit/temporal -m unit -qtemporalio 1.23.0: oldhttp://[{DD_AGENT_HOST}]:4317URLs rejectlocalhost,datadog-agent, and10.0.0.5withInvalid OTel URL: invalid IPv6 address;build_metrics_url(...)outputs are accepted byRuntime(telemetry=TelemetryConfig(metrics=OpenTelemetryConfig(url=...))).Greptile Summary
Fixes the OTLP metrics URL construction for Temporal workers by replacing the broken
http://[{DD_AGENT_HOST}]:4317string interpolation with a dedicatedbuild_metrics_urlfunction that correctly handles all commonDD_AGENT_HOSTshapes and adds focused unit tests for each case.build_metrics_urlcorrectly handles plain hostnames, IPv4 literals, bare IPv6 addresses (brackets them), pre-bracketed IPv6 (including the previously-identified empty-trailing-port edge case"[::1]:", now covered by a test), and explicit ports for all host types."["but has no closing"]"bypasses the inner parsing block and is then double-bracketed by the final colon-presence check, producing an invalid URL likehttp://[[::1]:4317.Confidence Score: 5/5
Safe to merge — the fix correctly resolves the invalid IPv6-bracket wrapping for all realistic DD_AGENT_HOST values and is well-covered by the new unit tests.
The core bug (wrapping every host in IPv6 brackets) is definitively fixed and tested across all meaningful host shapes. The one unguarded path — a malformed input that begins with an unclosed bracket — is an unrealistic operator configuration and does not affect production behaviour.
No files require special attention; the logic in run_worker.py is straightforward and the test file covers all realistic cases.
Important Files Changed
http://[{DD_AGENT_HOST}]:4317template withbuild_metrics_url, correctly handling plain hostnames, IPv4, bare IPv6 (brackets them), pre-bracketed IPv6 (strips and re-brackets), and explicit ports. One edge case remains: a malformed input like"[::1"(missing closing bracket) bypasses the inner block and then gets double-bracketed by the trailing guard, producing an invalid URL."[::1]:"empty-port case), and explicit-port variants. No tests for the malformed"[::1"(missing closing bracket) case.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[build_metrics_url] --> B{host_url falsy?} B -- Yes --> C[return None] B -- No --> D[host = host_url.strip] D --> E{host empty?} E -- Yes --> C E -- No --> F[port = 4317 default] F --> G{host starts with bracket?} G -- Yes --> H[find closing bracket] H --> I{bracket found?} I -- Yes --> J[parse rest after bracket] J --> K{rest starts with colon?} K -- Yes --> L[port = rest after colon or default] K -- No --> M[port stays default] L --> N[host = inner IPv6 address] M --> N I -- No --> O[host unchanged with leading bracket - BUG PATH] G -- No --> P{exactly one colon in host?} P -- Yes --> Q[split host and port] P -- No --> R[host unchanged] Q --> S{colon in host?} N --> S O --> S R --> S S -- Yes --> T[wrap host in brackets] S -- No --> U[return http://host:port] T --> U%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[build_metrics_url] --> B{host_url falsy?} B -- Yes --> C[return None] B -- No --> D[host = host_url.strip] D --> E{host empty?} E -- Yes --> C E -- No --> F[port = 4317 default] F --> G{host starts with bracket?} G -- Yes --> H[find closing bracket] H --> I{bracket found?} I -- Yes --> J[parse rest after bracket] J --> K{rest starts with colon?} K -- Yes --> L[port = rest after colon or default] K -- No --> M[port stays default] L --> N[host = inner IPv6 address] M --> N I -- No --> O[host unchanged with leading bracket - BUG PATH] G -- No --> P{exactly one colon in host?} P -- Yes --> Q[split host and port] P -- No --> R[host unchanged] Q --> S{colon in host?} N --> S O --> S R --> S S -- Yes --> T[wrap host in brackets] S -- No --> U[return http://host:port] T --> UReviews (2): Last reviewed commit: "fix(agentex): default empty OTLP metrics..." | Re-trigger Greptile