rename ExporterWithConfig to be less confusing and closer to otel

This commit is contained in:
Natalia Goc 2024-05-17 15:36:35 +02:00
parent 3c51f5575b
commit d4dc790298
2 changed files with 18 additions and 14 deletions

View File

@ -11,7 +11,7 @@ import (
"git.ma-al.com/gora_filip/observer/pkg/tracer" "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/attr/layer_attr"
"git.ma-al.com/gora_filip/pkg/exporters" "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" "git.ma-al.com/gora_filip/pkg/level"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@ -31,17 +31,21 @@ func main() {
if err == nil { if err == nil {
exps = append(exps, gelfExp) 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", AppName: "example",
Version: "0.0.0", Version: "0.0.0",
ServiceProvider: "maal", ServiceProvider: "maal",
Exporters: exps, Exporters: exps,
})) }))
defer fiber_tracing.ShutdownTracer() defer tracing.ShutdownTracer()
main.Get("/", func(c *fiber.Ctx) error { 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, Level: level.DEBUG,
}.AsOpts()) }.AsOpts())
defer span.End() defer span.End()

View File

@ -15,8 +15,8 @@ type TraceExporter interface {
IntoTraceProviderOption() traceProviderOpt IntoTraceProviderOption() traceProviderOpt
} }
func NewFromSpanExporter(exporter sdktrace.SpanExporter) ExporterWithConfig { func NewFromSpanExporter(exporter sdktrace.SpanExporter) ExporterWithOptions {
return ExporterWithConfig{ return ExporterWithOptions{
exporter: exporter, exporter: exporter,
} }
} }
@ -37,18 +37,18 @@ func NewFromSpanProcessor(processor sdktrace.SpanProcessor) TraceExporter {
} }
// Combined exporter with batch processor config // Combined exporter with batch processor config
type ExporterWithConfig struct { type ExporterWithOptions struct {
exporter sdktrace.SpanExporter exporter sdktrace.SpanExporter
config []sdktrace.BatchSpanProcessorOption opts []sdktrace.BatchSpanProcessorOption
} }
func (ecfg ExporterWithConfig) Add(opt sdktrace.BatchSpanProcessorOption) ExporterWithConfig { func (ecfg ExporterWithOptions) AddOption(opt sdktrace.BatchSpanProcessorOption) ExporterWithOptions {
ecfg.config = append(ecfg.config, opt) ecfg.opts = append(ecfg.opts, opt)
return ecfg return ecfg
} }
func (ecfg ExporterWithConfig) IntoTraceProviderOption() traceProviderOpt { func (ecfg ExporterWithOptions) IntoTraceProviderOption() traceProviderOpt {
return sdktrace.WithBatcher(ecfg.exporter, ecfg.config...) return sdktrace.WithBatcher(ecfg.exporter, ecfg.opts...)
} }
// An exporter printing to console with very small delay // An exporter printing to console with very small delay
@ -63,14 +63,14 @@ func DevConsoleExporter(opts ...console_exporter.ProcessorOptions) TraceExporter
} }
// Default exporter to Graylog. // 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...) gelfExp, err := gelf_exporter.New(opts...)
return NewFromSpanExporter(gelfExp), err return NewFromSpanExporter(gelfExp), err
} }
// Exporter for traces over HTTP. Can be used with Jaeger. // Exporter for traces over HTTP. Can be used with Jaeger.
// See documentation of [otlhttp_exporter] for details. // 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...) otlpExp, err := otlphttp_exporter.New(context.Background(), opts...)
return NewFromSpanExporter(otlpExp), err return NewFromSpanExporter(otlpExp), err
} }