Skip to content

Comments

fix(grpc): Read method from handler_call_details for grpcio >= 1.76 compat#5521

Merged
sentrivana merged 1 commit intogetsentry:masterfrom
yeung108:fix/grpc-server-interceptor-grpcio-1.76
Feb 24, 2026
Merged

fix(grpc): Read method from handler_call_details for grpcio >= 1.76 compat#5521
sentrivana merged 1 commit intogetsentry:masterfrom
yeung108:fix/grpc-server-interceptor-grpcio-1.76

Conversation

@yeung108
Copy link
Contributor

@yeung108 yeung108 commented Feb 24, 2026

Summary

Fixes sync ServerInterceptor to work with grpcio >= 1.76 by reading the method name from handler_call_details.method instead of context._rpc_event.call_details.method.

Problem

grpcio 1.76 introduced registered method handlers (add_registered_method_handlers) which resolve RPC methods at the C-core level. For these registered methods, context._rpc_event.call_details.method returns an empty string, causing Sentry tracing to silently fail (no transactions, no spans, no trace IDs in logs).

Solution

Capture handler_call_details.method directly in the closure scope before defining the behavior function. This approach:

  1. Fixes grpcio >= 1.76 compatibility - handler_call_details.method is always populated by grpcio's _find_method_handler
  2. Avoids race conditions - No shared instance state; each call creates its own closure with captured values
  3. Maintains backward compatibility - Custom find_name parameter still works

Why Closure Capture Instead of Instance State?

The gRPC sync server uses a ThreadPoolExecutor where multiple threads share the same ServerInterceptor instance. Storing state as self._handler_call_details would create a race condition where one thread could overwrite the value before another thread's behavior closure reads it.

Fixes #5520

@yeung108 yeung108 requested a review from a team as a code owner February 24, 2026 06:33
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

Openai

  • Avoid consuming iterables passed to the Completions API by alexander-alderman-webb in #5489
  • Avoid consuming iterables passed to the Embeddings API by alexander-alderman-webb in #5491

Other

  • (anthropic) Fix token accounting by shellmayr in #5490
  • (google-genai) Remove agent spans for simple requests by alexander-alderman-webb in #5443
  • (grpc) Read method from handler_call_details for grpcio >= 1.76 compat by yeung108 in #5521

Documentation 📚

  • New integration guide by alexander-alderman-webb in #5476

Internal Changes 🔧

  • (agents) Add sentry skills to be used by warden in CI reviews by ericapisani in #5485
  • (ai) Add configuration for dotagents by ericapisani in #5480
  • (github) Add warden configuration by ericapisani in #5484
  • (openai-agents) Expect new tool fields by alexander-alderman-webb in #5471
  • (repo) Add .serena to .gitignore by ericapisani in #5464
  • 🤖 Update test matrix with new releases (02/19) by github-actions in #5483
  • 🤖 Update test matrix with new releases (02/18) by github-actions in #5475

🤖 This preview updates automatically when you update the PR.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

…ompat

grpcio 1.76 introduced registered method handlers which resolve RPC
methods at the C-core level. For these methods,
`context._rpc_event.call_details.method` is empty, breaking tracing.

This fix captures `handler_call_details.method` in the closure scope
to avoid both the grpcio 1.76 issue and race conditions from shared
instance state in the ThreadPoolExecutor.

Fixes getsentry#5520
@yeung108 yeung108 force-pushed the fix/grpc-server-interceptor-grpcio-1.76 branch from 482ee29 to 8566650 Compare February 24, 2026 06:51
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Thanks @yeung108, looks good to me.

@sentrivana sentrivana merged commit bd0fc70 into getsentry:master Feb 24, 2026
155 of 156 checks passed
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.

gRPC sync ServerInterceptor._find_name broken with grpcio >= 1.76

2 participants