Skip to content

Comments

fix(langchain): Extract model name from 'model' field for non-OpenAI providers#125

Open
NikitaVoitov wants to merge 1 commit intosignalfx:mainfrom
NikitaVoitov:fix/model-name-extraction
Open

fix(langchain): Extract model name from 'model' field for non-OpenAI providers#125
NikitaVoitov wants to merge 1 commit intosignalfx:mainfrom
NikitaVoitov:fix/model-name-extraction

Conversation

@NikitaVoitov
Copy link

Summary

Fixes model name extraction to support providers that use model instead of model_name in invocation params. This enables proper model identification for Snowflake Cortex, Anthropic, Google, and other non-OpenAI providers.

Fixes #124

The Bug (Before)

Span name: chat unknown_model
gen_ai.request.model: unknown_model

The Fix (After)

Span name: chat claude-3-5-sonnet
gen_ai.request.model: claude-3-5-sonnet

Changes

callback_handler.py

Updated model name extraction with fallback chain:

# Before - only checks OpenAI convention
model = invocation_params.get("model_name", "unknown_model")

# After - fallback chain supporting multiple providers
model = (
    invocation_params.get("model_name") or  # OpenAI
    invocation_params.get("model") or        # Snowflake, Anthropic, Google
    "unknown_model"
)

Testing

  • test_model_name_extraction_from_model_field - verifies model field extraction
  • test_model_name_extraction_priority - verifies model_name takes precedence over model
  • test_model_name_fallback_to_unknown - verifies fallback when neither field present
  • All existing tests pass

Files Changed

File Changes
instrumentation-genai/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py Updated model extraction with fallback chain
instrumentation-genai/opentelemetry-instrumentation-langchain/tests/test_callback_handler_agent.py Added 3 tests for model name extraction

…providers

Fixes model name extraction for providers like ChatSnowflake and ChatAnthropic
that use 'model' instead of 'model_name' in invocation_params.

Priority order:
1. invocation_params.model_name (OpenAI convention)
2. invocation_params.model (Snowflake, Anthropic)
3. metadata.model_name
4. metadata.ls_model_name (LangSmith)

Tests added:
- test_model_name_extraction_from_model_field
- test_model_name_extraction_priority
- test_model_name_fallback_to_unknown
@NikitaVoitov NikitaVoitov requested review from a team as code owners January 13, 2026 12:53
@github-actions
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@NikitaVoitov
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@zhirafovod zhirafovod self-assigned this Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] gen_ai.request.model shows 'unknown_model' for non-OpenAI providers

2 participants