Skip to content

[BUG] mlflow-tracing package is not sufficient for tracing #17619

Description

@vilmar-hillow

Issues Policy acknowledgement

  • I have read and agree to submit bug reports in accordance with the issues policy

Where did you encounter this bug?

Local machine

MLflow version

  • Client: 3.3.2

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 24.04
  • Python version: 3.13

Describe the problem

We are checking out tracing functionality. The documentation mentions using mlflow-tracing, which is an ideal choice in production as it limits unnecessary dependencies in the environment. However, it doesn't actually work on its own - no traces are logged and the warning message is seen in the logs: WARNING mlflow.tracing.fluent: Failed to start span Completions: name 'MlflowClient' is not defined. For full traceback, set logging level to debug.. Tracing works with full mlflow package installed.

Tracking information

REPLACE_ME

Code to reproduce issue

import logging
import os

import azure.identity
import mlflow
import openai

logging.basicConfig(level=logging.DEBUG)


def configure_tracing(databricks_host_url: str, experiment_name: str) -> None:
    """Configure MLflow for Databricks.

    This function sets the necessary environment variables for MLflow to work with Databricks.

    Args:
        databricks_host_url: The URL of the Databricks workspace.
        experiment_name: The name of the MLflow experiment.
    """
    os.environ["MLFLOW_TRACKING_URI"] = "databricks"
    os.environ["MLFLOW_EXPERIMENT_NAME"] = experiment_name
    os.environ["DATABRICKS_HOST"] = databricks_host_url
    os.environ["DATABRICKS_TOKEN"] = os.getenv("DATABRICKS_TOKEN")

    mlflow.openai.autolog()


configure_tracing(
    databricks_host_url=os.getenv("DATABRICKS_HOST_URL"),
    experiment_name=os.getenv("MLFLOW_EXPERIMENT_NAME"),
)

token_provider = azure.identity.get_bearer_token_provider(
    azure.identity.AzureCliCredential(),
    "https://cognitiveservices.azure.com/.default",
)

client = openai.AzureOpenAI(
    api_version=os.getenv("OPENAI_AZURE_API_VERSION"),
    azure_endpoint=os.getenv("OPENAI_AZURE_URL"),
    azure_deployment=os.getenv("OPENAI_MODEL"),
    azure_ad_token_provider=token_provider,
)

response = client.chat.completions.create(
        model=os.getenv("OPENAI_MODEL"),
        messages=[{"role": "user", "content": "What is the capital of Canada?"}],
        temperature=0.2,
        max_completion_tokens=100,
    )

Stack trace

2025/09/11 15:41:45 DEBUG mlflow.utils.autologging_utils: Invoked patched API '<class 'openai.resources.chat.completions.completions.Completions'>.create' for openai autologging with args '(<openai.resources.chat.completions.completions.Completions object at 0x770cdacd86e0>,)' and kwargs '{'model': 'gpt-4o-mini', 'messages': [{'role': 'user', 'content': 'What is the capital of Canada?'}], 'temperature': 0.2, 'max_completion_tokens': 100}'
2025/09/11 15:41:45 DEBUG mlflow.openai.autolog: Failed to import `BetaChatCompletions` or `BetaAsyncChatCompletions`
Traceback (most recent call last):
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/openai/autolog.py", line 202, in _get_span_type_and_message_format
    from openai.resources.beta.chat.completions import (
        AsyncCompletions as BetaAsyncChatCompletions,
    )
ModuleNotFoundError: No module named 'openai.resources.beta.chat'
2025/09/11 15:41:45 DEBUG mlflow.tracing.utils.environment: Git python package is not installed. Skipping git metadata resolution.
2025/09/11 15:41:45 DEBUG mlflow.tracing.utils: Failed to get attribute mlflow.experimentId with from span _Span(name="Completions", context=SpanContext(trace_id=0x7e25d1fe03c769b5db91998b9c8f90fb, span_id=0x4e9b185b4a46f51c, trace_flags=0x01, trace_state=[], is_remote=False)).
Traceback (most recent call last):
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracing/utils/__init__.py", line 263, in get_otel_attribute
    return json.loads(span.attributes.get(key))
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/uv/python/cpython-3.13.2-linux-x86_64-gnu/lib/python3.13/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
                    f'not {s.__class__.__name__}')
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
2025/09/11 15:41:45 WARNING mlflow.tracing.fluent: Failed to start span Completions: name 'MlflowClient' is not defined. For full traceback, set logging level to debug.
Traceback (most recent call last):
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracing/fluent.py", line 570, in start_span_no_context
    otel_span = provider.start_detached_span(
        name,
    ...<2 lines>...
        experiment_id=experiment_id,
    )
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracing/provider.py", line 121, in start_detached_span
    span = tracer.start_span(name, context=context, attributes=attributes, start_time=start_time_ns)
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 1178, in start_span
    span.start(start_time=start_time, parent_context=context)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 936, in start
    self._span_processor.on_start(self, parent_context=parent_context)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 171, in on_start
    sp.on_start(span, parent_context=parent_context)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracing/processor/base_mlflow.py", line 73, in on_start
    trace_info = self._start_trace(span)
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracing/processor/mlflow_v3.py", line 35, in _start_trace
    experiment_id = self._get_experiment_id_for_trace(root_span)
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracing/processor/base_mlflow.py", line 126, in _get_experiment_id_for_trace
    return _get_experiment_id()
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracking/fluent.py", line 3043, in _get_experiment_id
    return _get_experiment_id_from_env() or default_experiment_registry.get_experiment_id()
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/user/work/mlflow_tracing/.venv/lib/python3.13/site-packages/mlflow/tracking/fluent.py", line 3013, in _get_experiment_id_from_env
    exp = MlflowClient().get_experiment_by_name(experiment_name)
          ^^^^^^^^^^^^
NameError: name 'MlflowClient' is not defined

Other info / logs

REPLACE_ME

What component(s) does this bug affect?

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow model serving, deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/prompt: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting
  • area/docs: MLflow documentation pages

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tracingMLflow Tracing and its integrationsbugSomething isn't workinghas-closing-prThis issue has a closing PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions