Skip to content

Commit

Permalink
eventbus supports configurable
Browse files Browse the repository at this point in the history
Signed-off-by: jyjiangkai <[email protected]>
  • Loading branch information
hwjiangkai committed Jul 17, 2023
1 parent 7ddd6ed commit 14cc0d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/trigger/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (elReader *eventlogReader) loop(ctx context.Context, lr api.BusReader) erro
if err = elReader.putEvent(ctx, eo); err != nil {
span.RecordError(err, trace.WithTimestamp(time.Now()))
span.SetStatus(otelcode.Error, "put event to el reader failed")
span.End()
return err
}
elReader.offset = offset
Expand Down
10 changes: 9 additions & 1 deletion observability/tracing/exporter/event_trace_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ type Option func(*Options)

type Options struct {
Endpoints string
Eventbus string
}

func defaultOptions() *Options {
return &Options{
Endpoints: "127.0.0.1:8080",
Eventbus: "event-tracing",
}
}

Expand All @@ -44,6 +46,12 @@ func WithEndpoint(endpoint string) Option {
}
}

func WithEventbus(eventbus string) Option {
return func(options *Options) {
options.Eventbus = eventbus
}
}

// Exporter exports trace data in the OTLP wire format.
type Exporter struct {
endpoints string
Expand All @@ -69,7 +77,7 @@ func New(ctx context.Context, opts ...Option) (*Exporter, error) {
panic("failed to connect to Vanus cluster, error: " + err.Error())
}

ebOpt := vanussdk.WithEventbus("default", "tracing")
ebOpt := vanussdk.WithEventbus("default", defaultOpts.Eventbus)
exporter := &Exporter{
endpoints: defaultOpts.Endpoints,
client: c,
Expand Down
5 changes: 4 additions & 1 deletion observability/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Config struct {
OtelCollector string `yaml:"otel_collector"`
EventTracingEnable bool `yaml:"event_tracing_enable"`
EventCollector string `yaml:"event_collector"`
Eventbus string `yaml:"eventbus"`
}

var tp *tracerProvider
Expand Down Expand Up @@ -188,7 +189,9 @@ func newTracerProvider(serviceName string, cfg Config) (*trace.TracerProvider, e

if cfg.EventTracingEnable && cfg.EventCollector != "" {
// Set up a event exporter
eventExporter, err := exporter.New(ctx, exporter.WithEndpoint(cfg.EventCollector))
endpoint := exporter.WithEndpoint(cfg.EventCollector)
eventbus := exporter.WithEventbus(cfg.Eventbus)
eventExporter, err := exporter.New(ctx, endpoint, eventbus)
if err != nil {
return nil, fmt.Errorf("failed to create event exporter: %w", err)
}
Expand Down

0 comments on commit 14cc0d1

Please sign in to comment.