cloudevents / sdk-go

Go SDK for CloudEvents
https://cloudevents.github.io/sdk-go/
Apache License 2.0
836 stars 221 forks source link

Make it possible to configure the ObservabilityService into the NewHTTPReceiveHandler method #1090

Open simone-livraghi-globant opened 3 months ago

simone-livraghi-globant commented 3 months ago

When you invoke the NewHTTPReceiveHandler method, a noopObservabilityService is set by default, and you cannot change it.

`func NewHTTPReceiveHandler(ctx context.Context, p thttp.Protocol, fn interface{}) (EventReceiver, error) { invoker, err := newReceiveInvoker(fn, noopObservabilityService{}, nil, nil, false) //TODO(slinkydeveloper) maybe not nil? if err != nil { return nil, err }

return &EventReceiver{
    p:       p,
    invoker: invoker,
}, nil

}`

Other methods instead have the Option varargs to configure it. For example with this one: func WithObservabilityService(service ObservabilityService) Option { return func(i interface{}) error { if c, ok := i.(*ceClient); ok { c.observabilityService = service c.inboundContextDecorators = append(c.inboundContextDecorators, service.InboundContextDecorators()...) } return nil } }

Can WithObservabilityService be made available in the NewHTTPReceiveHandler method?