Skip to content

fix(py/samples): guard sentry import, fix dual-trace export, improve dev UX#4503

Merged
yesudeep merged 1 commit intomainfrom
yesudeep/fix/sentry-optional-import
Feb 8, 2026
Merged

fix(py/samples): guard sentry import, fix dual-trace export, improve dev UX#4503
yesudeep merged 1 commit intomainfrom
yesudeep/fix/sentry-optional-import

Conversation

@yesudeep
Copy link
Contributor

@yesudeep yesudeep commented Feb 8, 2026

Summary

Screenshot 2026-02-08 at 1 31 28 AM Screenshot 2026-02-08 at 1 32 04 AM Screenshot 2026-02-08 at 1 32 46 AM Screenshot 2026-02-08 at 1 48 49 AM

Fixes and improvements for the web-endpoints-hello sample and _common.sh.

1. Guard sentry_sdk import behind TYPE_CHECKING

The top-level from sentry_sdk.integrations import Integration causes
ModuleNotFoundError when sentry-sdk is not installed.

2. Fix dual-trace export (DevUI + Jaeger)

Uses genkit.core.tracing.add_custom_exporter() to attach the OTLP
exporter to Genkit's existing TracerProvider. Both DevUI and Jaeger
receive spans simultaneously. Sets OTEL_SERVICE_NAME env var in
run.sh so traces show the correct service name.

3. Move Jaeger auto-start into run.sh

run.sh now handles Jaeger start + --otel-endpoint (previously only
just dev did this). just dev simplified to call ./run.sh.

4. gRPC OTel instrumentation

Added opentelemetry-instrumentation-grpc for auto-instrumentation of
gRPC spans with OTel semantic conventions (rpc.system, rpc.service,
rpc.method). gRPC and REST traces are distinguishable in Jaeger
by filtering on these attributes.

5. Robust CLI installers in _common.sh

  • AWS CLI: checks for unzip on Linux and installs it via
    apt-get/dnf/yum if missing.
  • Azure CLI: detects Linux distro via /etc/os-release and uses
    the appropriate installer (Debian/Ubuntu, Fedora/RHEL, or pip fallback).

6. Rich default text for translate_text flow

TranslateInput.text defaults to a paragraph about the Northern Lights.

Files changed

File Change
src/sentry_init.py Guard import behind TYPE_CHECKING
src/telemetry.py Rewrite to use add_custom_exporter
src/grpc_server.py Add GrpcAioInstrumentorServer instrumentation
src/schemas.py Add default text for translate flow
run.sh Jaeger auto-start + OTEL_SERVICE_NAME
justfile Simplify dev to call run.sh
pyproject.toml Add opentelemetry-instrumentation-grpc dep
tests/telemetry_otel_test.py Update tests for new telemetry API
tests/schemas_test.py Update test for new default
py/pyproject.toml Add grpc instrumentation to lint deps
py/samples/_common.sh Fix unzip dep + Azure distro detection

Testing

  • All 363 sample tests pass
  • bin/lint and just lint pass with 0 errors

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yesudeep, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a ModuleNotFoundError that occurred when sentry-sdk was not installed, despite the setup_sentry() function gracefully handling its absence. The fix involves conditionally importing the Integration type from sentry_sdk only during type-checking, thereby preventing runtime import errors and allowing the module to load successfully in all environments. This ensures the sample application remains functional and flexible regarding its Sentry integration.

Highlights

  • Conditional Import: The import statement for sentry_sdk.integrations.Integration in sentry_init.py has been moved behind a if typing.TYPE_CHECKING: block. This change ensures that the module can be loaded without raising a ModuleNotFoundError if the sentry-sdk package is not installed, while still allowing type checkers to use the Integration type.
  • Module Robustness: This modification improves the robustness of the sentry_init.py module, allowing it to function correctly in environments where sentry-sdk is not a dependency, without impacting type-checking capabilities due to the use of from __future__ import annotations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • py/samples/web-endpoints-hello/src/sentry_init.py
    • Added import typing to enable conditional type-checking.
    • Wrapped the from sentry_sdk.integrations import Integration statement within an if typing.TYPE_CHECKING: block to prevent runtime import errors when sentry-sdk is not installed.
Activity
  • The pull request was authored by yesudeep.
  • The changes focus on a single file: py/samples/web-endpoints-hello/src/sentry_init.py.
  • The author verified that the import now works correctly without sentry-sdk installed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@yesudeep yesudeep enabled auto-merge (squash) February 8, 2026 09:10
