Skip to content

AWS Bedrock Integration: Langtrace Python SDK fails to parse Cross Region Inference Model IDS or ARN #543

@prasadjSam

Description

@prasadjSam

When using the Langtrace Python SDK with AWS Bedrock and providing a cross-region model ID or an ARN (e.g., arn:aws:bedrock:us-east-1:<account_id>:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0, us.anthropic.claude-sonnet-4-20250514-v1:0) as the modelId, the SDK fails with an error:

Traceback (most recent call last):
  File "/opt/langtrace-app/call_bedrock.py", line 26, in <module>
    response = client.converse(
               ^^^^^^^^^^^^^^^^
  File "/opt/langtrace-app/langtrace-env/lib/python3.11/site-packages/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py", line 140, in traced_method
    (vendor, _) = modelId.split(".")
    ^^^^^^^^^^^

The issue originates from the assumption in the SDK code that modelId can always be split into two parts using vendor, model = modelId.split('.'), which breaks when the modelId is an ARN or contains multiple . (dots), as is the case for Bedrock inference profiles.
Steps to Reproduce:

Use the Langtrace Python SDK with boto3 to invoke Bedrock model using modelId as an ARN or a region-prefixed ID like us.anthropic.claude-3-haiku-20240307-v1:0.
Observe the crash due to unpacking error in the SDK.

Also cost calculation for AWS bedrock seems to be not supported.

Exception occured in cost calculation: type object 'SpanAttributes' has no attribute 'LLM_USAGE_COST'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions