Skip to content

feat(otel): instrument LLM providers for latency and prompt visibility - #3798

Draft
jaegeral wants to merge 20 commits into
google:masterfrom
jaegeral:otel-llm-tracing
Draft

feat(otel): instrument LLM providers for latency and prompt visibility#3798
jaegeral wants to merge 20 commits into
google:masterfrom
jaegeral:otel-llm-tracing

Conversation

@jaegeral

@jaegeral jaegeral commented May 5, 2026

Copy link
Copy Markdown
Collaborator

"Note: This PR is stacked on top of PR #3797 (Phase 2). It contains those changes to ensure the
telemetry stack is fully initialized."

@jaegeral
jaegeral force-pushed the otel-llm-tracing branch from ea97b20 to 74888cc Compare May 6, 2026 12:29
@jaegeral

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements OpenTelemetry instrumentation for LLM providers, OpenSearch, and SQLAlchemy, while introducing a privacy-focused span processor for PII redaction and a logging filter for trace correlation. Feedback focused on ensuring that exceptions are properly recorded within the new LLM spans and addressing a potential KeyError in the logging filter when telemetry is disabled.

Comment on lines +79 to +82
except (KeyError, IndexError, requests.RequestException) as e:
raise ValueError(
f"Error JSON parsing text: {formatted_data}: {error}"
) from error
f"Error generating text with Azure API: {e}"
) from e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When an exception occurs during the LLM request, it is important to record the exception and set the span status to ERROR to ensure visibility in the trace waterfall. Currently, this exception block only raises a ValueError without updating the OpenTelemetry span.

Suggested change
except (KeyError, IndexError, requests.RequestException) as e:
raise ValueError(
f"Error JSON parsing text: {formatted_data}: {error}"
) from error
f"Error generating text with Azure API: {e}"
) from e
except (KeyError, IndexError, requests.RequestException) as e:
span.record_exception(e)
span.set_status(telemetry.get_status_code("ERROR"), description=str(e))
raise ValueError(
f"Error generating text with Azure API: {e}"
) from e

Comment thread timesketch/lib/llms/providers/google_genai.py
Comment thread timesketch/lib/telemetry.py
jaegeral and others added 2 commits June 8, 2026 15:33
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@jaegeral jaegeral mentioned this pull request Jun 10, 2026
4 tasks
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