otel_pkg

package
v1.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 15 Imported by: 0

README ¶

📦 Package otel_pkg

Source Path: pkg/otel

🧩 Types

ExporterFactory

ExporterFactory is a function that creates a trace exporter.

type ExporterFactory func(ctx context.Context) (sdktrace.SpanExporter, error)
mockExporter

mockExporter is a no-op SpanExporter for testing purposes.

type mockExporter struct {
}
Methods
ExportSpans

ExportSpans implements sdktrace.SpanExporter.ExportSpans.

It is a no-op, and always returns nil.

func (m *mockExporter) ExportSpans(_ context.Context, _ []sdktrace.ReadOnlySpan) error
Shutdown

Shutdown does nothing and returns no error.

func (m *mockExporter) Shutdown(_ context.Context) error

🚀 Functions

DefaultExporterFactory

DefaultExporterFactory creates an OTLP GRPC trace exporter based on the environment variable OTEL_ENDPOINT. The exporter is configured to be insecure, meaning it does not validate the server's certificate.

This function should be used as a fallback when no other exporter factory is specified.

func DefaultExporterFactory(ctx context.Context) (sdktrace.SpanExporter, error)
InitTracerProvider

InitTracerProvider initializes an OpenTelemetry TracerProvider for a given service. It sets up a trace exporter using the OTLP gRPC protocol and configures the TracerProvider with resource attributes such as service name, version, and environment. It also sets up a batch span processor and a composite text map propagator for context propagation.

Parameters:

  • service: The name of the service for which the TracerProvider is being initialized.
  • ctx: The context for managing the lifecycle of the TracerProvider and trace exporter.

Returns:

  • A function to shut down the TracerProvider, releasing any resources held.
  • An error if there was a failure during the initialization of the trace exporter or resource.
func InitTracerProvider(service string, ctx context.Context) (func(context.Context) error, error)
TestInitTracerProvider_WithMockExporter

TestInitTracerProvider_WithMockExporter tests that initTracerProviderWithExporter returns a valid shutdown function that can be used to shut down the TracerProvider.

It also checks that the shutdown function returns no error when called.

func TestInitTracerProvider_WithMockExporter(t *testing.T)
fakeExporterFactory

fakeExporterFactory is a fake ExporterFactory for testing purposes, which returns a no-op SpanExporter.

func fakeExporterFactory(_ context.Context) (sdktrace.SpanExporter, error)
initTracerProviderWithExporter

initTracerProviderWithExporter initializes an OpenTelemetry TracerProvider for a given service using the given trace exporter factory. It sets up a trace exporter using the OTLP gRPC protocol and configures the TracerProvider with resource attributes such as service name, version, and environment. It also sets up a batch span processor and a composite text map propagator for context propagation.

Parameters:

  • service: The name of the service for which the TracerProvider is being initialized.
  • ctx: The context for managing the lifecycle of the TracerProvider and trace exporter.
  • factory: A function that creates a trace exporter.

Returns:

  • A function to shut down the TracerProvider, releasing any resources held.
  • An error if there was a failure during the initialization of the trace exporter or resource.
func initTracerProviderWithExporter(service string, ctx context.Context, factory ExporterFactory) (func(context.Context) error, error)

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Config ¶ added in v1.0.22

type Config struct {
	ServiceName            string
	ServiceVersion         string
	Environment            string
	Endpoint               string
	Insecure               bool
	EnableRuntimeMetrics   bool
	RuntimeMetricsInterval time.Duration
}

type Telemetry ¶ added in v1.0.22

type Telemetry struct {
	// contains filtered or unexported fields
}

func NewTelemetry ¶ added in v1.0.22

func NewTelemetry(config Config) *Telemetry

func (*Telemetry) GetLogger ¶ added in v1.0.22

func (t *Telemetry) GetLogger() *sdklog.LoggerProvider

func (*Telemetry) Init ¶ added in v1.0.22

func (t *Telemetry) Init(ctx context.Context) error

func (*Telemetry) InitLogger ¶ added in v1.0.22

func (t *Telemetry) InitLogger(ctx context.Context) error

func (*Telemetry) InitMeter ¶ added in v1.0.22

func (t *Telemetry) InitMeter(ctx context.Context) error

func (*Telemetry) InitRuntimeMetrics ¶ added in v1.0.22

func (t *Telemetry) InitRuntimeMetrics() error

func (*Telemetry) InitTracer ¶ added in v1.0.22

func (t *Telemetry) InitTracer(ctx context.Context) error

func (*Telemetry) Shutdown ¶ added in v1.0.22

func (t *Telemetry) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL