Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Allow adding custom gRPC interceptors when creating Modal clients#201

Merged
ehdr merged 2 commits intomainfrom
ehdr/custom-grpc-interceptors
Nov 4, 2025
Merged

Allow adding custom gRPC interceptors when creating Modal clients#201
ehdr merged 2 commits intomainfrom
ehdr/custom-grpc-interceptors

Conversation

@ehdr
Copy link
Copy Markdown
Contributor

@ehdr ehdr commented Nov 4, 2025

Note

Adds support to attach custom gRPC interceptors (Go) and middleware (JS) to Modal clients, applied after built-ins, with examples, tests, and docs updates.

  • Clients:
    • Go (modal-go):
      • Add ClientParams.GRPCUnaryInterceptors and ClientParams.GRPCStreamInterceptors; store on Client and pass to newClient(...).
      • Chain custom interceptors after built-ins (headers, auth, retry, timeout) for both unary and stream calls.
    • JS (modal-js):
      • Add ModalClientParams.grpcMiddleware; store and append to client factory after built-in middleware (auth, retry, timeout).
  • Examples:
    • Add telemetry examples: modal-go/examples/telemetry/main.go and modal-js/examples/telemetry.ts.
  • Tests:
    • Verify custom interceptors/middleware are invoked: modal-go/client_test.go, modal-js/test/client.test.ts.
  • Docs:
    • Update READMEs (Go/JS) with telemetry/observability guidance and example links.
    • Update CHANGELOG.md with unreleased note.

Written by Cursor Bugbot for commit 2c7d4e0. This will update automatically on new commits. Configure here.

@ehdr ehdr requested a review from thomasjpfan November 4, 2025 15:57
Copy link
Copy Markdown
Contributor

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Minor nits, but code-wise this looks good to me.

sdkVersion: sdkVersion(),
logger: logger,
ipClients: make(map[string]pb.ModalClientClient),
customUnaryInterceptors: params.GRPCUnaryInterceptors,
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.

Nit in naming, but not blocking:

Suggested change
customUnaryInterceptors: params.GRPCUnaryInterceptors,
additionalUnaryInterceptors: params.GRPCUnaryInterceptors,

In this context, these are just "more interceptors" to be appended to the rest of the interceptors

retryInterceptor(c),
timeoutInterceptor(),
}
unaryInterceptors = append(unaryInterceptors, customUnaryInterceptors...)
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.

If one wants to write a tracer that is aware of our retry semantics, they would need to read the retryInterceptor code and also pass the metadata into their tracer.

Note, I'm okay with this.

Comment on lines +53 to +56
mu.Lock()
firstCalled = true
firstMethod = method
mu.Unlock()
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.

Very very nit:

Suggested change
mu.Lock()
firstCalled = true
firstMethod = method
mu.Unlock()
mu.Lock()
defer mu.Unlock()
firstCalled = true
firstMethod = method

(It's slightly different behavior from what you have, but using defer feels more "go like")

Comment on lines +68 to +71
mu.Lock()
secondCalled = true
secondMethod = method
mu.Unlock()
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.

Suggested change
mu.Lock()
secondCalled = true
secondMethod = method
mu.Unlock()
mu.Lock()
defer mu.Unlock()
secondCalled = true
secondMethod = method

@ehdr ehdr merged commit 1db383c into main Nov 4, 2025
8 of 9 checks passed
@ehdr ehdr deleted the ehdr/custom-grpc-interceptors branch November 4, 2025 20:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants