Skip to content

[BUG]: NoneType is not subscriptable when used with mlflow.langchain.autolog #14218

@tschutte

Description

@tschutte

Tracer Version(s)

3.11.2

Python Version(s)

3.12

Pip Version(s)

pip 24.0

Bug Report

We are running langchain + mlflow autolog within a Lambda function to issue prediction requests to a backend LLM endpoint. When ddtrace is added to the Lambda function (using the process for AWS SAM as described in the docs) we receive an error during the Lambda init.

The result is a stacktrace that looks to be an issue patching the mlflow.autolog() call which occurs during Lambda init. Note that init fails, so the Lambda never fully deploys and we cannot verify any additional functionality.

Reproduction Code

Added the following to our AWS SAM template.yaml

Transform:
  - AWS::Serverless-2016-10-31
  - Name: DatadogServerless
    Parameters:
      pythonLayerVersion: "113"
      stackName: !Ref "AWS::StackName"
      forwarderArn: "arn:aws:lambda:us-east-1:<redacted>:function:DatadogIntegration-ForwarderStack-XIZ2PT-Forwarder-TIJAFwmhEPiJ"
      service: "<redacted>"
try:
    import json
    import mlflow
    from generation import get_available_chains
    import os
    from generation.config import DATABRICKS_HOST, MLFLOW_EXPERIMENT_NAME, get_aws_secret
    from ddtrace import tracer
except Exception as e:
    print(f"Error importing modules: {e}")
    raise

print("Import initialized successfully")

secrets = get_aws_secret()
databricks_token = secrets.get("DATABRICKS_TOKEN")
os.environ["DATABRICKS_TOKEN"] = databricks_token
os.environ["DATABRICKS_HOST"] = DATABRICKS_HOST

mlflow.set_tracking_uri("databricks")
mlflow.set_experiment(experiment_name=MLFLOW_EXPERIMENT_NAME)
mlflow.langchain.autolog()

def lambda_handler(event, context):
     # Do more stuff, init never makes it this far

Error Logs

[ERROR] 2025-08-04T12:46:04.813Z Error patching handler. Timeout spans will not be generated.
Traceback (most recent call last):
File "/var/task/ddtrace/contrib/internal/aws_lambda/patch.py", line 238, in patch
handler, handler_module, wrapper = _get_handler_and_module()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/ddtrace/contrib/internal/aws_lambda/patch.py", line 178, in _get_handler_and_module
handler_module = import_module(modified_mod_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "./python/lib/python3.12/site-packages/datadog_lambda/cold_start.py", line 117, in wrapped_method
File "", line 999, in exec_module
File "", line 488, in _call_with_frames_removed
File "/var/task/app.py", line 21, in
mlflow.langchain.autolog()
File "/var/task/mlflow/utils/autologging_utils/init.py", line 96, in wrapper
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/var/task/mlflow/utils/autologging_utils/init.py", line 472, in autolog
return _autolog(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/mlflow/langchain/init.py", line 1071, in autolog
if pkg.metadata["Name"].startswith("langchain"):
~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Libraries in Use

mlflow-skinny~=2.22.0 # Pinned to match DBR 17.0 ML
langchain==0.3.23 # Pinned to latest version compatible with mlflow 2.22.*
langchain-openai
boto3
botocore
pandas~=2.2.3
ddtrace

Operating System

AWS Lambda

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions