Skip to content

Commit ed7262a

Browse files
Merge branch 'main' into fix/issue-16272-trace-name-overwrite-by-child-span
2 parents 9466895 + 3c91c3a commit ed7262a

193 files changed

Lines changed: 13074 additions & 539 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
persist-credentials: false
2626
- name: Install uv and set Python version
27-
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
27+
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
2828
with:
2929
version: "0.11.2"
3030
python-version: "3.13"
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
persist-credentials: false
4343
- name: Install uv and set Python version
44-
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
44+
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
4545
with:
4646
version: "0.11.2"
4747
python-version: "3.13"
@@ -82,7 +82,7 @@ jobs:
8282
with:
8383
persist-credentials: false
8484
- name: Install uv and set Python version
85-
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
85+
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
8686
with:
8787
version: "0.11.2"
8888
python-version: ${{ matrix.python-version }}
@@ -145,7 +145,7 @@ jobs:
145145
with:
146146
persist-credentials: false
147147
- name: Install uv and set Python version
148-
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
148+
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
149149
with:
150150
version: "0.11.2"
151151
python-version: "3.13"

‎.github/workflows/codeql.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161

6262
# Initializes the CodeQL tools for scanning.
6363
- name: Initialize CodeQL
64-
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
64+
uses: github/codeql-action/init@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
6565
with:
6666
languages: ${{ matrix.language }}
6767
build-mode: ${{ matrix.build-mode }}
@@ -89,6 +89,6 @@ jobs:
8989
exit 1
9090
9191
- name: Perform CodeQL Analysis
92-
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
92+
uses: github/codeql-action/analyze@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
9393
with:
9494
category: "/language:${{matrix.language}}"

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
persist-credentials: false
9898

9999
- name: Install uv and set Python version
100-
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
100+
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
101101
with:
102102
version: "0.11.2"
103103
python-version: "3.12"

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ If you change CI bootstrap:
147147
## Python-Specific Notes
148148

149149
- Exception messages should not inline f-string literals in the `raise` statement. Build the message in a variable first.
150+
- Logging calls must not use f-strings; pass lazy `%`-style args (`langfuse_logger.debug("span=%s", name)`), enforced by ruff `G004`. Arguments are still evaluated eagerly, so guard an expensive one with `langfuse_logger.isEnabledFor(logging.DEBUG)`.
150151
- Prefer ASCII-only edits unless the file already uses Unicode or Unicode is clearly required.
151152

152153
## Release And Docs

‎code_review.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Use this checklist for `/review`, PR review, or self-review before handoff.
3333
## Python Style
3434

3535
- Exception messages should not inline f-string literals in `raise` statements; build the message in a variable first.
36+
- Logging calls should use lazy `%`-style args, not f-strings (ruff `G004`). Flag any logging argument that is expensive to compute and is not behind an `isEnabledFor` guard.
3637
- Keep edits ASCII-only unless the file already uses Unicode or Unicode is clearly required.
3738
- Keep changes scoped; avoid opportunistic refactors.
3839
- Never commit secrets or credentials.

