Skip to main content

MLflow

If we want to use MLflow for observability of Spring AI applications, no code changes are required. MLflow provides full OpenTelemetry support. All we need to do is configuring OpenTelemetry collector to send traces to MLflow.

OpenTelemetry collector with MLflow

Below is the updated config of OpenTelemetry collector. The endpoint is set to http://mlflow:5000. The header x-mlflow-experiment-id specifies the experiment id in MLflow. This is a required header.

Configuration of OpenTelemetry collector for MLflow
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
http:
endpoint: "0.0.0.0:4318"
processors:
batch:
exporters:
otlp_http/mlflow:
endpoint: "http://mlflow:5000"
headers:
x-mlflow-experiment-id: "0"
tls:
insecure: true
prometheus:
endpoint: "otel-collector:10010"
service:
pipelines:
metrics:
receivers: [ otlp ]
processors: [ batch ]
exporters: [ prometheus ]
traces:
receivers: [ otlp ]
processors: [ batch ]
exporters: [ otlp_http/mlflow ]

Test

After starting the Spring AI app, we can interact with it by send some messages. Open MLflow UI to view traces. Below is the screenshot of MLflow UI.

MLflow UI

Source Code