Skip to content

fix(agno): normalize user_id and session_id with diagnostic logging (#3404) - #3719

Open
dlowzzxx wants to merge 1 commit into
Arize-ai:mainfrom
dlowzzxx:fix/agno-user-session-id-normalization-3404
Open

dlowzzxx wants to merge 1 commit into
Arize-ai:mainfrom
dlowzzxx:fix/agno-user-session-id-normalization-3404

Conversation

@dlowzzxx

Copy link
Copy Markdown
Contributor

Description

Fixes #3404.

In openinference-instrumentation-agno, user_id and session_id can be provided as integers (or other non-string types) by users or framework run arguments. Currently:

  1. Per the OpenInference semantic conventions, user.id and session.id are defined as strings. When non-string values like 123 were passed, they could be exported as non-string attribute values, causing downstream UIs (such as Phoenix or Arize) that expect string IDs to surface them as blank or unindexed.
  2. In truthiness checks like if user_id: and if session_id:, numeric zero (0) was silently dropped without any warning or attribute emission.
  3. No diagnostic feedback was logged when non-string types were received, making type mismatches difficult to diagnose.

Proposed Changes

  • Introduced _normalize_id(value: Any, name: str) -> Optional[str] helper in openinference.instrumentation.agno.utils:
    • Returns None if value is None or an empty/whitespace-only string.
    • Strips strings.
    • If a non-string value is encountered, logs a diagnostic warning (Expected <name> to be a string, but received <value> (type: <type>). Coercing to string.) and coerces to string (str(value)).
    • Correctly preserves numeric 0 as "0".
  • Applied _normalize_id in:
    • _runs_wrapper.py: _run_arguments() (normalizing both user_id and session_id, checking is not None instead of truthiness) and _agent_run_attributes() (for Agent and Team runs).
    • _workflow_wrapper.py: _workflow_run_arguments(), _WorkflowWrapper.run(), run_stream(), arun(), and _WorkflowExecuteWrapper.execute() / aexecute().
  • Added comprehensive unit tests in tests/test_instrumentor.py:
    • test_run_arguments_user_and_session_id_coercion: validates string coercion, diagnostic logging via caplog, and preservation of 0.
    • test_agent_run_attributes_session_and_user_id_coercion: validates agent instance attribute coercion and 0 preservation.
    • test_workflow_run_arguments_coercion: validates workflow run arguments coercion and diagnostic warnings.
    • test_normalize_id_unit: unit tests for _normalize_id.

Verification

  • Ran uv run --extra test pytest across all 159 tests in openinference-instrumentation-agno (100% pass).
  • Verified uv run --with ruff ruff check and uv run --with ruff ruff format --check (0 issues, 100% clean).
  • Verified strict mypy type checking (Success: no issues found in 7 source files).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[feature request] Better error messaging for Agno instrumentor user_id

1 participant