MCPcopy
hub / github.com/NVIDIA/TensorRT-LLM / async_wrapper

Function async_wrapper

tensorrt_llm/llmapi/tracing.py:201–223  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

199
200 @functools.wraps(func)
201 async def async_wrapper(*args, **kwargs):
202 span_name = name if name is not None else func.__name__
203 if global_otlp_tracer() is None:
204 return await func(*args, **kwargs)
205
206 trace_headers = None
207 for arg in list(args) + list(kwargs.values()):
208 if hasattr(arg, 'headers'):
209 trace_headers = extract_trace_context(arg.headers)
210 break
211
212 with global_otlp_tracer().start_as_current_span(
213 span_name, kind=SpanKind.SERVER,
214 context=trace_headers) as span:
215 try:
216 result = await func(*args, **kwargs)
217 span.set_status(Status(StatusCode.OK))
218 return result
219 except Exception as e:
220 span.record_exception(e)
221 span.set_status(
222 Status(StatusCode.ERROR, f"An error occurred: {e}"))
223 raise e
224
225 return async_wrapper
226

Callers

nothing calls this directly

Calls 4

global_otlp_tracerFunction · 0.85
extract_trace_contextFunction · 0.85
funcFunction · 0.50
valuesMethod · 0.45

Tested by

no test coverage detected