Documentation ¶
Index ¶
- Variables
- func NewMeterProvider(cfg Config, det resource.Detector, mr metric.Reader) (*metric.MeterProvider, error)
- func NewMetricExporter(cfg Config) (metric.Exporter, error)
- func NewTracerProvider(cfg Config, logs *zap.Logger, exp sdktrace.SpanExporter, det resource.Detector, ...) (*sdktrace.TracerProvider, error)
- func WithExtraEcsAttributes(d resource.Detector) resource.Detector
- type Config
Constants ¶
This section is empty.
Variables ¶
View Source
var Base = fx.Module(moduleName, fx.Decorate(func(l *zap.Logger) *zap.Logger { return l.Named(moduleName) }), fx.Provide(fx.Annotate( func(o env.Options) (c Config, err error) { o.Prefix = strings.ToUpper(moduleName) + "_" return c, env.Parse(&c, o) }, fx.ParamTags(`optional:"true"`))), fx.Provide(fx.Annotate(xray.NewIDGenerator, fx.As(new(sdktrace.IDGenerator)))), fx.Provide(func() propagation.TextMapPropagator { xp := xray.Propagator{}; return xp }), fx.Provide(fx.Annotate(NewTracerProvider, fx.OnStop(func(ctx context.Context, tp *sdktrace.TracerProvider) error { return tp.Shutdown(ctx) }), )), fx.Provide(func(tp *sdktrace.TracerProvider) trace.TracerProvider { return tp }), fx.Provide(fx.Annotate(NewMeterProvider)), fx.Provide(func(mp *sdkmetric.MeterProvider) metric.MeterProvider { return mp }), )
Base module with di setup Base between test and prod environment
View Source
var Service = fx.Options(Base, fx.Provide(fx.Annotate(newGrpcExporter, fx.OnStart(func(ctx context.Context, e *otlptrace.Exporter) error { return e.Start(ctx) }), fx.OnStop(func(ctx context.Context, e *otlptrace.Exporter) error { return e.Shutdown(ctx) }), )), fx.Provide(func(e *otlptrace.Exporter) sdktrace.SpanExporter { return e }), fx.Provide(ecs.NewResourceDetector), fx.Decorate(WithExtraEcsAttributes), fx.Provide(sdkmetric.NewPeriodicReader), fx.Provide(NewMetricExporter), )
Service provides otel dependencies for container services
View Source
var Test = fx.Options(Base, fx.Provide(sdkmetric.NewManualReader), fx.Provide(fx.Annotate(tracetest.NewInMemoryExporter)), fx.Provide(func(e *tracetest.InMemoryExporter) sdktrace.SpanExporter { return e }), fx.Provide(func() resource.Detector { return resource.StringDetector(semconv.SchemaURL, semconv.ServiceNameKey, func() (string, error) { return "ClTest", nil }) }), )
Test configures the DI for a test environment
Functions ¶
func NewMeterProvider ¶ added in v0.6.0
func NewMeterProvider(cfg Config, det resource.Detector, mr metric.Reader) (*metric.MeterProvider, error)
NewMeterProvider initiales otel provider for metrics throughout the application
func NewMetricExporter ¶ added in v0.6.0
NewMetricExporter inits a metric exporter
func NewTracerProvider ¶ added in v0.6.0
func NewTracerProvider( cfg Config, logs *zap.Logger, exp sdktrace.SpanExporter, det resource.Detector, idg sdktrace.IDGenerator, pr propagation.TextMapPropagator, ) (*sdktrace.TracerProvider, error)
NewTracerProvider inits a tracer provider
Types ¶
type Config ¶
type Config struct { // DetectorDetectTimeout bound the time it may take to init a trace provider DetectorDetectTimeout time.Duration `env:"DETECTOR_DETECT_TIMEOUT" envDefault:"1s"` // ExporterTimeout overwrites the timeout for exporting spans. This can be usefull in tests to speed // them up ExporterTimeout time.Duration `env:"EXPORTER_TIMEOUT" envDefault:"10s"` // ExporterEndpoint configures where otel span exporter will send data to ExporterEndpoint string `env:"EXPORTER_ENDPOINT" envDefault:"localhost:4317"` // MetricExporterConnectTimeout configures how long we'll wait for het metric exporter to connect to the collector MetricExporterConnectTimeout time.Duration `env:"METRIC_EXPORTER_CONNECT_TIMEOUT" envDefault:"1s"` }
Config configures the code in this package.
Click to show internal directories.
Click to hide internal directories.