LLM Observability with Google Cloud Trace and OpenLLMetry
Google Cloud, also known as Google Cloud Platform (GCP), is a cloud provider including over 150+ products and services. Among these products and services is Cloud Trace, which is a part of the Google Cloud Observability suite alongside Cloud Monitoring and Cloud Logging.
Traceloop’s OpenLLMetry library enables instrumenting LLM frameworks in an OTel-aligned manner and supports writing that instrumentation data as distributed traces to Cloud Trace. Traceloop’s OpenLLMetry library can be additionally configured to also write to Cloud Monitoring and to Cloud Logging.
Minimal Integration: Cloud Trace only
Dependencies
OpenLLMetry Configuration
Integration with Cloud Trace and Cloud Monitoring
Dependencies
OpenLLMetry Configuration
Integration with Cloud Trace, Cloud Monitoring, and Cloud Logging
As of 2024-12-05, there is no direct Python OTel exporter for Cloud Logging. However,
it is possible to work around this by routing to the OTel Collector
and using the googlecloudexporter
in the OTel Collector to route logs to Google Cloud Logging. Alternatively, you
can use the Python ConsoleLogExporter
to log to a file in conjunction with automatic file-based log routing such as via
the Ops Agent,
direct use of FluentBit, or other routing solutions.
Dependencies
OTel Dependencies
This is assuming that you write to Cloud Logging via the OTel Collector:
Python Dependencies
opentelemetry-exporter-gcp-trace
opentelemetry-exporter-gcp-monitoring
opentelemetry-exporter-otlp-proto-grpc
traceloop-sdk
OpenLLMetry Configuration
Advanced Topics
Large Span Attributes
Although OTel Semantic Conventions for GenAI has been moving from prompt/response logging in span attributes to recording prompts/responses in events (logs) — see related pull request —, some versions of OpenLLMetry and related instrumentation packages follow older experimental conventions of recording prompts/responses in span attributes which do not fit within Cloud Trace limits.
The e2e-gen-ai-app-starter-pack
code sample provided by Google illustrates a potential workaround; that app, calls
Traceloop.init
with a custom CloudTraceLoggingSpanExporter
which inherits from the official CloudTraceSpanExporter
and adds additional capabilities
for handling large span attributes.