Skip to content

trulens.core.otel.client_hooks.exporting

trulens.core.otel.client_hooks.exporting

Destination configuration and span export for coding-agent hooks.

Everything here is configured through the environment; there are no arguments to pass.

TRULENS_DESTINATION selects the destination and defaults to local:

  • local or database -- TRULENS_DATABASE_URL if set, otherwise a SQLite file at TRULENS_DATABASE_PATH (default ~/.trulens/client-hooks.sqlite, created mode 0700).
  • snowflake -- TRULENS_SNOWFLAKE_CONNECTION (required) names the connection; the optional TRULENS_SNOWFLAKE_DATABASE and TRULENS_SNOWFLAKE_SCHEMA override what it resolves to.
  • otlp -- TRULENS_OTLP_ENDPOINT is the collector to export to. Unset, the exporter falls back to its own default rather than failing here, so a typo in the variable name shows up as spans arriving somewhere unexpected rather than as an error. TRULENS_OTLP_PROTOCOL picks the transport, grpc or http/protobuf, and falls back to the standard OTEL_EXPORTER_OTLP_PROTOCOL.
  • ai_gateway -- TRULENS_AI_GATEWAY_URL (required) is the gateway base URL, and the token comes from TRULENS_AI_GATEWAY_PAT_FILE or TRULENS_AI_GATEWAY_TOKEN (one required). Always OTLP over HTTP/protobuf, since gateways do not serve gRPC.

Any other value of TRULENS_DESTINATION raises.

Functions

create_session

create_session() -> TruSession

Create the configured destination TruLens session.

Supported TRULENS_DESTINATION values: local (default), database, snowflake, otlp, and ai_gateway.

export_spans

export_spans(
    spans: Sequence[ReadableSpan],
    *,
    session: Optional[TruSession] = None
) -> bool

Synchronously export one complete trace batch.