-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(observability): otel integration add tracing #48
base: main
Are you sure you want to change the base?
Conversation
be31dda
to
d9ab161
Compare
Please resolve the conflict. |
|
||
type OpentelemetryConfig config.OpenTelemetryConfig | ||
|
||
func (o *OpentelemetryConfig) Setup(serviceName string, samplingRate float64, globalAttributes map[string]string) (trace.Tracer, io.Closer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to make OpentelemetryConfig as a function arg instead of a receiver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface should be better to implement different tracing setup.
config/tracing.go
Outdated
CapturedResponseHeaders []string `yaml:"captured_response_headers"` | ||
SafeQueryParams []string `yaml:"safe_query_params"` | ||
SamplingRate float64 `yaml:"sampling_rate" default:"1"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to specific the propagation type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otel.SetTextMapPropagator(autoprop.NewTextMapPropagator())
will config propagation type from env OTEL_PROPAGATORS
, default is tracecontext,baggage
0d34f5f
to
164487f
Compare
config/tracing.go
Outdated
ServiceName string `yaml:"service_name" default:"WebhookX"` | ||
CapturedRequestHeaders []string `yaml:"captured_request_headers"` | ||
CapturedResponseHeaders []string `yaml:"captured_response_headers"` | ||
SafeQueryParams []string `yaml:"safe_query_params"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the safe_query_params
is defined in the config.yml? do we really need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
safe_query_params
defined in config.yml, should check again.
config/tracing.go
Outdated
type OpenTelemetryConfig struct { | ||
Protocol OtlpProtocol `yaml:"protocol" envconfig:"PROTOCOL" default:"http/protobuf"` | ||
Endpoint string `yaml:"endpoint" envconfig:"ENDPOINT" default:"http://localhost:4318/v1/metrics"` | ||
Headers map[string]string `yaml:"headers,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove it as it can be configured via Otel Envs? Or do you think this is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's necessary, webhookx should start up with a simple default config rather than letting user gain a deeper understanding about OTEL Envs.
It can be override by OTEL Envs if users have more requirements of tracing
|
good point, updated.
omited spans:
all available spans list below:
|
admin/api/api.go
Outdated
@@ -95,7 +97,7 @@ func (api *API) assert(err error) { | |||
func (api *API) Handler() http.Handler { | |||
r := mux.NewRouter() | |||
|
|||
r.Use(panicRecovery) | |||
r.Use(middlewares.PanicRecovery) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite that both panicRecovery in proxy and admin are shares most of logic, but I don't it's the right time to use the same middleware.
@@ -58,6 +59,10 @@ func (cfg Config) Validate() error { | |||
return err | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Username string `yaml:"username" default:"webhookx"` | ||
Password string `yaml:"password" default:""` | ||
Database string `yaml:"database" default:"webhookx"` | ||
tracingEnabled bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer replacing db driver at app initialize rather than having tracingEnabled everywhere.
config/redis.go
Outdated
Port uint32 `yaml:"port" default:"6379"` | ||
Password string `yaml:"password" default:""` | ||
Database uint32 `yaml:"database" default:"0"` | ||
tracingEnabled bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
func init() { | ||
var err error | ||
cfg, err = config.Init() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need to be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE format issue
config/tracing.go
Outdated
type TracingConfig struct { | ||
Enabled bool `yaml:"enabled" default:"false"` | ||
Attributes Map `yaml:"attributes"` | ||
Opentelemetry *OpenTelemetryConfig `yaml:"opentelemetry"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason to use pointer here
return nil | ||
} | ||
if cfg.SamplingRate > 1 || cfg.SamplingRate < 0 { | ||
return errors.New("invalid sampling rate, must be [0,1]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("invalid sampling rate, must be [0,1]") | |
return errors.New("sampling_rate must be in the range [0, 1]") |
config/tracing.go
Outdated
type OpenTelemetryConfig struct { | ||
Protocol OtlpProtocol `yaml:"protocol" envconfig:"PROTOCOL" default:"http/protobuf"` | ||
Endpoint string `yaml:"endpoint" envconfig:"ENDPOINT" default:"http://localhost:4318/v1/metrics"` | ||
Headers Map `yaml:"headers" envconfig:"HEADERS"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove Headers as it can be configured via
OTEL_EXPORTER_OTLP_TRACES_HEADERS
pkg/taskqueue/redis.go
Outdated
@@ -91,6 +93,12 @@ func NewRedisQueue(opts RedisTaskQueueOptions, logger *zap.SugaredLogger, metric | |||
} | |||
|
|||
func (q *RedisTaskQueue) Add(ctx context.Context, tasks []*TaskMessage) error { | |||
if tracer := tracing.TracerFromContext(ctx); tracer != nil { | |||
tracingCtx, span := tracer.Start(context.Background(), "queue.add", trace.WithSpanKind(trace.SpanKindClient)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracingCtx, span := tracer.Start(context.Background(), "queue.add", trace.WithSpanKind(trace.SpanKindClient)) | |
tracingCtx, span := tracer.Start(ctx, "queue.add", trace.WithSpanKind(trace.SpanKindClient)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change queue.*
to taskqueue.*
as it may get confused with the proxy queue.
|
feat(observability): correct config feat(observability): fix otelsql tracing missing
9e1a1c5
to
55b0ef5
Compare
No description provided.