@@ -22,19 +22,21 @@ import (
2222 cloudevents "github.com/cloudevents/sdk-go/v2"
2323 "github.com/google/uuid"
2424 "go.uber.org/zap"
25+ "k8s.io/apimachinery/pkg/types"
2526 "k8s.io/client-go/tools/cache"
2627 "knative.dev/eventing/pkg/adapter/apiserver/events"
2728 "knative.dev/eventing/pkg/eventfilter"
29+ "knative.dev/eventing/pkg/observability"
2830)
2931
3032type resourceDelegate struct {
3133 ce cloudevents.Client
3234 source string
3335 ref bool
3436 apiServerSourceName string
37+ apiServerSourceNS string
3538 filter eventfilter.Filter
36-
37- logger * zap.SugaredLogger
39+ logger * zap.SugaredLogger
3840}
3941
4042var _ cache.Store = (* resourceDelegate )(nil )
@@ -82,6 +84,14 @@ func (a *resourceDelegate) sendCloudEvent(ctx context.Context, event cloudevents
8284 subject := event .Context .GetSubject ()
8385 a .logger .Debugf ("sending cloudevent id: %s, source: %s, subject: %s" , event .ID (), source , subject )
8486
87+ // Add labels to context so otelhttp picks them up for metrics
88+ ctx = observability .WithLabeler (ctx )
89+ ctx = observability .WithSourceLabels (ctx , types.NamespacedName {
90+ Name : a .apiServerSourceName ,
91+ Namespace : a .apiServerSourceNS ,
92+ })
93+ ctx = observability .WithMinimalEventLabels (ctx , & event )
94+
8595 if result := a .ce .Send (ctx , event ); ! cloudevents .IsACK (result ) {
8696 a .logger .Errorw ("failed to send cloudevent" , zap .Error (result ), zap .String ("source" , source ),
8797 zap .String ("subject" , subject ), zap .String ("id" , event .ID ()))
0 commit comments