OpenTelemetry Export
Traces generated by MLflow are compatible with the OpenTelemetry trace specs. Therefore, MLflow traces can be exported to various observability solutions that support OpenTelemetry.
By default, MLflow exports traces to the MLflow Tracking Server. To enable exporting traces to an OpenTelemetry Collector, set the OTEL_EXPORTER_OTLP_ENDPOINT
environment variable (or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
) to the target URL of the OpenTelemetry Collector before starting any trace.
import mlflow
import os
# Set the endpoint of the OpenTelemetry Collector
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = "http://localhost:4317/v1/traces"
# Optionally, set the service name to group traces
os.environ["OTEL_SERVICE_NAME"] = "<your-service-name>"
# Trace will be exported to the OTel collector at http://localhost:4317/v1/traces
with mlflow.start_span(name="foo") as span:
span.set_inputs({"a": 1})
span.set_outputs({"b": 2})
MLflow only exports traces to a single destination. When the OTEL_EXPORTER_OTLP_ENDPOINT
environment variable is configured, MLflow will not export traces to Databricks MLflow Tracking and you will not see traces in the MLflow UI.
Similarly, if you deploy the model to the Databricks Model Serving with tracing enabled, using the OpenTelemetry Collector will result in traces not being recorded in the Inference Table.
Click on the following icons to learn more about how to set up OpenTelemetry Collector for your specific observability platform.
Platform | OpenTelemetry Documentation |
---|---|
Datadog | |
New Relic | |
SigNoz | |
Splunk | |
Grafana | |
ServiceNow (Lightstep) |
Configurations
MLflow uses the standard OTLP Exporter for exporting traces to OpenTelemetry Collector instances. Thereby, you can use all of the configurations supported by OpenTelemetry. The following example configures the OTLP Exporter to use HTTP protocol instead of the default gRPC and sets custom headers:
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://localhost:4317/v1/traces"
export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="api_key=12345"
Next Steps
- Understand tracing concepts - Learn how MLflow's OpenTelemetry-compatible traces are structured
- Instrument your app with tracing - Add custom spans to enrich your OpenTelemetry exports
- Debug production issues - Use exported traces to monitor production applications