85742ab165
CPU Test / Lint - next (push) Waiting to run
Dashboard / Chromatic (push) Waiting to run
CPU Test / Lint - fast (push) Waiting to run
CPU Test / Build documentation (push) Waiting to run
CPU Test / Test (Store, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Weave, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Others, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Store, latest, Python 3.13) (push) Waiting to run
CPU Test / Lint - slow (push) Waiting to run
CPU Test / Lint - JavaScript (push) Waiting to run
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Others, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Weave, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (JavaScript) (push) Waiting to run
Deploy Documentation / deploy (push) Has been cancelled
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
import agentops
|
|
import agentops.sdk.core as agentops_core
|
|
import opentelemetry.trace as trace_api
|
|
|
|
from agentlightning.tracer.dummy import DummyTracer
|
|
from agentlightning.types import Attributes, SpanCoreFields, TraceStatus
|
|
|
|
|
|
# pyright: reportPrivateUsage=false
|
|
def clear_tracer_provider() -> None:
|
|
"""OpenTelemetry tracer provider does not allow set twice.
|
|
|
|
Reset the tracer provider to allow setting it again in tests.
|
|
This is a hack to the internal state of OpenTelemetry.
|
|
Not a good idea to use in production.
|
|
Always remember to setup two processes if you need two tracers.
|
|
"""
|
|
|
|
if hasattr(trace_api, "_TRACER_PROVIDER"):
|
|
if trace_api._TRACER_PROVIDER is not None:
|
|
trace_api._TRACER_PROVIDER = None
|
|
|
|
if hasattr(trace_api, "_TRACER_PROVIDER_SET_ONCE"):
|
|
if hasattr(trace_api._TRACER_PROVIDER_SET_ONCE, "_done"):
|
|
if trace_api._TRACER_PROVIDER_SET_ONCE._done:
|
|
trace_api._TRACER_PROVIDER_SET_ONCE._done = False
|
|
|
|
if hasattr(trace_api._TRACER_PROVIDER_SET_ONCE, "_flag"):
|
|
if trace_api._TRACER_PROVIDER_SET_ONCE._flag: # type: ignore
|
|
trace_api._TRACER_PROVIDER_SET_ONCE._flag = False # type: ignore
|
|
|
|
|
|
def clear_agentops_init() -> None:
|
|
"""Make agentops.init() runnable again."""
|
|
agentops.get_client().initialized = False
|
|
agentops_core.tracer._initialized = False
|
|
|
|
|
|
class RecordingDummyTracer(DummyTracer):
|
|
"""Dummy tracer that captures the most recent span request for assertions."""
|
|
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self.last_span: Optional[SpanCoreFields] = None
|
|
|
|
def create_span(
|
|
self,
|
|
name: str,
|
|
attributes: Optional[Attributes] = None,
|
|
timestamp: Optional[float] = None,
|
|
status: Optional[TraceStatus] = None,
|
|
) -> SpanCoreFields:
|
|
span = super().create_span(name, attributes, timestamp, status)
|
|
self.last_span = span
|
|
return span
|