@@ -33,9 +33,10 @@ def decorator(
3333 version : Optional [Any ] = None ,
3434 tags : Optional [Union [list , dict ]] = None ,
3535 cost = None ,
36+ spec = None ,
3637 ) -> Callable [..., Any ]:
3738 if wrapped is None :
38- return functools .partial (decorator , name = name , version = version , tags = tags , cost = cost )
39+ return functools .partial (decorator , name = name , version = version , tags = tags , cost = cost , spec = spec )
3940
4041 if inspect .isclass (wrapped ):
4142 # Class decoration wraps __init__ and aenter/aexit for context management.
@@ -168,10 +169,13 @@ async def _wrapped_session_async() -> Any:
168169 attributes = {CoreAttributes .TAGS : tags } if tags else None ,
169170 )
170171 try :
171- _record_entity_input (span , args , kwargs )
172+ _record_entity_input (span , args , kwargs , entity_kind = entity_kind )
172173 # Set cost attribute if tool
173174 if entity_kind == "tool" and cost is not None :
174175 span .set_attribute (SpanAttributes .LLM_USAGE_TOOL_COST , cost )
176+ # Set spec attribute if guardrail
177+ if entity_kind == "guardrail" and (spec == "input" or spec == "output" ):
178+ span .set_attribute (SpanAttributes .AGENTOPS_DECORATOR_SPEC .format (entity_kind = entity_kind ), spec )
175179 except Exception as e :
176180 logger .warning (f"Input recording failed for '{ operation_name } ': { e } " )
177181 result = wrapped_func (* args , ** kwargs )
@@ -184,10 +188,13 @@ async def _wrapped_session_async() -> Any:
184188 attributes = {CoreAttributes .TAGS : tags } if tags else None ,
185189 )
186190 try :
187- _record_entity_input (span , args , kwargs )
191+ _record_entity_input (span , args , kwargs , entity_kind = entity_kind )
188192 # Set cost attribute if tool
189193 if entity_kind == "tool" and cost is not None :
190194 span .set_attribute (SpanAttributes .LLM_USAGE_TOOL_COST , cost )
195+ # Set spec attribute if guardrail
196+ if entity_kind == "guardrail" and (spec == "input" or spec == "output" ):
197+ span .set_attribute (SpanAttributes .AGENTOPS_DECORATOR_SPEC .format (entity_kind = entity_kind ), spec )
191198 except Exception as e :
192199 logger .warning (f"Input recording failed for '{ operation_name } ': { e } " )
193200 result = wrapped_func (* args , ** kwargs )
@@ -202,16 +209,21 @@ async def _wrapped_async() -> Any:
202209 attributes = {CoreAttributes .TAGS : tags } if tags else None ,
203210 ) as span :
204211 try :
205- _record_entity_input (span , args , kwargs )
212+ _record_entity_input (span , args , kwargs , entity_kind = entity_kind )
206213 # Set cost attribute if tool
207214 if entity_kind == "tool" and cost is not None :
208215 span .set_attribute (SpanAttributes .LLM_USAGE_TOOL_COST , cost )
216+ # Set spec attribute if guardrail
217+ if entity_kind == "guardrail" and (spec == "input" or spec == "output" ):
218+ span .set_attribute (
219+ SpanAttributes .AGENTOPS_DECORATOR_SPEC .format (entity_kind = entity_kind ), spec
220+ )
209221 except Exception as e :
210222 logger .warning (f"Input recording failed for '{ operation_name } ': { e } " )
211223 try :
212224 result = await wrapped_func (* args , ** kwargs )
213225 try :
214- _record_entity_output (span , result )
226+ _record_entity_output (span , result , entity_kind = entity_kind )
215227 except Exception as e :
216228 logger .warning (f"Output recording failed for '{ operation_name } ': { e } " )
217229 return result
@@ -229,16 +241,21 @@ async def _wrapped_async() -> Any:
229241 attributes = {CoreAttributes .TAGS : tags } if tags else None ,
230242 ) as span :
231243 try :
232- _record_entity_input (span , args , kwargs )
244+ _record_entity_input (span , args , kwargs , entity_kind = entity_kind )
233245 # Set cost attribute if tool
234246 if entity_kind == "tool" and cost is not None :
235247 span .set_attribute (SpanAttributes .LLM_USAGE_TOOL_COST , cost )
248+ # Set spec attribute if guardrail
249+ if entity_kind == "guardrail" and (spec == "input" or spec == "output" ):
250+ span .set_attribute (
251+ SpanAttributes .AGENTOPS_DECORATOR_SPEC .format (entity_kind = entity_kind ), spec
252+ )
236253 except Exception as e :
237254 logger .warning (f"Input recording failed for '{ operation_name } ': { e } " )
238255 try :
239256 result = wrapped_func (* args , ** kwargs )
240257 try :
241- _record_entity_output (span , result )
258+ _record_entity_output (span , result , entity_kind = entity_kind )
242259 except Exception as e :
243260 logger .warning (f"Output recording failed for '{ operation_name } ': { e } " )
244261 return result
0 commit comments