nemoguardrails.http.instrumented

View as Markdown

Module Contents

Classes

NameDescription
InstrumentedHTTPClientDecorate an HTTP client with privacy-safe tracing and metrics.

Functions

NameDescription
instrument_http_clientReturn client decorated with the requested HTTP telemetry.

Data

__all__

API

class nemoguardrails.http.instrumented.InstrumentedHTTPClient(
client: nemoguardrails.http.client.HTTPClient,
tracer: opentelemetry.trace.Tracer | None,
metrics_enabled: bool = False
)

Decorate an HTTP client with privacy-safe tracing and metrics.

The decorator preserves request behavior and client ownership. Wrapping an existing InstrumentedHTTPClient is idempotent, and tracing and metrics can be enabled independently.

_close_lock
= asyncio.Lock()
wrapped_client
HTTPClient

Return the underlying client for direct access or re-instrumentation.

nemoguardrails.http.instrumented.InstrumentedHTTPClient.__new__(
client: nemoguardrails.http.client.HTTPClient,
args: typing.Any = (),
kwargs: typing.Any = {}
)

Return an existing instrumented client without wrapping it again.

Apply the current instrumentation settings to another client.

nemoguardrails.http.instrumented.InstrumentedHTTPClient.close() -> None
async

Close the wrapped client without taking ownership from its caller.

Repeated calls are safe. A failed or cancelled close remains retryable.

nemoguardrails.http.instrumented.InstrumentedHTTPClient.request(
method: str,
url: str,
headers: typing.Mapping[str, str] | None = None,
params: typing.Mapping[str, typing.Any] | None = None,
json: typing.Any = None,
content: bytes | str | None = None,
timeout: float | None = None
) -> nemoguardrails.http.types.HTTPResponse
async

Forward one request while recording privacy-safe HTTP telemetry.

Telemetry includes the method, sanitized URL, payload sizes, response status, and retry count. Header, query, body, and credential values are never recorded.

nemoguardrails.http.instrumented.instrument_http_client(
client: nemoguardrails.http.client.HTTPClient,
tracer: opentelemetry.trace.Tracer | None = None,
metrics_enabled: bool = False
) -> nemoguardrails.http.client.HTTPClient

Return client decorated with the requested HTTP telemetry.

The original client is returned when telemetry is disabled or the client is already instrumented.

nemoguardrails.http.instrumented.__all__ = ['InstrumentedHTTPClient', 'instrument_http_client']