Copy link
Contributor

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

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 correctly addresses the ModuleNotFoundError by moving the type-only import behind a TYPE_CHECKING guard. This is the standard approach for handling optional dependencies in Python for type hinting. My review includes one suggestion to add a regression test to ensure the module remains importable even if sentry-sdk is not installed, which will help prevent similar issues in the future.

@yesudeep yesudeep disabled auto-merge February 8, 2026 09:13
@yesudeep yesudeep force-pushed the yesudeep/fix/sentry-optional-import branch 5 times, most recently from 4d5edd5 to 713dfce Compare February 8, 2026 09:30
@yesudeep yesudeep changed the title fix(py/samples): guard sentry_sdk import behind TYPE_CHECKING fix(py/samples): guard sentry import, fix dual-trace export, improve dev UX Feb 8, 2026
@yesudeep yesudeep force-pushed the yesudeep/fix/sentry-optional-import branch 2 times, most recently from 85305c4 to 0b7d106 Compare February 8, 2026 09:35
@yesudeep yesudeep enabled auto-merge (squash) February 8, 2026 09:37
@yesudeep yesudeep disabled auto-merge February 8, 2026 09:37
@yesudeep yesudeep enabled auto-merge (squash) February 8, 2026 09:37
@yesudeep yesudeep disabled auto-merge February 8, 2026 09:42
@yesudeep yesudeep force-pushed the yesudeep/fix/sentry-optional-import branch from 0b7d106 to 853a5d3 Compare February 8, 2026 09:46
@github-actions github-actions bot added the config label Feb 8, 2026
@yesudeep yesudeep force-pushed the yesudeep/fix/sentry-optional-import branch 3 times, most recently from 564119d to 27a3938 Compare February 8, 2026 09:54
@yesudeep yesudeep enabled auto-merge (squash) February 8, 2026 09:55
@yesudeep
Copy link
Contributor Author

yesudeep commented Feb 8, 2026

/gemini review

@yesudeep yesudeep disabled auto-merge February 8, 2026 09:55
Copy link
Contributor

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

Choose a reason for hiding this comment

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

Code Review

This is a great pull request that brings several valuable improvements to the Python samples. The fixes for dual-trace export and the Sentry import guard are well-implemented and address important issues. The enhancements to developer experience, such as the robust CLI installers in _common.sh and the simplified just dev command, are excellent additions. The code is clean, well-documented, and the accompanying tests are thorough. I have one minor suggestion in _common.sh to improve the robustness of the package manager detection. Overall, fantastic work!

@yesudeep yesudeep force-pushed the yesudeep/fix/sentry-optional-import branch from 27a3938 to 235cf60 Compare February 8, 2026 09:59
@yesudeep yesudeep enabled auto-merge (squash) February 8, 2026 10:00
…slate default

Three fixes for the web-endpoints-hello sample:

1. Guard sentry_sdk import behind TYPE_CHECKING — the top-level import
   causes ModuleNotFoundError when sentry-sdk is not installed, even
   though setup_sentry() handles the missing package gracefully.

2. Fix dual-trace export to DevUI + Jaeger — the old code created a
   competing TracerProvider that replaced Genkit's provider, so traces
   went to either the DevUI or Jaeger but not both. Now uses
   genkit.core.tracing.add_custom_exporter to attach the OTLP exporter
   to Genkit's existing provider. When no DevUI is running (production),
   a provider with SERVICE_NAME is created first so Jaeger shows the
   correct service name.

3. Move Jaeger auto-start and --otel-endpoint wiring from justfile into
   run.sh so `./run.sh` alone gives the full dev experience with
   tracing. Pass --no-telemetry to skip Jaeger.

4. Add a rich default text for translate_text flow — a paragraph about
   the Northern Lights makes the DevUI demo more impressive.
@yesudeep yesudeep force-pushed the yesudeep/fix/sentry-optional-import branch from 235cf60 to ceec4d3 Compare February 8, 2026 10:00
@yesudeep yesudeep disabled auto-merge February 8, 2026 10:05
@yesudeep yesudeep enabled auto-merge (squash) February 8, 2026 10:06
@yesudeep yesudeep merged commit 282d988 into main Feb 8, 2026
18 checks passed
@yesudeep yesudeep deleted the yesudeep/fix/sentry-optional-import branch February 8, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants