nemoguardrails.http.telemetry

View as Markdown

Module Contents

Classes

NameDescription
_HTTPRequestDurationStateCarry response status from request execution to metric recording.

Functions

NameDescription
_http_metric_attributes-
http_call_spanCreate a privacy-safe client span for one HTTP call.
http_request_durationRecord one HTTP client request-duration observation.
record_http_errorRecord an exception type and retry count without exposing its message.
set_http_request_attributesRecord privacy-safe HTTP request attributes on a span.
set_http_response_attributesRecord response status, body size, and retry count on a span.

Data

__all__

log

API

class nemoguardrails.http.telemetry._HTTPRequestDurationState(
response_status_code: int | None = None
)
Dataclass

Carry response status from request execution to metric recording.

response_status_code
int | None = None
nemoguardrails.http.telemetry._http_metric_attributes(
method: str,
url: str
) -> dict[str, str | int] | None
nemoguardrails.http.telemetry.http_call_span(
tracer: opentelemetry.trace.Tracer | None,
method: str,
url: str,
content: bytes | str | None
) -> typing.Generator[opentelemetry.trace.Span | None, None, None]

Create a privacy-safe client span for one HTTP call.

Yields None when no tracer is configured. Request exceptions are recorded and re-raised unchanged.

nemoguardrails.http.telemetry.http_request_duration(
method: str,
url: str
) -> typing.Generator[nemoguardrails.http.telemetry._HTTPRequestDurationState, None, None]

Record one HTTP client request-duration observation.

The metric contains only low-cardinality endpoint attributes plus response status or exception type. Telemetry failures never affect the request.

nemoguardrails.http.telemetry.record_http_error(
span: opentelemetry.trace.Span | None,
error: BaseException
) -> None

Record an exception type and retry count without exposing its message.

nemoguardrails.http.telemetry.set_http_request_attributes(
span: opentelemetry.trace.Span | None,
method: str,
url: str,
content: bytes | str | None
) -> None

Record privacy-safe HTTP request attributes on a span.

The URL is stripped of credentials, query parameters, and fragments. Raw headers and body content are never recorded.

nemoguardrails.http.telemetry.set_http_response_attributes(
span: opentelemetry.trace.Span | None,
response: nemoguardrails.http.types.HTTPResponse
) -> None

Record response status, body size, and retry count on a span.

nemoguardrails.http.telemetry.__all__ = ['http_call_span', 'http_request_duration', 'record_http_error', 'set_http_reque...
nemoguardrails.http.telemetry.log = logging.getLogger(__name__)