wip: cleanup

This commit is contained in:
franklin 2023-08-11 17:43:16 +02:00
parent 5f01366d8c
commit 20c71407db

View File

@ -117,7 +117,7 @@ func Telemetry(opts ...TelemetryOption) middleware.Middleware {
// TelemetryWithOptions middleware // TelemetryWithOptions middleware
func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware { func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware {
observe := func(l *zap.Logger, r *http.Request, metric prometheus.ObserverVec, stats *gotsrpc.CallStats, operation string) { observe := func(r *http.Request, metric prometheus.ObserverVec, stats *gotsrpc.CallStats, operation string) {
observer := metric.WithLabelValues( observer := metric.WithLabelValues(
stats.Func, stats.Func,
stats.Service, stats.Service,
@ -135,24 +135,12 @@ func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware {
duration = stats.Execution duration = stats.Execution
} }
spanCtx := trace.SpanContextFromContext(r.Context()) spanCtx := trace.SpanContextFromContext(r.Context())
if v, ok := observer.(prometheus.ExemplarObserver); ok && opts.Exemplars && spanCtx.HasTraceID() { if exemplarObserver, ok := observer.(prometheus.ExemplarObserver); ok && opts.Exemplars && spanCtx.HasTraceID() && spanCtx.IsSampled() {
l.Info("==> exemplar") exemplarObserver.ObserveWithExemplar(duration.Seconds(), prometheus.Labels{
v.ObserveWithExemplar(duration.Seconds(), prometheus.Labels{
"traceID": spanCtx.TraceID().String(), "traceID": spanCtx.TraceID().String(),
}) })
return return
} }
l.Info("==> no exemplar")
if !opts.Exemplars {
l.Info("==> not exemplar")
}
if !spanCtx.HasTraceID() {
l.Info("==> not traceID")
}
if !spanCtx.IsSampled() {
l.Info("==> not sampled")
}
observer.Observe(duration.Seconds()) observer.Observe(duration.Seconds())
} }
return func(l *zap.Logger, name string, next http.Handler) http.Handler { return func(l *zap.Logger, name string, next http.Handler) http.Handler {
@ -164,16 +152,16 @@ func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware {
if stats, ok := gotsrpc.GetStatsForRequest(r); ok { if stats, ok := gotsrpc.GetStatsForRequest(r); ok {
// create custom metics // create custom metics
if opts.Marshalling { if opts.Marshalling {
observe(l, r, gotsrpcRequestDurationSummary, stats, "marshalling") observe(r, gotsrpcRequestDurationSummary, stats, "marshalling")
observe(l, r, gotsrpcRequestDurationHistogram, stats, "marshalling") observe(r, gotsrpcRequestDurationHistogram, stats, "marshalling")
} }
if opts.Unmarshalling { if opts.Unmarshalling {
observe(l, r, gotsrpcRequestDurationSummary, stats, "unmarshalling") observe(r, gotsrpcRequestDurationSummary, stats, "unmarshalling")
observe(l, r, gotsrpcRequestDurationHistogram, stats, "unmarshalling") observe(r, gotsrpcRequestDurationHistogram, stats, "unmarshalling")
} }
if opts.Execution { if opts.Execution {
observe(l, r, gotsrpcRequestDurationSummary, stats, "execution") observe(r, gotsrpcRequestDurationSummary, stats, "execution")
observe(l, r, gotsrpcRequestDurationHistogram, stats, "execution") observe(r, gotsrpcRequestDurationHistogram, stats, "execution")
} }
// enrich logger // enrich logger