()
| 419 | elif is_async: |
| 420 | |
| 421 | async def _wrapped_async() -> Any: |
| 422 | with _create_as_current_span( |
| 423 | operation_name, |
| 424 | entity_kind, |
| 425 | version=version, |
| 426 | attributes={CoreAttributes.TAGS: tags} if tags else None, |
| 427 | ) as span: |
| 428 | try: |
| 429 | _record_entity_input(span, args, kwargs, entity_kind=entity_kind) |
| 430 | # Set cost attribute if tool |
| 431 | if entity_kind == "tool" and cost is not None: |
| 432 | span.set_attribute(SpanAttributes.LLM_USAGE_TOOL_COST, cost) |
| 433 | # Set spec attribute if guardrail |
| 434 | if entity_kind == "guardrail" and (spec == "input" or spec == "output"): |
| 435 | span.set_attribute( |
| 436 | SpanAttributes.AGENTOPS_DECORATOR_SPEC.format(entity_kind=entity_kind), spec |
| 437 | ) |
| 438 | except Exception as e: |
| 439 | logger.warning(f"Input recording failed for '{operation_name}': {e}") |
| 440 | try: |
| 441 | result = await wrapped_func(*args, **kwargs) |
| 442 | try: |
| 443 | _record_entity_output(span, result, entity_kind=entity_kind) |
| 444 | except Exception as e: |
| 445 | logger.warning(f"Output recording failed for '{operation_name}': {e}") |
| 446 | return result |
| 447 | except Exception as e: |
| 448 | logger.error(f"Error in async function execution: {e}") |
| 449 | span.record_exception(e) |
| 450 | raise |
| 451 | |
| 452 | return _wrapped_async() |
| 453 | else: # Sync function for non-SESSION kinds |
no test coverage detected
searching dependent graphs…