mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
feat: add env configuration
This commit is contained in:
parent
0a682498d4
commit
ab382f801a
@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/foomo/gotsrpc/v2"
|
"github.com/foomo/gotsrpc/v2"
|
||||||
|
"github.com/foomo/keel/env"
|
||||||
httplog "github.com/foomo/keel/net/http/log"
|
httplog "github.com/foomo/keel/net/http/log"
|
||||||
"github.com/foomo/keel/telemetry"
|
"github.com/foomo/keel/telemetry"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -36,7 +37,7 @@ const (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
TelemetryOptions struct {
|
TelemetryOptions struct {
|
||||||
Exemplars bool
|
ExemplarsDisabled bool
|
||||||
ObserveExecution bool
|
ObserveExecution bool
|
||||||
ObserveMarshalling bool
|
ObserveMarshalling bool
|
||||||
ObserveUnmarshalling bool
|
ObserveUnmarshalling bool
|
||||||
@ -77,18 +78,18 @@ var (
|
|||||||
// DefaultTelemetryOptions returns the default options
|
// DefaultTelemetryOptions returns the default options
|
||||||
func DefaultTelemetryOptions() TelemetryOptions {
|
func DefaultTelemetryOptions() TelemetryOptions {
|
||||||
return TelemetryOptions{
|
return TelemetryOptions{
|
||||||
Exemplars: false,
|
|
||||||
ObserveExecution: true,
|
ObserveExecution: true,
|
||||||
ObserveMarshalling: false,
|
ObserveMarshalling: false,
|
||||||
ObserveUnmarshalling: false,
|
ObserveUnmarshalling: false,
|
||||||
PayloadAttributeDisabled: true,
|
PayloadAttributeDisabled: env.GetBool("OTEL_GOTSRPC_PAYLOAD_ATTRIBUTE_DISABLED", true),
|
||||||
|
ExemplarsDisabled: env.GetBool("OTEL_GOTSRPC_EXEMPLARS_DISABLED", false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TelemetryWithExemplars middleware option
|
// TelemetryWithExemplarsDisabled middleware option
|
||||||
func TelemetryWithExemplars(v bool) TelemetryOption {
|
func TelemetryWithExemplarsDisabled(v bool) TelemetryOption {
|
||||||
return func(o *TelemetryOptions) {
|
return func(o *TelemetryOptions) {
|
||||||
o.Exemplars = v
|
o.ExemplarsDisabled = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware {
|
|||||||
case "execution":
|
case "execution":
|
||||||
duration = stats.Execution
|
duration = stats.Execution
|
||||||
}
|
}
|
||||||
if exemplarObserver, ok := observer.(prometheus.ExemplarObserver); ok && opts.Exemplars && spanCtx.HasTraceID() && spanCtx.IsSampled() {
|
if exemplarObserver, ok := observer.(prometheus.ExemplarObserver); ok && opts.ExemplarsDisabled && spanCtx.HasTraceID() && spanCtx.IsSampled() {
|
||||||
exemplarObserver.ObserveWithExemplar(duration.Seconds(), prometheus.Labels{
|
exemplarObserver.ObserveWithExemplar(duration.Seconds(), prometheus.Labels{
|
||||||
"traceID": spanCtx.TraceID().String(),
|
"traceID": spanCtx.TraceID().String(),
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user