Skip to content

datarobot_genai.core.telemetry.agent

agent

Lightweight, idempotent client/framework instrumentation for agents.

instrument

instrument() -> None

Idempotently instrument supported HTTP clients and OpenAI SDK.

Also disables telemetry for some third-party libraries to avoid duplicate/undesired tracking.

Source code in datarobot_genai/core/telemetry/agent.py
def instrument() -> None:
    """Idempotently instrument supported HTTP clients and OpenAI SDK.

    Also disables telemetry for some third-party libraries to avoid duplicate/undesired tracking.
    """
    # Some libraries collect telemetry data by default. Disable that.
    os.environ.setdefault("RAGAS_DO_NOT_TRACK", "true")
    os.environ.setdefault("DEEPEVAL_TELEMETRY_OPT_OUT", "YES")

    # Install a global OTel TracerProvider pointed at the DataRobot OTel
    # ingest before any instrumentor patches a framework. NAT's
    # datarobot_otelcollector exporter pipes its own IntermediateStep-derived
    # spans through a separate channel that does not touch the OTel SDK
    # global provider — so without this bootstrap, the framework
    # instrumentors patched below would emit spans through a no-op tracer
    # and nothing reaches DataRobot.
    #
    # TODO (BUZZOK-31396): Call bootstrap from the deployment/notebook entrypoint instead of
    # here so notebook hosts that already install their own TracerProvider
    # (via setup_otel_env_variables) are not double-bootstrapped. See
    # https://github.com/datarobot/datarobot-user-models/blob/master/public_dropin_environments/python311_genai_agents/run_agent.py#L188
    if is_hosted_runtime():
        from .datarobot_otel import bootstrap_otel_provider_for_datarobot

        bootstrap_otel_provider_for_datarobot()

    _instrument_threading()
    _instrument_http_clients()
    _instrument_openai()