ray.serve.get_trace_context#
- ray.serve.get_trace_context() Dict[str, str] | None[source]#
Get the current OpenTelemetry trace context.
This can be used inside a deployment to create child spans that are linked to the Serve request trace. Requires tracing to be enabled via the
RAY_SERVE_TRACING_EXPORTER_IMPORT_PATHenvironment variable.- Returns:
The current OpenTelemetry context, or None if tracing is not enabled.
Example:
from opentelemetry import trace from ray import serve tracer = trace.get_tracer(__name__) @serve.deployment class MyDeployment: def __call__(self, request): with tracer.start_as_current_span( "my_span", context=serve.get_trace_context() ): ...
PublicAPI (alpha): This API is in alpha and may change before becoming stable.