Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Problem with langfuse_tags when using litellm proxy with langfuse integration #7801

Closed
yuu341 opened this issue Jan 16, 2025 · 0 comments · Fixed by #7825
Closed

[Bug]: Problem with langfuse_tags when using litellm proxy with langfuse integration #7801

yuu341 opened this issue Jan 16, 2025 · 0 comments · Fixed by #7825
Labels
bug Something isn't working

Comments

@yuu341
Copy link
Contributor

yuu341 commented Jan 16, 2025

What happened?

When integrating litellm proxy with langfuse, specifying langfuse_tags in the HTTP header is expected to populate the Tags field in langfuse. However, in practice, attempting this results in the proxy crashing with the following error message:

07:52:12 - LiteLLM:ERROR: langfuse.py:731 - Langfuse Layer Error - Traceback (most recent call last):
  File "/home/ubuntu/work/xxx/venv/lib/python3.12/site-packages/litellm/integrations/langfuse/langfuse.py", line 499, in _log_langfuse_v2
    tags.append(f"{key}:{value}")
    ^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'append'

This error occurs at line 500 in litellm/integrations/langfuse/langfuse.py and seems to be caused by the tags being treated as a string instead of being parsed into a list.

Proposed Solution:
I made the following change, which resolved the issue. By ensuring tags is properly parsed as a JSON list, the error no longer occurs.
Before:

tags = metadata.pop("tags", []) if supports_tags else []

After

import json
tags = json.loads(metadata.pop("tags", "[]")) if supports_tags else []

Next Steps:
I plan to submit a pull request with this fix to address the issue. Please let me know if there are additional steps or considerations for this fix.

Relevant log output

The error behavior differs when litellm_config.yaml contains the following setting:

litellm_settings:
  langfuse_default_tags: ["cache_hit", "cache_key", "proxy_base_url", "user_api_key_alias", "user_api_key_user_id", "user_api_key_user_email", "user_api_key_team_alias", "semantic-similarity", "proxy_base_url"]


Without setting langfuse_default_tags:
When this setting is not specified, the following error occurs:
```text
07:48:27 - LiteLLM:DEBUG: langfuse.py:594 - trace: 0
1 validation error for TraceBody
tags
  value is not a valid list (type=type_error.list)
Traceback (most recent call last):
  File "/home/ubuntu/work/xxx/venv/lib/python3.12/site-packages/langfuse/client.py", line 1432, in trace
    new_body = TraceBody(**new_dict)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/work/xxx/venv/lib/python3.12/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for TraceBody
tags
  value is not a valid list (type=type_error.list)

With langfuse_default_tags set:
When the langfuse_default_tags setting is specified, the following error occurs instead:

07:52:12 - LiteLLM:ERROR: langfuse.py:731 - Langfuse Layer Error - Traceback (most recent call last):
  File "/home/ubuntu/work/xxx/venv/lib/python3.12/site-packages/litellm/integrations/langfuse/langfuse.py", line 499, in _log_langfuse_v2
    tags.append(f"{key}:{value}")
    ^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'append'


### Are you a ML Ops Team?

No

### What LiteLLM version are you on ?

v1.58.1

### Twitter / LinkedIn details

_No response_
@yuu341 yuu341 added the bug Something isn't working label Jan 16, 2025
yuu341 added a commit to yuu341/litellm that referenced this issue Jan 17, 2025
ishaan-jaff pushed a commit that referenced this issue Jan 18, 2025
#7825)

* Fix: Problem with langfuse_tags when using litellm proxy with langfuse integration (#7801)

* Refactor: Create method get_langfuse_tags

* Fix: Exception Handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant