Tracer
Tracer provides a convenient way to aggregate multiple library calls made within its context, automatically waiting for and aggregating impact data when accessed, unlike direct API calls which need to be handled individually - see our complete guide for details and examples.
scope3ai.api.tracer
Classes:
-
Tracer–Tracer is responsible for tracking and aggregating environmental impact metrics
Tracer
Tracer(name: str = None, keep_traces: bool = False, client_id: Optional[str] = None, project_id: Optional[str] = None, application_id: Optional[str] = None, session_id: Optional[str] = None, trace_id: Optional[str] = None)
Tracer is responsible for tracking and aggregating environmental impact metrics from AI model interactions. It supports nested tracing, async operations, and provides detailed impact breakdowns for energy, emissions and water usage.
Parameters:
-
(namestr, default:None) –Name identifier for the tracer. Defaults to None.
-
(keep_tracesbool, default:False) –Whether to keep trace history after completion. Defaults to False.
-
(client_idstr, default:None) –Client identifier for categorizing traces. Overrides global
SCOPE3AI_CLIENT_IDsetting. Defaults to None. -
(project_idstr, default:None) –Project identifier for categorizing traces. Overrides global
SCOPE3AI_PROJECT_IDsetting. Defaults to None. -
(application_idstr, default:None) –Application identifier for categorizing traces. Overrides global
SCOPE3AI_APPLICATION_IDsetting. Defaults to None. -
(session_idstr, default:None) –Session identifier for tracking user sessions. Only available at tracer level. Defaults to None.
-
(trace_idstr, default:None) –Unique identifier for the trace. Auto-generated if not provided. Defaults to None.
Methods:
-
aimpact–Async version of Tracer::impact.
-
impact–Return an aggregated impact response for the current tracer and its children.
aimpact
async
aimpact(timeout: Optional[int] = None) -> ImpactResponse
Async version of Tracer::impact.
impact
impact(timeout: Optional[int] = None) -> ImpactResponse
Return an aggregated impact response for the current tracer and its children.
As the impact is computed asynchronously, this method will wait for the impact response to be available before returning it.