Add pydocstyle to the ruff rules (#52136)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Signed-off-by: Harry Mellor <hej.mellor@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -94,9 +94,7 @@ def instrument(
|
||||
attributes: dict[str, str] | None = None,
|
||||
record_exception: bool = True,
|
||||
):
|
||||
"""
|
||||
Generic decorator to instrument functions.
|
||||
"""
|
||||
"""Generic decorator to instrument functions."""
|
||||
if obj is None:
|
||||
return functools.partial(
|
||||
instrument,
|
||||
@@ -135,6 +133,7 @@ def instrument_manual(
|
||||
attributes: Optional dict of span attributes.
|
||||
context: Optional trace context (e.g., from extract_trace_context).
|
||||
kind: Optional SpanKind (e.g., SpanKind.SERVER).
|
||||
|
||||
"""
|
||||
is_available, _, _, _, manual_instrument_fn = _REGISTERED_TRACING_BACKENDS["otel"]
|
||||
if is_available():
|
||||
@@ -146,8 +145,7 @@ def instrument_manual(
|
||||
|
||||
|
||||
def is_tracing_available() -> bool:
|
||||
"""
|
||||
Returns True if any tracing backend (OTel, Profiler, etc.) is available.
|
||||
"""Returns True if any tracing backend (OTel, Profiler, etc.) is available.
|
||||
Use this to guard expensive tracing logic in the main code.
|
||||
"""
|
||||
check_available = [
|
||||
|
||||
@@ -107,9 +107,7 @@ def init_otel_worker_tracer(
|
||||
process_kind: str,
|
||||
process_name: str,
|
||||
) -> Tracer:
|
||||
"""
|
||||
Backend-specific initialization for OpenTelemetry in a worker process.
|
||||
"""
|
||||
"""Backend-specific initialization for OpenTelemetry in a worker process."""
|
||||
# Initialize the tracer if an OTLP endpoint is configured.
|
||||
# The endpoint is propagated via environment variable from the main process.
|
||||
otlp_endpoint = os.environ.get("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT")
|
||||
@@ -133,7 +131,6 @@ def extract_trace_context(headers: Mapping[str, str] | None) -> Context | None:
|
||||
|
||||
def instrument_otel(func, span_name, attributes, record_exception):
|
||||
"""Internal wrapper logic for sync and async functions."""
|
||||
|
||||
# Pre-calculate static code attributes once (these don't change)
|
||||
code_attrs = {
|
||||
LoadingSpanAttributes.CODE_FUNCTION: func.__qualname__,
|
||||
@@ -214,8 +211,7 @@ def manual_instrument_otel(
|
||||
|
||||
|
||||
def _get_smart_context() -> Context | None:
|
||||
"""
|
||||
Determines the parent context.
|
||||
"""Determines the parent context.
|
||||
1. If a Span is already active in this process, use it.
|
||||
2. If not, extract from os.environ, handling the case-sensitivity mismatch.
|
||||
"""
|
||||
@@ -239,8 +235,7 @@ def _get_smart_context() -> Context | None:
|
||||
|
||||
@contextmanager
|
||||
def propagate_trace_to_env():
|
||||
"""
|
||||
Temporarily injects the current OTel context into os.environ.
|
||||
"""Temporarily injects the current OTel context into os.environ.
|
||||
This ensures that any subprocesses (like vLLM workers) spawned
|
||||
within this context inherit the correct traceparent.
|
||||
"""
|
||||
|
||||
@@ -13,8 +13,7 @@ TRACE_HEADERS = ["traceparent", "tracestate"]
|
||||
|
||||
|
||||
class SpanAttributes:
|
||||
"""
|
||||
Standard attributes for spans.
|
||||
"""Standard attributes for spans.
|
||||
|
||||
These are largely based on OpenTelemetry Semantic Conventions but are defined
|
||||
here as constants so they can be used by any backend or logger.
|
||||
@@ -60,8 +59,7 @@ def contains_trace_headers(headers: Mapping[str, str]) -> bool:
|
||||
|
||||
|
||||
def extract_trace_headers(headers: Mapping[str, str]) -> Mapping[str, str]:
|
||||
"""
|
||||
Extract only trace-related headers from a larger header dictionary.
|
||||
"""Extract only trace-related headers from a larger header dictionary.
|
||||
Useful for logging or passing context to a non-OTel client.
|
||||
"""
|
||||
return {h: headers[h] for h in TRACE_HEADERS if h in headers}
|
||||
|
||||
Reference in New Issue
Block a user