‎langfuse/_client/client.py‎

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ def start_as_current_observation(
12031203

12041204
# This should never be reached since all valid types are handled above
12051205
langfuse_logger.warning(
1206-
f"Unknown observation type: {as_type}, falling back to span"
1206+
"Unknown observation type: %s, falling back to span", as_type
12071207
)
12081208
return self._start_as_current_otel_span_with_processed_media(
12091209
as_type="span",
@@ -1748,12 +1748,16 @@ def _create_remote_parent_span(
17481748
) -> Any:
17491749
if not self._is_valid_trace_id(trace_id):
17501750
langfuse_logger.warning(
1751-
f"Passed trace ID '{trace_id}' is not a valid 32 lowercase hex char Langfuse trace id. Ignoring trace ID."
1751+
"Passed trace ID '%s' is not a valid 32 lowercase hex char Langfuse trace "
1752+
"id. Ignoring trace ID.",
1753+
trace_id,
17521754
)
17531755

17541756
if parent_span_id and not self._is_valid_span_id(parent_span_id):
17551757
langfuse_logger.warning(
1756-
f"Passed span ID '{parent_span_id}' is not a valid 16 lowercase hex char Langfuse span id. Ignoring parent span ID."
1758+
"Passed span ID '%s' is not a valid 16 lowercase hex char Langfuse span "
1759+
"id. Ignoring parent span ID.",
1760+
parent_span_id,
17571761
)
17581762

17591763
int_trace_id = int(trace_id, 16)
@@ -2065,7 +2069,11 @@ def create_score(
20652069

20662070
except Exception as e:
20672071
langfuse_logger.exception(
2068-
f"Error creating score: Failed to process score event for trace_id={trace_id}, name={name}. Error: {e}"
2072+
"Error creating score: Failed to process score event for trace_id=%s, "
2073+
"name=%s. Error: %s",
2074+
trace_id,
2075+
name,
2076+
e,
20692077
)
20702078

20712079
def _create_trace_tags_via_ingestion(
@@ -2098,7 +2106,10 @@ def _create_trace_tags_via_ingestion(
20982106
self._resources.add_trace_task(event)
20992107
except Exception as e:
21002108
langfuse_logger.exception(
2101-
f"Error updating trace tags: Failed to process trace update event for trace_id={trace_id}. Error: {e}"
2109+
"Error updating trace tags: Failed to process trace update event for "
2110+
"trace_id=%s. Error: %s",
2111+
trace_id,
2112+
e,
21022113
)
21032114

21042115
@overload
@@ -2181,7 +2192,12 @@ def score_current_span(
21812192
observation_id = self._get_otel_span_id(current_span)
21822193

21832194
langfuse_logger.info(
2184-
f"Score: Creating score name='{name}' value={value} for current span ({observation_id}) in trace {trace_id}"
2195+
"Score: Creating score name='%s' value=%s for current span (%s) in trace "
2196+
"%s",
2197+
name,
2198+
value,
2199+
observation_id,
2200+
trace_id,
21852201
)
21862202

21872203
self.create_score(
@@ -2279,7 +2295,10 @@ def score_current_trace(
22792295
trace_id = self._get_otel_trace_id(current_span)
22802296

22812297
langfuse_logger.info(
2282-
f"Score: Creating score name='{name}' value={value} for entire trace {trace_id}"
2298+
"Score: Creating score name='%s' value=%s for entire trace %s",
2299+
name,
2300+
value,
2301+
trace_id,
22832302
)
22842303

22852304
self.create_score(
@@ -2490,7 +2509,7 @@ def get_dataset(
24902509
DatasetClient: The dataset with the given name.
24912510
"""
24922511
try:
2493-
langfuse_logger.debug(f"Getting datasets {name}")
2512+
langfuse_logger.debug("Getting datasets %s", name)
24942513
dataset = self.api.datasets.get(dataset_name=self._url_encode(name))
24952514

24962515
dataset_items: List[DatasetItem] = []
@@ -2818,7 +2837,7 @@ async def _run_experiment_async(
28182837
dataset_version: Optional[datetime] = None,
28192838
) -> ExperimentResult:
28202839
langfuse_logger.debug(
2821-
f"Starting experiment '{name}' run '{run_name}' with {len(data)} items"
2840+
"Starting experiment '%s' run '%s' with %s items", name, run_name, len(data)
28222841
)
28232842

28242843
shared_fallback_experiment_id = self._create_observation_id()
@@ -2850,7 +2869,7 @@ async def process_item(item: ExperimentItem) -> ExperimentItemResult:
28502869
valid_results: List[ExperimentItemResult] = []
28512870
for i, result in enumerate(item_results):
28522871
if isinstance(result, Exception):
2853-
langfuse_logger.error(f"Item {i} failed: {result}")
2872+
langfuse_logger.error("Item %s failed: %s", i, result)
28542873
elif isinstance(result, ExperimentItemResult):
28552874
valid_results.append(result) # type: ignore
28562875

@@ -2863,7 +2882,7 @@ async def process_item(item: ExperimentItem) -> ExperimentItemResult:
28632882
)
28642883
run_evaluations.extend(evaluations)
28652884
except Exception as e:
2866-
langfuse_logger.error(f"Run evaluator failed: {e}")
2885+
langfuse_logger.error("Run evaluator failed: %s", e)
28672886

28682887
# Generate dataset run URL if applicable
28692888
dataset_run_id = next(
@@ -2908,7 +2927,7 @@ async def process_item(item: ExperimentItem) -> ExperimentItemResult:
29082927
)
29092928

29102929
except Exception as e:
2911-
langfuse_logger.error(f"Failed to store run evaluation: {e}")
2930+
langfuse_logger.error("Failed to store run evaluation: %s", e)
29122931

29132932
# Flush scores and traces
29142933
self.flush()
@@ -3030,7 +3049,7 @@ async def _process_experiment_item(
30303049

30313050
except Exception as e:
30323051
langfuse_logger.error(
3033-
f"Failed to create dataset run item: {e}"
3052+
"Failed to create dataset run item: %s", e
30343053
)
30353054

30363055
experiment_id = dataset_run_id or fallback_experiment_id
@@ -3129,7 +3148,7 @@ async def _process_experiment_item(
31293148
level="ERROR",
31303149
status_message=str(e),
31313150
)
3132-
langfuse_logger.error(f"Evaluator failed: {e}")
3151+
langfuse_logger.error("Evaluator failed: %s", e)
31333152
continue
31343153

31353154
evaluations.extend(eval_results)
@@ -3148,7 +3167,7 @@ async def _process_experiment_item(
31483167
)
31493168
except Exception as e:
31503169
langfuse_logger.error(
3151-
f"Failed to store evaluation: {e}"
3170+
"Failed to store evaluation: %s", e
31523171
)
31533172

31543173
if composite_evaluator and evaluations:
@@ -3196,7 +3215,7 @@ async def _process_experiment_item(
31963215
status_message=str(e),
31973216
)
31983217
langfuse_logger.error(
3199-
f"Composite evaluator failed: {e}"
3218+
"Composite evaluator failed: %s", e
32003219
)
32013220
composite_evals = []
32023221

@@ -3215,7 +3234,7 @@ async def _process_experiment_item(
32153234
)
32163235
except Exception as e:
32173236
langfuse_logger.error(
3218-
f"Failed to store composite evaluation: {e}"
3237+
"Failed to store composite evaluation: %s", e
32193238
)
32203239

32213240
evaluation_span.update(
@@ -3495,7 +3514,7 @@ def auth_check(self) -> bool:
34953514
try:
34963515
projects = self.api.projects.get()
34973516
langfuse_logger.debug(
3498-
f"Auth check successful, found {len(projects.data)} projects"
3517+
"Auth check successful, found %s projects", len(projects.data)
34993518
)
35003519
if len(projects.data) == 0:
35013520
raise Exception(
@@ -3505,7 +3524,7 @@ def auth_check(self) -> bool:
35053524

35063525
except AttributeError as e:
35073526
langfuse_logger.warning(
3508-
f"Auth check failed: Client not properly initialized. Error: {e}"
3527+
"Auth check failed: Client not properly initialized. Error: %s", e
35093528
)
35103529
return False
35113530

@@ -3535,7 +3554,7 @@ def create_dataset(
35353554
Dataset: The created dataset as returned by the Langfuse API.
35363555
"""
35373556
try:
3538-
langfuse_logger.debug(f"Creating datasets {name}")
3557+
langfuse_logger.debug("Creating datasets %s", name)
35393558

35403559
result = self.api.datasets.create(
35413560
name=name,
@@ -3596,7 +3615,7 @@ def create_dataset_item(
35963615
```
35973616
"""
35983617
try:
3599-
langfuse_logger.debug(f"Creating dataset item for dataset {dataset_name}")
3618+
langfuse_logger.debug("Creating dataset item for dataset %s", dataset_name)
36003619

36013620
# Media uploads must reference the (dataset, item) they belong to, and
36023621
# the item need not exist yet — so settle on the item id up front and
@@ -3771,7 +3790,8 @@ def _replace_json_path_value(
37713790
return json_path.set_value_at_path(value, path, replacement)
37723791
except Exception as e:
37733792
langfuse_logger.warning(
3774-
f"Failed to hydrate dataset media reference at JSONPath {path}",
3793+
"Failed to hydrate dataset media reference at JSONPath %s",
3794+
path,
37753795
exc_info=e,
37763796
)
37773797

@@ -3916,12 +3936,12 @@ def get_prompt(
39163936
max_retries, default_max_retries=2, max_retries_upper_bound=4
39173937
)
39183938

3919-
langfuse_logger.debug(f"Getting prompt '{cache_key}'")
3939+
langfuse_logger.debug("Getting prompt '%s'", cache_key)
39203940
cached_prompt = self._resources.prompt_cache.get(cache_key)
39213941

39223942
if cached_prompt is None or cache_ttl_seconds == 0:
39233943
langfuse_logger.debug(
3924-
f"Prompt '{cache_key}' not found in cache or caching disabled."
3944+
"Prompt '%s' not found in cache or caching disabled.", cache_key
39253945
)
39263946
try:
39273947
return self._fetch_prompt_and_update_cache(
@@ -3935,7 +3955,9 @@ def get_prompt(
39353955
except Exception as e:
39363956
if fallback:
39373957
langfuse_logger.warning(
3938-
f"Returning fallback prompt for '{cache_key}' due to fetch error: {e}"
3958+
"Returning fallback prompt for '%s' due to fetch error: %s",
3959+
cache_key,
3960+
e,
39393961
)
39403962

39413963
fallback_client_args: Dict[str, Any] = {
@@ -3963,10 +3985,12 @@ def get_prompt(
39633985
raise e
39643986

39653987
if cached_prompt.is_expired():
3966-
langfuse_logger.debug(f"Stale prompt '{cache_key}' found in cache.")
3988+
langfuse_logger.debug("Stale prompt '%s' found in cache.", cache_key)
39673989
try:
39683990
# refresh prompt in background thread, refresh_prompt deduplicates tasks
3969-
langfuse_logger.debug(f"Refreshing prompt '{cache_key}' in background.")
3991+
langfuse_logger.debug(
3992+
"Refreshing prompt '%s' in background.", cache_key
3993+
)
39703994

39713995
def refresh_task() -> None:
39723996
self._fetch_prompt_and_update_cache(
@@ -3984,14 +4008,17 @@ def refresh_task() -> None:
39844008
refresh_task,
39854009
)
39864010
langfuse_logger.debug(
3987-
f"Returning stale prompt '{cache_key}' from cache."
4011+
"Returning stale prompt '%s' from cache.", cache_key
39884012
)
39894013
# return stale prompt
39904014
return cached_prompt.value
39914015

39924016
except Exception as e:
39934017
langfuse_logger.warning(
3994-
f"Error when refreshing cached prompt '{cache_key}', returning cached version. Error: {e}"
4018+
"Error when refreshing cached prompt '%s', returning cached version. "
4019+
"Error: %s",
4020+
cache_key,
4021+
e,
39954022
)
39964023
# creation of refresh prompt task failed, return stale prompt
39974024
return cached_prompt.value
@@ -4009,7 +4036,7 @@ def _fetch_prompt_and_update_cache(
40094036
fetch_timeout_seconds: Optional[int],
40104037
) -> PromptClient:
40114038
cache_key = PromptCache.generate_cache_key(name, version=version, label=label)
4012-
langfuse_logger.debug(f"Fetching prompt '{cache_key}' from server...")
4039+
langfuse_logger.debug("Fetching prompt '%s' from server...", cache_key)
40134040

40144041
try:
40154042

@@ -4043,15 +4070,15 @@ def fetch_prompts() -> Any:
40434070

40444071
except NotFoundError as not_found_error:
40454072
langfuse_logger.warning(
4046-
f"Prompt '{cache_key}' not found during refresh, evicting from cache."
4073+
"Prompt '%s' not found during refresh, evicting from cache.", cache_key
40474074
)
40484075
if self._resources is not None:
40494076
self._resources.prompt_cache.delete(cache_key)
40504077
raise not_found_error
40514078

40524079
except Exception as e:
40534080
langfuse_logger.error(
4054-
f"Error while fetching prompt '{cache_key}': {str(e)}"
4081+
"Error while fetching prompt '%s': %s", cache_key, str(e)
40554082
)
40564083
raise e
40574084

@@ -4128,7 +4155,7 @@ def create_prompt(
41284155
ChatPromptClient: The prompt if type argument is 'chat'.
41294156
"""
41304157
try:
4131-
langfuse_logger.debug(f"Creating prompt {name=}, {labels=}")
4158+
langfuse_logger.debug("Creating prompt name=%r, labels=%r", name, labels)
41324159

41334160
if type == "chat":
41344161
if not isinstance(prompt, list):

0 commit comments

Comments
 (0)