mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
b024cda4e5
* initial sentry variables and secrets * feat: sentry monitoring * fix typo * feat(sentry version): sentry capability * fix(sentry include): included sentry import 4 zitadel * usage flag for sentry * improve sentry flag * merge main * fix sentry config * add sentry dsn to secret env vars * fix test * log sentry start * add sentry grpc interceptor and recover * add sentry http interceptor to asset api * fix interceptor order * try improve sentry recover * fix i18n interception * panic Co-authored-by: Livio Amstutz <livio.a@gmail.com>
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
grpc_api "github.com/caos/zitadel/internal/api/grpc"
|
|
"github.com/caos/zitadel/internal/telemetry/metrics"
|
|
|
|
"github.com/caos/logging"
|
|
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
|
"golang.org/x/text/language"
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/api/grpc/server/middleware"
|
|
"github.com/caos/zitadel/internal/api/http"
|
|
"github.com/caos/zitadel/internal/telemetry/tracing"
|
|
)
|
|
|
|
const (
|
|
defaultGrpcPort = "80"
|
|
)
|
|
|
|
type Server interface {
|
|
Gateway
|
|
RegisterServer(*grpc.Server)
|
|
AppName() string
|
|
MethodPrefix() string
|
|
AuthMethods() authz.MethodMapping
|
|
}
|
|
|
|
func CreateServer(verifier *authz.TokenVerifier, authConfig authz.Config, lang language.Tag) *grpc.Server {
|
|
metricTypes := []metrics.MetricType{metrics.MetricTypeTotalCount, metrics.MetricTypeRequestCount, metrics.MetricTypeStatusCode}
|
|
return grpc.NewServer(
|
|
grpc.UnaryInterceptor(
|
|
grpc_middleware.ChainUnaryServer(
|
|
middleware.DefaultTracingServer(),
|
|
middleware.MetricsHandler(metricTypes, grpc_api.Probes...),
|
|
middleware.ErrorHandler(),
|
|
middleware.AuthorizationInterceptor(verifier, authConfig),
|
|
middleware.SentryHandler(),
|
|
middleware.TranslationHandler(lang),
|
|
middleware.ValidationHandler(),
|
|
middleware.ServiceHandler(),
|
|
),
|
|
),
|
|
)
|
|
}
|
|
|
|
func Serve(ctx context.Context, server *grpc.Server, port string) {
|
|
go func() {
|
|
<-ctx.Done()
|
|
server.GracefulStop()
|
|
}()
|
|
|
|
go func() {
|
|
listener := http.CreateListener(port)
|
|
err := server.Serve(listener)
|
|
logging.Log("SERVE-Ga3e94").OnError(err).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Panic("grpc server serve failed")
|
|
}()
|
|
logging.LogWithFields("SERVE-bZ44QM", "port", port).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Info("grpc server is listening")
|
|
}
|
|
|
|
func grpcPort(port string) string {
|
|
if port == "" {
|
|
return defaultGrpcPort
|
|
}
|
|
return port
|
|
}
|