From d4dc790298f8eb90dc5bd6837979bb5df7469efb Mon Sep 17 00:00:00 2001 From: Natalia Goc Date: Fri, 17 May 2024 15:36:35 +0200 Subject: [PATCH] rename ExporterWithConfig to be less confusing and closer to otel --- example/main.go | 12 ++++++++---- pkg/exporters/exporters.go | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/example/main.go b/example/main.go index a5d8a0f..460f447 100644 --- a/example/main.go +++ b/example/main.go @@ -11,7 +11,7 @@ import ( "git.ma-al.com/gora_filip/observer/pkg/tracer" "git.ma-al.com/gora_filip/pkg/attr/layer_attr" "git.ma-al.com/gora_filip/pkg/exporters" - "git.ma-al.com/gora_filip/pkg/fiber_tracing" + tracing "git.ma-al.com/gora_filip/pkg/fiber_tracing" "git.ma-al.com/gora_filip/pkg/level" "github.com/gofiber/fiber/v2" ) @@ -31,17 +31,21 @@ func main() { if err == nil { exps = append(exps, gelfExp) } + jaegerExp, err := exporters.OtlpHTTPExporter() + if err == nil { + exps = append(exps, jaegerExp) + } - main.Use(fiber_tracing.NewMiddleware(fiber_tracing.Config{ + main.Use(tracing.NewMiddleware(tracing.Config{ AppName: "example", Version: "0.0.0", ServiceProvider: "maal", Exporters: exps, })) - defer fiber_tracing.ShutdownTracer() + defer tracing.ShutdownTracer() main.Get("/", func(c *fiber.Ctx) error { - ctx, span := fiber_tracing.FStart(c, layer_attr.Handler{ + ctx, span := tracing.FStart(c, layer_attr.Handler{ Level: level.DEBUG, }.AsOpts()) defer span.End() diff --git a/pkg/exporters/exporters.go b/pkg/exporters/exporters.go index c337fa0..4482e77 100644 --- a/pkg/exporters/exporters.go +++ b/pkg/exporters/exporters.go @@ -15,8 +15,8 @@ type TraceExporter interface { IntoTraceProviderOption() traceProviderOpt } -func NewFromSpanExporter(exporter sdktrace.SpanExporter) ExporterWithConfig { - return ExporterWithConfig{ +func NewFromSpanExporter(exporter sdktrace.SpanExporter) ExporterWithOptions { + return ExporterWithOptions{ exporter: exporter, } } @@ -37,18 +37,18 @@ func NewFromSpanProcessor(processor sdktrace.SpanProcessor) TraceExporter { } // Combined exporter with batch processor config -type ExporterWithConfig struct { +type ExporterWithOptions struct { exporter sdktrace.SpanExporter - config []sdktrace.BatchSpanProcessorOption + opts []sdktrace.BatchSpanProcessorOption } -func (ecfg ExporterWithConfig) Add(opt sdktrace.BatchSpanProcessorOption) ExporterWithConfig { - ecfg.config = append(ecfg.config, opt) +func (ecfg ExporterWithOptions) AddOption(opt sdktrace.BatchSpanProcessorOption) ExporterWithOptions { + ecfg.opts = append(ecfg.opts, opt) return ecfg } -func (ecfg ExporterWithConfig) IntoTraceProviderOption() traceProviderOpt { - return sdktrace.WithBatcher(ecfg.exporter, ecfg.config...) +func (ecfg ExporterWithOptions) IntoTraceProviderOption() traceProviderOpt { + return sdktrace.WithBatcher(ecfg.exporter, ecfg.opts...) } // An exporter printing to console with very small delay @@ -63,14 +63,14 @@ func DevConsoleExporter(opts ...console_exporter.ProcessorOptions) TraceExporter } // Default exporter to Graylog. -func GelfExporter(opts ...gelf_exporter.Option) (ExporterWithConfig, error) { +func GelfExporter(opts ...gelf_exporter.Option) (ExporterWithOptions, error) { gelfExp, err := gelf_exporter.New(opts...) return NewFromSpanExporter(gelfExp), err } // Exporter for traces over HTTP. Can be used with Jaeger. // See documentation of [otlhttp_exporter] for details. -func OtlpHTTPExporter(opts ...otlphttp_exporter.Option) (ExporterWithConfig, error) { +func OtlpHTTPExporter(opts ...otlphttp_exporter.Option) (ExporterWithOptions, error) { otlpExp, err := otlphttp_exporter.New(context.Background(), opts...) return NewFromSpanExporter(otlpExp), err }