Comments (8)
I just pushed https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/providers%2Fopenmetrics%2Fv2.0.1, does that work?
from go-grpc-middleware.
@johanbrandhorst Thank You, very much for your help.
I think the package is not available yet, go get failed and at pkg.go.dev still list rc3 as the latest package.
go get go-grpc-middleware-providers-openmetrics-v2.0.1 ─╯
go: unrecognized import path "go-grpc-middleware-providers-openmetrics-v2.0.1": https fetch: Get "https://go-grpc-middleware-providers-openmetrics-v2.0.1/?go-get=1": dial tcp: lookup go-grpc-middleware-providers-openmetrics-v2.0.1: no such host
from go-grpc-middleware.
Oops, looks like we removed that folder before tagging v2, I can't see it on the main
branch. @bwplotka what happened to openmetrics?
from go-grpc-middleware.
Hey, it got renamed to Prometheus provider: https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/providers/prometheus , calling it open metrics was a mistake there, sorry.
Just replace it with a prometheus provider module should work for you (it has a different version than the main module, see https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/providers%2Fprometheus%2Fv1.0.0).
from go-grpc-middleware.
Get and reference the prometheus provider module via go get github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus
from go-grpc-middleware.
@johanbrandhorst and @bwplotka Thank you very much Guys!
I've changed to prometheus package and referenced v2.0.1 of main package, it build correctly and worked with slog.
from go-grpc-middleware.
Epic! Do you mind sharing your slog integration? How your integrated roughly?
from go-grpc-middleware.
Sure, I have no credit on the implementation, basically I just followed the other logging interceptors, I may tweak it a little bit later, but for now I'm prioritizing the simplicity.
I've removed some lines to make it clear.
InterceptorLogger implementation
import (
"context"
"fmt"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
log "log/slog"
)
// InterceptorLogger function
func InterceptorLogger(l *log.Logger) logging.Logger {
return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) {
l.Log(ctx, log.Level(lvl), msg, fields...)
})
}
Logging Options
loggingOpts := []logging.Option{
logging.WithLogOnEvents(logging.StartCall, logging.FinishCall,
logging.PayloadReceived, logging.PayloadSent),
}
Added it to the Chain of Responsibility, log.Default returns the slog singleton previously configured
// Create gRPC server with slog, prometheus, and panic recovery middleware
srv := grpc.NewServer(
grpc.ChainUnaryInterceptor(
logging.UnaryServerInterceptor(InterceptorLogger(log.Default()), loggingOpts...),
promGrpcServerMetrics.UnaryServerInterceptor(),
recovery.UnaryServerInterceptor(),
),
grpc.ChainStreamInterceptor(
logging.StreamServerInterceptor(InterceptorLogger(log.Default()), loggingOpts...),
promGrpcServerMetrics.StreamServerInterceptor(),
recovery.StreamServerInterceptor(),
),
)
A call to the Unary rpc method produced the bellow lines (non sensitive data)
{"time":"2023-12-05T16:16:13.460813-03:00","level":"INFO","msg":"started call","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.time_ms":"0.027"}
{"time":"2023-12-05T16:16:13.460865-03:00","level":"INFO","msg":"request received","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.recv.duration":"27.708µs","grpc.request.content":{}}
{"time":"2023-12-05T16:16:13.461066-03:00","level":"INFO","msg":"response sent","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.send.duration":"319.166µs","grpc.response.content":{"jwksUri":"http://localhost:8080/.well-known/openid-configuration/jwks"}}
{"time":"2023-12-05T16:16:13.461301-03:00","level":"INFO","msg":"finished call","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.code":"OK","grpc.time_ms":"0.554"}
from go-grpc-middleware.
Related Issues (20)
- Adding `grpc_code` label to prometheus `grpc_server_handling_seconds` metric HOT 6
- With HOT 1
- Logging interceptor does not correctly log client calls sent from a server HOT 4
- Support for connect go HOT 5
- "make test" and "make lint" ignore failures
- Support for WithSubsystem() HOT 5
- [retry-middleware] Stream is finished when retry timeout ends HOT 2
- Support loggging grpc status details HOT 1
- Add source and target endpoint as label for all client/server grpc metrics HOT 2
- Support ignore logging for v2(already attached PR) HOT 3
- Prometheus metrics label value inconsistency between Go and Java HOT 3
- [logging] disable option does not work with request/response fields HOT 6
- Q: Logger migration HOT 2
- Support extensibility of retry condition
- [feat]: logging should loging grpc request msg HOT 1
- Example will log only first field HOT 3
- Add Capability to Override Base Timeout for Specific API HOT 1
- Use retry hooks for adding retry metrics
- logging.InjectFields does not work. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-grpc-middleware.