From 7d4fe44c7142bb7aa497c267ad9d5fab6e4e065b Mon Sep 17 00:00:00 2001 From: Steve Farthing <516498+sfarthin@users.noreply.github.com> Date: Wed, 7 May 2025 19:10:24 -0400 Subject: [PATCH 1/2] Upgrade langfuse sdk and enable passing generation params thru metadata (#10600) * Langfuse Upgrade and allow passing generation params like environment * remove comments --------- Co-authored-by: Steve Farthing --- .circleci/config.yml | 8 ++++---- litellm/integrations/langfuse/langfuse.py | 8 ++++++++ poetry.lock | 6 +++--- requirements.txt | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9fb1aeaf4f55..0b9ab5998ef2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,7 +80,7 @@ jobs: pip install langchain pip install lunary==0.2.5 pip install "azure-identity==1.16.1" - pip install "langfuse==2.45.0" + pip install "langfuse==2.60.4" pip install "logfire==0.29.0" pip install numpydoc pip install traceloop-sdk==0.21.1 @@ -199,7 +199,7 @@ jobs: pip install langchain pip install lunary==0.2.5 pip install "azure-identity==1.16.1" - pip install "langfuse==2.45.0" + pip install "langfuse==2.60.4" pip install "logfire==0.29.0" pip install numpydoc pip install traceloop-sdk==0.21.1 @@ -305,7 +305,7 @@ jobs: pip install langchain pip install lunary==0.2.5 pip install "azure-identity==1.16.1" - pip install "langfuse==2.45.0" + pip install "langfuse==2.60.4" pip install "logfire==0.29.0" pip install numpydoc pip install traceloop-sdk==0.21.1 @@ -559,7 +559,7 @@ jobs: pip install langchain pip install lunary==0.2.5 pip install "azure-identity==1.16.1" - pip install "langfuse==2.45.0" + pip install "langfuse==2.60.4" pip install "logfire==0.29.0" pip install numpydoc pip install traceloop-sdk==0.21.1 diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py index d0472ee6383e..4f95531baa25 100644 --- a/litellm/integrations/langfuse/langfuse.py +++ b/litellm/integrations/langfuse/langfuse.py @@ -691,6 +691,14 @@ def _log_langfuse_v2( # noqa: PLR0915 "version": clean_metadata.pop("version", None), } + # Promote every metadata entry whose key starts with "generation_" + for key in list( + filter(lambda k: k.startswith("generation_"), clean_metadata.keys()) + ): + stripped = key.replace("generation_", "") + if stripped not in generation_params: + generation_params[stripped] = clean_metadata[key] + parent_observation_id = metadata.get("parent_observation_id", None) if parent_observation_id is not None: generation_params["parent_observation_id"] = parent_observation_id diff --git a/poetry.lock b/poetry.lock index d8464199c945..f162f191406f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1084,15 +1084,15 @@ grpcio-gcp = ["grpcio-gcp (>=0.2.2,<1.0.dev0)"] [[package]] name = "google-auth" -version = "2.39.0" +version = "2.40.0" description = "Google Authentication Library" optional = true python-versions = ">=3.7" groups = ["main"] markers = "extra == \"extra-proxy\"" files = [ - {file = "google_auth-2.39.0-py2.py3-none-any.whl", hash = "sha256:0150b6711e97fb9f52fe599f55648950cc4540015565d8fbb31be2ad6e1548a2"}, - {file = "google_auth-2.39.0.tar.gz", hash = "sha256:73222d43cdc35a3aeacbfdcaf73142a97839f10de930550d89ebfe1d0a00cde7"}, + {file = "google_auth-2.40.0-py2.py3-none-any.whl", hash = "sha256:dc3a5078acb1043c3e43685c22d628afe40af8559cf561de388e0c939280fcc8"}, + {file = "google_auth-2.40.0.tar.gz", hash = "sha256:c277cf39f7c192d8540eb6331c08b5a0796e8041af8343ae73dd6b269732ca6c"}, ] [package.dependencies] diff --git a/requirements.txt b/requirements.txt index 28056869e24f..224cc91d22cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ anthropic[vertex]==0.21.3 mcp==1.5.0 # for MCP server google-generativeai==0.5.0 # for vertex ai calls async_generator==1.10.0 # for async ollama calls -langfuse==2.45.0 # for langfuse self-hosted logging +langfuse==2.60.4 # for langfuse self-hosted logging prometheus_client==0.20.0 # for /metrics endpoint on proxy ddtrace==2.19.0 # for advanced DD tracing / profiling orjson==3.10.12 # fast /embedding responses From eb2c0ab2063340cb90520e8c6c02832b13d270d9 Mon Sep 17 00:00:00 2001 From: Steve Farthing Date: Mon, 12 May 2025 08:34:29 -0400 Subject: [PATCH 2/2] URL fix --- litellm/proxy/example_config_yaml/oai_misc_config.yaml | 2 +- tests/local_testing/test_pass_through_endpoints.py | 2 +- tests/logging_callback_tests/test_langfuse_e2e_test.py | 2 +- tests/proxy_unit_tests/test_proxy_server.py | 4 ++-- tests/proxy_unit_tests/test_proxy_utils.py | 4 ++-- tests/test_team_logging.py | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/litellm/proxy/example_config_yaml/oai_misc_config.yaml b/litellm/proxy/example_config_yaml/oai_misc_config.yaml index 1191e054ef88..779c8d3c3f44 100644 --- a/litellm/proxy/example_config_yaml/oai_misc_config.yaml +++ b/litellm/proxy/example_config_yaml/oai_misc_config.yaml @@ -38,7 +38,7 @@ litellm_settings: failure_callback: ["langfuse"] langfuse_public_key: os.environ/LANGFUSE_PROJECT2_PUBLIC # Project 2 langfuse_secret: os.environ/LANGFUSE_PROJECT2_SECRET # Project 2 - langfuse_host: https://us.cloud.langfuse.com + langfuse_host: https://cloud.langfuse.com # For /fine_tuning/jobs endpoints finetune_settings: diff --git a/tests/local_testing/test_pass_through_endpoints.py b/tests/local_testing/test_pass_through_endpoints.py index ae9644afb81d..4f9c0e177d7a 100644 --- a/tests/local_testing/test_pass_through_endpoints.py +++ b/tests/local_testing/test_pass_through_endpoints.py @@ -261,7 +261,7 @@ async def test_aaapass_through_endpoint_pass_through_keys_langfuse( pass_through_endpoints = [ { "path": "/api/public/ingestion", - "target": "https://us.cloud.langfuse.com/api/public/ingestion", + "target": "https://cloud.langfuse.com/api/public/ingestion", "auth": auth, "custom_auth_parser": "langfuse", "headers": { diff --git a/tests/logging_callback_tests/test_langfuse_e2e_test.py b/tests/logging_callback_tests/test_langfuse_e2e_test.py index b46d8764dd71..71bafcb78366 100644 --- a/tests/logging_callback_tests/test_langfuse_e2e_test.py +++ b/tests/logging_callback_tests/test_langfuse_e2e_test.py @@ -158,7 +158,7 @@ async def _verify_langfuse_call( print(f"URL: {url}") print(f"Request Body: {json.dumps(actual_request_body, indent=4)}") - assert url == "https://us.cloud.langfuse.com/api/public/ingestion" + assert url == "https://cloud.langfuse.com/api/public/ingestion" assert_langfuse_request_matches_expected( actual_request_body, expected_file_name, diff --git a/tests/proxy_unit_tests/test_proxy_server.py b/tests/proxy_unit_tests/test_proxy_server.py index dda39d2bd512..ad5c12e09e28 100644 --- a/tests/proxy_unit_tests/test_proxy_server.py +++ b/tests/proxy_unit_tests/test_proxy_server.py @@ -1347,7 +1347,7 @@ async def test_add_callback_via_key(prisma_client): "callback_vars": { "langfuse_public_key": "os.environ/LANGFUSE_PUBLIC_KEY", "langfuse_secret_key": "os.environ/LANGFUSE_SECRET_KEY", - "langfuse_host": "https://us.cloud.langfuse.com", + "langfuse_host": "https://cloud.langfuse.com", }, } ] @@ -1451,7 +1451,7 @@ async def test_add_callback_via_key_litellm_pre_call_utils( "callback_vars": { "langfuse_public_key": "my-mock-public-key", "langfuse_secret_key": "my-mock-secret-key", - "langfuse_host": "https://us.cloud.langfuse.com", + "langfuse_host": "https://cloud.langfuse.com", }, } ] diff --git a/tests/proxy_unit_tests/test_proxy_utils.py b/tests/proxy_unit_tests/test_proxy_utils.py index 1281d5086382..b0454ba15314 100644 --- a/tests/proxy_unit_tests/test_proxy_utils.py +++ b/tests/proxy_unit_tests/test_proxy_utils.py @@ -217,7 +217,7 @@ async def test_add_key_or_team_level_spend_logs_metadata_to_request( "callback_vars", [ { - "langfuse_host": "https://us.cloud.langfuse.com", + "langfuse_host": "https://cloud.langfuse.com", "langfuse_public_key": "pk-lf-9636b7a6-c066", "langfuse_secret_key": "sk-lf-7cc8b620", }, @@ -231,7 +231,7 @@ async def test_add_key_or_team_level_spend_logs_metadata_to_request( def test_dynamic_logging_metadata_key_and_team_metadata(callback_vars): os.environ["LANGFUSE_PUBLIC_KEY_TEMP"] = "pk-lf-9636b7a6-c066" os.environ["LANGFUSE_SECRET_KEY_TEMP"] = "sk-lf-7cc8b620" - os.environ["LANGFUSE_HOST_TEMP"] = "https://us.cloud.langfuse.com" + os.environ["LANGFUSE_HOST_TEMP"] = "https://cloud.langfuse.com" from litellm.proxy.proxy_server import ProxyConfig proxy_config = ProxyConfig() diff --git a/tests/test_team_logging.py b/tests/test_team_logging.py index 516b6fa13b46..50390748705d 100644 --- a/tests/test_team_logging.py +++ b/tests/test_team_logging.py @@ -100,7 +100,7 @@ async def test_aaateam_logging(): langfuse_client = langfuse.Langfuse( public_key=os.getenv("LANGFUSE_PROJECT1_PUBLIC"), secret_key=os.getenv("LANGFUSE_PROJECT1_SECRET"), - host="https://us.cloud.langfuse.com", + host="https://cloud.langfuse.com", ) await asyncio.sleep(30) @@ -128,7 +128,7 @@ async def test_team_2logging(): print(f"langfuse_public_key: {langfuse_public_key}") langfuse_secret_key = os.getenv("LANGFUSE_PROJECT2_SECRET") print(f"langfuse_secret_key: {langfuse_secret_key}") - langfuse_host = "https://us.cloud.langfuse.com" + langfuse_host = "https://cloud.langfuse.com" try: assert langfuse_public_key is not None @@ -181,7 +181,7 @@ async def test_team_2logging(): langfuse_client_1 = langfuse.Langfuse( public_key=os.getenv("LANGFUSE_PROJECT1_PUBLIC"), secret_key=os.getenv("LANGFUSE_PROJECT1_SECRET"), - host="https://us.cloud.langfuse.com", + host="https://cloud.langfuse.com", ) generations_team_1 = langfuse_client_1.get_generations(