-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add request logging interceptor for API (#2203)
Set `PEERDB_API_REQUEST_LOGGING_ENABLED` = true to enable request logging. Separating it from the oauth interceptor incase oauth is disabled and we wish to enable request logging
- Loading branch information
1 parent
159d868
commit 7d63502
Showing
5 changed files
with
77 additions
and
33 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package middleware | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/PeerDB-io/peer-flow/peerdbenv" | ||
) | ||
|
||
func RequestLoggingMiddleWare() grpc.UnaryServerInterceptor { | ||
if !peerdbenv.PeerDBRAPIRequestLoggingEnabled() { | ||
slog.Info("Request Logging Interceptor is disabled") | ||
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { | ||
return handler(ctx, req) | ||
} | ||
} | ||
slog.Info("Setting up request logging middleware") | ||
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { | ||
slog.Info("Received gRPC request", slog.String("method", info.FullMethod)) | ||
|
||
resp, err := handler(ctx, req) | ||
if err != nil { | ||
slog.Error("gRPC request failed", slog.String("method", info.FullMethod), slog.Any("error", err)) | ||
} else { | ||
slog.Info("gRPC request completed successfully", slog.String("method", info.FullMethod)) | ||
} | ||
return resp, err | ||
} | ||
} |
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