Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Mlflow Mlflow Set Destination

From Leeroopedia
Knowledge Sources
Domains ML_Ops, LLM_Observability
Last Updated 2026-02-13 20:00 GMT

Overview

Concrete tool for configuring the export destination of MLflow traces provided by the MLflow library.

Description

The mlflow.tracing.set_destination function sets a custom trace location that takes precedence over other configurations such as the tracking URI or OTLP environment variables. It accepts a TraceLocationBase object that specifies where trace data should be exported.

Two built-in location types are supported: MlflowExperimentLocation for routing traces to a specific MLflow experiment by experiment ID, and UCSchemaLocation for routing traces to a Databricks Unity Catalog schema (available only in Databricks environments). When a UCSchemaLocation is specified and the tracking URI is not already set to Databricks, the function automatically sets it.

The context_local parameter enables per-task or per-thread destination isolation. When set to True, the destination only applies within the current execution context (async task or thread), preventing trace cross-contamination in concurrent multi-tenant applications. The destination can be reset using mlflow.tracing.reset().

Internally, the function stores the destination in the _MLFLOW_TRACE_USER_DESTINATION context variable and reinitializes the tracer provider to apply the new configuration.

Usage

Use set_destination when you need explicit control over where traces are stored. This is necessary when working with multiple experiments simultaneously, routing traces to Unity Catalog for governance, or building multi-tenant serving applications where each request must write to a different trace store. Call it during application initialization or at the beginning of a request handler.

Code Reference

Source Location

  • Repository: mlflow
  • File: mlflow/tracing/provider.py
  • Lines: L308-394

Signature

mlflow.tracing.set_destination(
    destination: TraceLocationBase,
    *,
    context_local: bool = False,
) -> None

Import

from mlflow.tracing import set_destination
from mlflow.entities.trace_location import MlflowExperimentLocation, UCSchemaLocation

I/O Contract

Inputs

Name Type Required Description
destination TraceLocationBase Yes A trace location object specifying the export target. Supported types: MlflowExperimentLocation, UCSchemaLocation.
context_local bool No If True, the destination is scoped to the current async task or thread. If False (default), the destination is set globally.

Outputs

Name Type Description
(side effect) None The custom trace exporter is configured via the internal _MLFLOW_TRACE_USER_DESTINATION context variable and the tracer provider is reinitialized.

Usage Examples

Basic Usage

import mlflow
from mlflow.entities.trace_location import MlflowExperimentLocation

# Route all traces to a specific experiment
mlflow.tracing.set_destination(
    MlflowExperimentLocation(experiment_id="123")
)

# Traces generated after this call go to experiment "123"

Unity Catalog Destination

import mlflow
from mlflow.entities.trace_location import UCSchemaLocation

# Route traces to a Databricks Unity Catalog schema
mlflow.tracing.set_destination(
    UCSchemaLocation(catalog_name="ml_catalog", schema_name="traces")
)

Context-Local Destination for Multi-Tenancy

import mlflow
from mlflow.entities.trace_location import MlflowExperimentLocation

# Isolate trace destination to the current async task
mlflow.tracing.set_destination(
    MlflowExperimentLocation(experiment_id="tenant_456"),
    context_local=True,
)

Resetting the Destination

import mlflow

# Reset to default destination behavior
mlflow.tracing.reset()

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment