Skip to content

fix(logger): auto-convert non-string metadata values to strings#488

Draft
calebe94 wants to merge 1 commit intomainfrom
sc-54947/fix-int-bool-spans-not-logged
Draft

fix(logger): auto-convert non-string metadata values to strings#488
calebe94 wants to merge 1 commit intomainfrom
sc-54947/fix-int-bool-spans-not-logged

Conversation

@calebe94
Copy link

@calebe94 calebe94 commented Feb 27, 2026

User description

Added auto-conversion of non-string metadata and dataset_metadata values to strings to ensure consistent logging behavior across all span methods and the add_single_llm_span_trace API.

Included unit tests to prevent future regressions.

Shortcut:
sc-54947

Description:

Fixes sc-54947 - passing int or bool metadata values to any span method (add_llm_span, add_tool_span, etc.) caused the span to be silently dropped with no error surfaced to the user.

start_trace() already auto-converts non-string metadata values to strings via _convert_metadata_value(), but none of the span methods did. When a user passed metadata like {"count": 1, "enabled": True}, the raw values reached the Pydantic BaseStep model which expects Dict[str, str], triggering a ValidationError. The @warn_catch_exception decorator then swallowed the error and returned None - the span was never created, and the user saw nothing.

Reproduction:

logger.add_llm_span(
    input="input content",
    output="output",
    model="gpt-4o",
    metadata={"intMeta": 1, "boolMeta": True, "strMeta": "physics"}
)
# span silently dropped - returns None

Fix

Applied the same conversion pattern from start_trace() to all 7 span methods:

  • add_single_llm_span_trace() (+ dataset_metadata)
  • add_llm_span()
  • add_retriever_span()
  • add_tool_span()
  • add_protect_span()
  • add_workflow_span()
  • add_agent_span()

For each method:

  1. Updated type hint: dict[str, str] -> dict[str, MetadataValue] (where `MetadataValue = str | bool | int | float | None)
  2. Added auto-conversion block before kwargs construction:
      if metadata:
       metadata = {k: GalileoLogger._convert_metadata_value(v) for k, v in metadata.items()}

Tests:

  • Unit Tests Added
  • E2E Test Added (if it's a user-facing feature, or fixing a bug)

Generated description

Below is a concise technical summary of the changes proposed in this PR:
Ensures that non-string metadata values are automatically converted to strings across all span logging methods to prevent silent failures caused by validation errors. This change aligns the behavior of various span types with the existing trace logging logic and includes comprehensive regression tests.

TopicDetails
Regression Testing Add unit tests to verify that add_llm_span, add_tool_span, and other span methods correctly handle and stringify diverse metadata types without dropping spans.
Modified files (1)
  • tests/test_logger_batch.py
Latest Contributors(2)
UserCommitDate
mason@galileo.aifeat-allow-session-met...February 13, 2026
fernando.correia@galil...fix-logger-restore-res...February 11, 2026
Metadata Conversion Implement auto-conversion of int, bool, and float metadata values to strings in GalileoLogger span methods to ensure compatibility with the internal schema.
Modified files (1)
  • src/galileo/logger/logger.py
Latest Contributors(2)
UserCommitDate
mason@galileo.aifeat-allow-session-met...February 13, 2026
fernando.correia@galil...fix-logger-restore-res...February 11, 2026
This pull request is reviewed by Baz. Review like a pro on (Baz).

Added auto-conversion of non-string metadata and dataset_metadata values to strings to ensure consistent logging behavior across all span methods and the add_single_llm_span_trace API.

Included unit tests to prevent future regressions.
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.85%. Comparing base (bdcdede) to head (b3fd60f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #488      +/-   ##
==========================================
+ Coverage   81.82%   81.85%   +0.03%     
==========================================
  Files          96       96              
  Lines        9223     9239      +16     
==========================================
+ Hits         7547     7563      +16     
  Misses       1676     1676              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant