package exporters import ( "context" "time" "git.ma-al.com/gora_filip/pkg/exporters/console_exporter" gelf_exporter "git.ma-al.com/gora_filip/pkg/exporters/gelf_exporter" otlphttp_exporter "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) func NewWithConfig(exporter sdktrace.SpanExporter) ExporterWithConfig { return ExporterWithConfig{ exporter: exporter, } } // Combined exporter with batch processor config type ExporterWithConfig struct { exporter sdktrace.SpanExporter config []sdktrace.BatchSpanProcessorOption } func (ecfg ExporterWithConfig) Add(opt sdktrace.BatchSpanProcessorOption) ExporterWithConfig { ecfg.config = append(ecfg.config, opt) return ecfg } func (ecfg ExporterWithConfig) IntoTraceProviderOption() sdktrace.TracerProviderOption { return sdktrace.WithBatcher(ecfg.exporter, ecfg.config...) } // An exporter printing to console with very small delay func DevConsoleExporter(opts ...console_exporter.ExporterOptions) ExporterWithConfig { batchTimeout := (time.Millisecond * 250) exportTimeout := (time.Millisecond * 250) var exporter ExporterWithConfig if len(opts) > 0 { exporter = NewWithConfig(console_exporter.NewExporter(opts[0])) } else { exporter = NewWithConfig(console_exporter.DefaultConsoleExporter()) } return exporter.Add(sdktrace.WithBatchTimeout(batchTimeout)).Add(sdktrace.WithExportTimeout(exportTimeout)) } // Default exporter to Graylog. func GelfExporter(opts ...gelf_exporter.Option) (ExporterWithConfig, error) { gelfExp, err := gelf_exporter.New(opts...) return NewWithConfig(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) { otlpExp, err := otlphttp_exporter.New(context.Background(), opts...) return NewWithConfig(otlpExp), err }