Skip to content

Commit

Permalink
Allow setting of Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBergmeier6176 committed Feb 8, 2024
1 parent bd628f7 commit d324d26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.0.55 Allow setting of Extensions
- Introduces `ApplyCloudEventOptions` for applying Options to CloudEvents

## v0.0.51 Allow passing of Test Clients
- Introduces `FakeSetup`, which allows for passing TestClients along.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.21.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator v0.45.0
github.com/cloudevents/sdk-go/protocol/pubsub/v2 v2.14.0
github.com/cloudevents/sdk-go/v2 v2.14.0
github.com/google/go-cmp v0.6.0
go.opentelemetry.io/otel v1.22.0
go.opentelemetry.io/otel/sdk v1.22.0
Expand All @@ -37,7 +38,6 @@ require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
github.com/cloudevents/sdk-go/v2 v2.14.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.16.0+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
Expand Down
20 changes: 20 additions & 0 deletions pkg/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import (

"cloud.google.com/go/errorreporting"
cepubsub "github.com/cloudevents/sdk-go/protocol/pubsub/v2"
"github.com/cloudevents/sdk-go/v2/event"
"github.com/otto-de/sherlock-microservice/pkg/gcp/errorreports"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)

type Option struct {
extensions map[string]any
orderingKey string
}

func WithExtensions(extensions map[string]any) Option {
return Option{
extensions: extensions,
}
}

func WithOrderingKey(orderingKey string) Option {
return Option{
orderingKey: orderingKey,
Expand Down Expand Up @@ -44,6 +52,18 @@ func ApplyCloudEventsPubSubOrderingKey(ctx context.Context, opts ...Option) cont
return ctx
}

func ApplyCloudEventOptions(ctx context.Context, event *event.Event, opts ...Option) context.Context {
ctx = ApplyCloudEventsPubSubOrderingKey(ctx, opts...)
for _, opt := range opts {
if opt.extensions != nil {
for k, v := range opt.extensions {
event.SetExtension(k, v)
}
}
}
return ctx
}

// PanicPublisher wraps a Publisher.
// Panics if publishing fails.
type PanicPublisher[EV any] struct {
Expand Down

0 comments on commit d324d26

Please sign in to comment.