The most basic form of manual trace control involves starting a trace, executing your code, and then ending the trace with a specific state:
Copy
import agentops# Initialize without automatic session creationagentops.init("your-api-key", auto_start_session=False)# Start a trace manuallytrace = agentops.start_trace("my-workflow")try: # Your application logic here result = perform_some_operation() # End the trace successfully agentops.end_trace(trace, "Success")except Exception as e: # End the trace with failure state agentops.end_trace(trace, "Indeterminate")
You can provide meaningful names and tags when starting traces:
Copy
# Start a trace with custom name and tagstrace = agentops.start_trace( trace_name="customer-service-workflow", tags=["customer-123", "priority-high", "support"])
You can update metadata on running traces at any point during execution using the update_trace_metadata function. This is useful for adding context, tracking progress, or storing intermediate results.
The function automatically maps user-friendly keys to semantic conventions when possible:
Copy
# These keys will be mapped to semantic conventionsagentops.update_trace_metadata({ "operation_name": "AI Agent Data Processing", "tags": ["production", "batch-job", "gpt-4"], # Maps to core.tags "agent_name": "DataProcessorAgent", # Maps to agent.name "workflow_name": "Intelligent ETL Pipeline", # Maps to workflow.name})