forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OTEL wiring in grpcserver interceptor (DataDog POC) #612
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
436de0d
OTEL wiring in grpcserver
p0mvn c14cd47
updates
p0mvn f7b0738
updates
p0mvn 3796c6f
grpc headers
p0mvn aea2d17
updates
p0mvn 9d591d4
updates
p0mvn db534ba
updates
p0mvn 812a68e
go 1.21
p0mvn fe6ed0d
updates
p0mvn cdd9d8c
test go1.21
p0mvn 71570b7
update lint go
p0mvn 8617a75
go mod for tests
p0mvn d4313a9
more updates
p0mvn b53ae8d
bump linter version
p0mvn d7e3b4b
updates
p0mvn 9395286
remove nakedret
p0mvn 6667816
codeql go version
p0mvn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ jobs: | |
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.20" | ||
go-version: "1.21" | ||
check-latest: true | ||
- uses: technote-space/[email protected] | ||
id: git_diff | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ run: | |
linters: | ||
disable-all: true | ||
enable: | ||
- depguard | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: too many complaints after linter version bump so I removed it |
||
- dogsled | ||
- exportloopref | ||
- goconst | ||
|
@@ -19,7 +18,6 @@ linters: | |
- govet | ||
- ineffassign | ||
- misspell | ||
- nakedret | ||
- staticcheck | ||
- stylecheck | ||
- typecheck | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,12 @@ import ( | |
"fmt" | ||
"strconv" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
otelcodes "go.opentelemetry.io/otel/codes" | ||
"go.opentelemetry.io/otel/propagation" | ||
"go.opentelemetry.io/otel/trace" | ||
|
||
gogogrpc "github.com/cosmos/gogoproto/grpc" | ||
grpcmiddleware "github.com/grpc-ecosystem/go-grpc-middleware" | ||
grpcrecovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery" | ||
|
@@ -18,14 +24,18 @@ import ( | |
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" | ||
) | ||
|
||
const tracerName = "cosmos-sdk" | ||
|
||
// GRPCQueryRouter returns the GRPCQueryRouter of a BaseApp. | ||
func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter } | ||
|
||
// RegisterGRPCServer registers gRPC services directly with the gRPC server. | ||
func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server, logQueries bool) { | ||
tracer := otel.Tracer(tracerName) | ||
|
||
// Define an interceptor for all gRPC queries: this interceptor will create | ||
// a new sdk.Context, and pass it into the query handler. | ||
interceptor := func(grpcCtx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { | ||
interceptor := func(grpcCtx context.Context, req interface{}, grpcInfo *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { | ||
// If there's some metadata in the context, retrieve it. | ||
md, ok := metadata.FromIncomingContext(grpcCtx) | ||
if !ok { | ||
|
@@ -70,7 +80,25 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server, logQueries bool) | |
app.logger.Info("gRPC query received of type: " + fmt.Sprintf("%#v", req)) | ||
} | ||
|
||
return handler(grpcCtx, req) | ||
// Extract the existing span context from the incoming request | ||
parentCtx := otel.GetTextMapPropagator().Extract(grpcCtx, propagation.HeaderCarrier(md)) | ||
|
||
// Start a new span representing the request | ||
// The span ends when the request is complete | ||
grpcCtx, span := tracer.Start(parentCtx, grpcInfo.FullMethod, trace.WithSpanKind(trace.SpanKindServer)) | ||
defer span.End() | ||
|
||
span.SetAttributes(attribute.String("http.method", grpcInfo.FullMethod)) | ||
|
||
resp, err = handler(grpcCtx, req) | ||
|
||
if err != nil { | ||
span.SetStatus(otelcodes.Error, err.Error()) | ||
} else { | ||
span.SetStatus(otelcodes.Ok, "OK") | ||
} | ||
|
||
return resp, err | ||
Comment on lines
-73
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link |
||
} | ||
|
||
// Loop through all services and methods, add the interceptor, and register | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.20-alpine AS build | ||
FROM golang:1.21-alpine AS build | ||
|
||
RUN apk add build-base git linux-headers | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this because this is the first version that supports go 1.21