Skip to content

Conversation

@pdelewski
Copy link
Member

No description provided.

@github-actions github-actions bot added the conventional-commit/chore Something that needs to be taken care of but not very appealing label Nov 6, 2025
@kakkoyun kakkoyun requested a review from Copilot November 7, 2025 11:46
Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

Looking good 🚀

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds gRPC server instrumentation support to the OpenTelemetry compile-time instrumentation project. It enables hooking into gRPC server initialization to add telemetry capabilities.

Key changes:

  • Adds gRPC server hook configuration and implementation
  • Implements a Shutdown RPC method for graceful server termination in tests
  • Adds end-to-end test coverage for the gRPC instrumentation hook

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tool/data/grpc.yaml Defines hook configuration for gRPC server's Serve method
test/e2e/grpc_test.go Adds e2e test to verify gRPC server hook invocation
pkg/instrumentation/grpc/server_hook.go Implements the BeforeServe hook for gRPC server instrumentation
pkg/instrumentation/grpc/go.mod Adds Go module definition for the gRPC instrumentation package
demo/grpc/server/pb/greeter_grpc.pb.go Generated gRPC code including new Shutdown RPC method
demo/grpc/server/pb/greeter.pb.go Generated protobuf code for Shutdown request/reply messages
demo/grpc/server/main.go Implements Shutdown RPC handler and adds startup logging
demo/grpc/server/greeter.proto Adds Shutdown RPC definition to the service
demo/grpc/server/go.sum Updates dependency checksums
demo/grpc/client/main.go Adds shutdown flag to invoke server shutdown
demo/grpc/README.md Documents the new Shutdown RPC method and usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +37
if strings.Contains(line, readyMsg) {
close(readyChan)
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The readyChan channel could be closed multiple times if the "server started" message appears more than once in the server output, which would cause a panic. Consider using a sync.Once or checking if the channel is already closed before attempting to close it again.

Example fix:

var readyOnce sync.Once
// ... in the goroutine:
if strings.Contains(line, readyMsg) {
    readyOnce.Do(func() { close(readyChan) })
}

Copilot uses AI. Check for mistakes.
@pdelewski
Copy link
Member Author

pdelewski commented Nov 9, 2025

Right now, the example rule isn’t working, and BeforeServe isn’t being called. I’ll investigate the root cause.

❌ TestGrpc (13.81s)
      infra.go:44: 
          	Error Trace:	/home/runner/work/opentelemetry-go-compile-instrumentation/opentelemetry-go-compile-instrumentation/test/app/infra.go:44
          	            				/home/runner/work/opentelemetry-go-compile-instrumentation/opentelemetry-go-compile-instrumentation/test/e2e/grpc_test.go:63
          	Error:      	Received unexpected error:
          	            	exit status 1
          	Test:       	TestGrpc

@y1yang0 y1yang0 mentioned this pull request Nov 10, 2025
36 tasks
@pdelewski
Copy link
Member Author

pdelewski commented Nov 10, 2025

According to debug.log rule is matched:

msg="Match func rule" phase=go rule=server_hook2 dep="{google.golang.org/[email protected]: [/Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/backoff.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/balancer_wrapper.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/call.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/clientconn.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/codec.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/dialoptions.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/doc.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/interceptor.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/picker_wrapper.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/pickfirst.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/preloader.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/resolver_wrapper.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/rpc_util.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/server.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/service_config.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/shared_buffer_pool.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/stream.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/stream_interfaces.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/trace.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/trace_withtrace.go /Users/pdelewski/go/pkg/mod/google.golang.org/[email protected]/version.go]}"

But it's not applied, e.g code is not injected. Below place where we return with an error
image

@pdelewski
Copy link
Member Author

pdelewski commented Nov 10, 2025

Going deeper, it seems that there is signature mismatch
image

Hi @y1yang0 — there’s a gap in my understanding here. I’m trying to hook into grpc.(*Server).Serve

My current hook is:

//go:linkname BeforeServe google.golang.org/grpc.BeforeServe
func BeforeServe(ictx inst.HookContext, _ interface{}, lis net.Listener) {
    fmt.Println("BeforeServe")
    // TODO: Implement the real server hook logic here
}

According to my understanding the first two parameters in this case should be ictx inst.HookContext, _ interface{}, however it does not work. Just wanted to confirm if that's correct.

@y1yang0
Copy link
Contributor

y1yang0 commented Nov 11, 2025

@pdelewski I see. The issue was that ast.FindFuncDecl was identifying the wrong target function, which led to a signature mismatch. I will submit a PR to fix this. Apologies for the mistake.

"github.com/stretchr/testify/require"
)

func waitUntilGrpcReady(t *testing.T, serverApp *exec.Cmd, outputPipe io.ReadCloser) func() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks almost identical to waitUntilReady in http_test.go. Perhaps we could extract this into a shared app.go, like app.WaitUntilReady (or app.WaitReady)?

@pdelewski
Copy link
Member Author

pdelewski commented Nov 11, 2025

@kakkoyun Why it was closed? #147 contains a fix that is needed to grpc work correctly

@pdelewski pdelewski reopened this Nov 11, 2025
@pdelewski
Copy link
Member Author

It seems that still, there is some problem

@pdelewski
Copy link
Member Author

It's better now, as it seems that instrumentation is there:

func (s *Server) Serve(lis net.Listener) (_unnamedRetVal0 error) {
        //line <generated>:1  
        if hookContext802697909, skip802697909 := OtelBeforeTrampoline_Serve802697909(&s, &lis); skip802697909 {
                OtelAfterTrampoline_Serve802697909(hookContext802697909, &_unnamedRetVal0)
                return _unnamedRetVal0
        } else

However tests is failing. I need to investigate further.

@pdelewski
Copy link
Member Author

@pdelewski I see. The issue was that ast.FindFuncDecl was identifying the wrong target function, which led to a signature mismatch. I will submit a PR to fix this. Apologies for the mistake.

@y1yang0 Thanks for the fix. I was not sure if that was due to wrong rule or bug in the instrumentation itself.

@kakkoyun
Copy link
Member

kakkoyun commented Nov 11, 2025

@kakkoyun Why it was closed? #147 contains a fix that is needed to grpc work correctly

I think it happened because I merged the PR (#147)? I didn't close it deliberately.

It says "fixes" in the description. And apparently GH doesn't care if it is an issue or PR, it closes it.

@pdelewski
Copy link
Member Author

@kakkoyun Why it was closed? #147 contains a fix that is needed to grpc work correctly

I think it happened because I merged the PR (#147)? I didn't close it deliberately.

It says "fixes" in the description. And apparently GH doesn't care if it is an issue or PR, it closes it.

Ok, thank you

@kakkoyun
Copy link
Member

@pdelewski Do you need any help with this?

@pdelewski
Copy link
Member Author

@pdelewski Do you need any help with this?

@kakkoyun I haven’t had much time on this yet. I’ll take a closer look today. If I don’t find the root cause, I’d appreciate a hand.

@pdelewski pdelewski marked this pull request as ready for review November 12, 2025 10:04
@pdelewski pdelewski requested a review from a team as a code owner November 12, 2025 10:04
@pdelewski pdelewski merged commit d67b38c into open-telemetry:main Nov 12, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conventional-commit/chore Something that needs to be taken care of but not very appealing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants