Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #938 +/- ##
==========================================
+ Coverage 84.00% 84.32% +0.31%
==========================================
Files 50 52 +2
Lines 5171 5340 +169
==========================================
+ Hits 4344 4503 +159
- Misses 673 680 +7
- Partials 154 157 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
grpc/server.go
Outdated
| // CaptureRequestBody determines whether to capture and send request bodies to Sentry. | ||
| CaptureRequestBody bool |
There was a problem hiding this comment.
This should be handled by the base SDK.
grpc/server.go
Outdated
| // OperationName overrides the default operation name (grpc.server). | ||
| OperationName string |
There was a problem hiding this comment.
Let's not expose this to users.
grpc/server.go
Outdated
|
|
||
| options := []sentry.SpanOption{ | ||
| sentry.ContinueTrace(hub, sentryTraceHeader, sentryBaggageHeader), | ||
| sentry.WithOpName(opts.OperationName), |
There was a problem hiding this comment.
Let's hard code this grpc.server.
| examplepb.RegisterExampleServiceServer(server, &ExampleServiceServer{}) | ||
|
|
||
| // Start the server | ||
| listener, err := net.Listen("tcp", grpcPort) |
There was a problem hiding this comment.
Semgrep identified an issue in your code:
Detected a network listener listening on 0.0.0.0 or an empty string. This could unexpectedly expose the server publicly as it binds to all available interfaces. Instead, specify another IP address that is not 0.0.0.0 nor the empty string.
To resolve this comment:
✨ Commit Assistant Fix Suggestion
- Update the value of
grpcPortso it is not just a port or set to0.0.0.0.
For example, ifgrpcPortis":50051", change it to"127.0.0.1:50051"or another appropriate interface (like your private network IP address). - If you need the server to be accessible only from the local machine, use
"127.0.0.1:<port>"as the address when callingnet.Listen. - If you do need remote access, restrict the IP address as much as possible to only the needed network interface, rather than using
0.0.0.0or a blank string. - Example:
listener, err := net.Listen("tcp", "127.0.0.1:50051")
When a server binds to 0.0.0.0 or just the port (like ":50051"), it listens on all interfaces, which could make your service accessible from unwanted sources. Use a specific IP to limit access.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by avoid-bind-to-all-interfaces.
You can view more details about this finding in the Semgrep AppSec Platform.
grpc/client.go
Outdated
| // OperationName overrides the default operation name (grpc.client). | ||
| OperationName string |
There was a problem hiding this comment.
Let's remove this here as well.
grpc/server.go
Outdated
| // ReportOn defines the conditions under which errors are reported to Sentry. | ||
| ReportOn func(error) bool |
grpc/server.go
Outdated
| func reportErrorToSentry(hub *sentry.Hub, err error, methodName string, req any, md map[string]string) { | ||
| hub.WithScope(func(scope *sentry.Scope) { | ||
| scope.SetExtras(map[string]any{ | ||
| "grpc.method": methodName, | ||
| "grpc.error": err.Error(), | ||
| }) | ||
|
|
||
| if req != nil { | ||
| scope.SetExtra("request", req) | ||
| } | ||
|
|
||
| if len(md) > 0 { | ||
| scope.SetExtra("metadata", md) | ||
| } | ||
|
|
||
| defer hub.CaptureException(err) | ||
|
|
||
| statusErr, ok := status.FromError(err) | ||
| if !ok { | ||
| return | ||
| } | ||
|
|
||
| for _, detail := range statusErr.Details() { | ||
| debugInfo, ok := detail.(*errdetails.DebugInfo) | ||
| if !ok { | ||
| continue | ||
| } | ||
| hub.AddBreadcrumb(&sentry.Breadcrumb{ | ||
| Type: "debug", | ||
| Category: "grpc.server", | ||
| Message: debugInfo.Detail, | ||
| Data: map[string]any{"stackTrace": strings.Join(debugInfo.StackEntries, "\n")}, | ||
| Level: sentry.LevelError, | ||
| Timestamp: time.Now(), | ||
| }, nil) | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
The reported errors here add zero value. Let's remove this.
|
Is this forgotten? |
|
@xf072161, not really. At the point of my changes we were discussing what's the best way to handle errors are in order to provide value to the users, then it got a bit de-prioritized due to some new things on the roadmap. It's definitely on my roadmap after we finish with some major additions that we want to do (eg. trace metrics). |
Closes #240
Sample error logged to Sentry:
Possible improvements / todos:
sentryandsentry-docs