Skip to content

fix(grpc): handle None server interceptors - #19864

Open
ramannanda9 wants to merge 3 commits into
DataDog:mainfrom
ramannanda9:fix/grpc-none-interceptors
Open

fix(grpc): handle None server interceptors#19864
ramannanda9 wants to merge 3 commits into
DataDog:mainfrom
ramannanda9:fix/grpc-none-interceptors

Conversation

@ramannanda9

@ramannanda9 ramannanda9 commented Aug 25, 2026

Copy link
Copy Markdown

Description

Handle explicit interceptors=None when ddtrace wraps synchronous and asynchronous gRPC server constructors.

Both gRPC APIs define interceptors as optional. The wrappers previously checked only whether the keyword was present, then attempted tuple(None), raising TypeError before the server could start. Ray 2.58 exposed this by passing interceptors=None when creating an internal async gRPC server without authentication.

Treat None like an omitted or empty interceptor sequence while preserving Datadog-first ordering for non-empty user interceptors.

Testing

  • scripts/run-tests --venv 9a13b9a --venv 53b1ba3 -- -- -k test_server_accepts_explicit_none_interceptors
  • scripts/run-tests --venv 9a13b9a --venv 53b1ba3 -- -s
  • scripts/lint checks

Risks

Low. The change only affects server construction when interceptors is missing, empty, or None; non-empty interceptor sequences retain their existing ordering.

Additional Notes

This was observed with Ray 2.58 and ddtrace 3.19.8. ddtrace 3.x is EOL, but if maintainers consider the startup crash critical, a 3.19 backport would help users unable to move immediately to 4.x.

We are fine with moving to 4.x, but the bug is present there as well.

@ramannanda9
ramannanda9 requested review from a team as code owners August 25, 2026 21:01
@ramannanda9
ramannanda9 force-pushed the fix/grpc-none-interceptors branch from 0c8a64d to deaddcd Compare August 25, 2026 21:10

@emmettbutler emmettbutler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution!

Ray 2.58 passes interceptors=None when it constructs an internal async gRPC server without authentication. The tracing wrappers previously tried to convert that value to a tuple and failed before server startup.

Normalize missing, empty, and None interceptor values to the Datadog interceptor tuple while preserving Datadog-first ordering for non-empty user interceptors.
@ramannanda9
ramannanda9 force-pushed the fix/grpc-none-interceptors branch from deaddcd to 7720f4d Compare August 26, 2026 17:52

@dubloom dubloom 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.

Straightforward and great contribution, thank you for the fix !

@datadog-prod-us1-3

This comment has been minimized.

@KowalskiThomas KowalskiThomas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

@gnufede gnufede left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just a nit

Comment on lines +231 to 232
if kwargs.get("interceptors"):
kwargs["interceptors"] = (interceptor,) + tuple(kwargs["interceptors"])

@gnufede gnufede Aug 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use walrus operator here to avoid accessing kwargs twice, same below in 245+246

Suggested change
if kwargs.get("interceptors"):
kwargs["interceptors"] = (interceptor,) + tuple(kwargs["interceptors"])
if interceptors := kwargs.get("interceptors"):
kwargs["interceptors"] = (interceptor,) + tuple(interceptors)

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.

5 participants