feat(http): add client instrumentation and metrics - #2219
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
933c19b to
b77d54f
Compare
Greptile SummaryThe PR adds optional tracing and request-duration metrics around the shared HTTP client while preserving the existing request and ownership contracts.
|
| Filename | Overview |
|---|---|
| nemoguardrails/http/instrumented.py | Adds the instrumentation decorator and correctly fixes both previously reported close-state and concurrent-close failures by locking cleanup and marking closure only after success. |
| nemoguardrails/http/telemetry.py | Adds isolated tracing and duration-metric helpers that preserve request outcomes when telemetry operations fail. |
| nemoguardrails/tracing/constants.py | Adds HTTP semantic-convention constants and lazily initialized request-duration instrumentation. |
| tests/http/test_instrumentation.py | Covers tracing, metrics, privacy, error preservation, wrapping idempotency, and serialized retryable cleanup. |
| nemoguardrails/http/init.py | Exposes the new instrumented client and factory helper through the HTTP package API. |
Sequence Diagram
sequenceDiagram
participant Caller
participant Instrumented as InstrumentedHTTPClient
participant Telemetry
participant Wrapped as Wrapped HTTPClient
Caller->>Instrumented: request(method, url, ...)
Instrumented->>Telemetry: start span and duration metric
Instrumented->>Wrapped: request(method, url, ...)
Wrapped-->>Instrumented: HTTPResponse or exception
Instrumented->>Telemetry: record status, retry count, size, or error type
Instrumented-->>Caller: preserve response or exception
Caller->>Instrumented: close()
Instrumented->>Instrumented: acquire close lock
Instrumented->>Wrapped: close()
Wrapped-->>Instrumented: success or failure
alt success
Instrumented->>Instrumented: mark closed
else failure or cancellation
Instrumented->>Instrumented: remain retryable
end
Reviews (4): Last reviewed commit: "docs(http): cite OpenTelemetry bucket gu..." | Re-trigger Greptile
📝 WalkthroughWalkthroughAdds OpenTelemetry tracing and request-duration metrics for HTTP clients, including semantic attributes, error and retry telemetry, idempotent client wrapping, public exports, and comprehensive asynchronous tests. ChangesHTTP instrumentation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant instrument_http_client
participant InstrumentedHTTPClient
participant HTTPClient
participant OpenTelemetry
Caller->>instrument_http_client: request instrumentation
instrument_http_client->>InstrumentedHTTPClient: create or reuse wrapper
InstrumentedHTTPClient->>OpenTelemetry: start span and duration measurement
InstrumentedHTTPClient->>HTTPClient: forward HTTP request
HTTPClient-->>InstrumentedHTTPClient: return HTTPResponse
InstrumentedHTTPClient->>OpenTelemetry: record response attributes and metrics
InstrumentedHTTPClient-->>Caller: return HTTPResponse
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
tgasser-nv
left a comment
There was a problem hiding this comment.
I reviewed the first commit (sha 71ca58d) only, thanks for the second commit to show how this would integrate into IORails. Here are the comments on the first commit, can you remove the IORails-related commit before you merge?
High level comments:
- Can you address the Greptile 3/5 and feedback?
- Can you add tests to improve coverage?
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Pouyan <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
37f4cdb to
c3dd93f
Compare
Description
Adds privacy-safe tracing and request-duration metrics as a decorator over the
shared HTTP client contract introduced in Stack 9.
Design principle: instrumentation observes the client boundary without owning
request or client lifecycle.
http_call, IORails, and other callers can keepusing the same
HTTPClientcontract, while tracing and metrics remain optionaland independently configurable.
Related Issue(s)
AI Assistance
Codex assisted with implementation, validation, and stack restructuring. Check
the disclosure box after human review.
Checklist
Summary by CodeRabbit