Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(ctx context.Context, options ...Options) (shutdown func(context.Context) error, err error)
Init initialises the global OTEL trace and metric providers and returns a shutdown function that flushes and closes them. Call the shutdown function before your process exits to ensure all pending telemetry is exported.
When Enabled is false (the default unless OTEL_ENABLED=true), a no-op shutdown function is returned immediately.
Usage — rely entirely on environment variables:
shutdown, err := telemetry.Init(ctx)
Usage — override specific fields in code:
shutdown, err := telemetry.Init(ctx, telemetry.Options{ServiceName: "my-service"})
Types ¶
type Options ¶
type Options struct {
// Enabled controls whether telemetry is initialised. Maps to OTEL_ENABLED.
Enabled bool
// Host is the OTEL collector hostname. Maps to OTEL_HOST.
Host string
// Port is the OTEL collector port. Maps to OTEL_PORT.
Port string
// ServiceName is reported as the service.name resource attribute. Maps to OTEL_SERVICE_NAME.
ServiceName string
// Environment is reported as the deployment.environment attribute. Maps to ENVIRONMENT.
Environment string
// Protocol selects the export transport: "grpc" (port 4317) or "http" (port 4318).
// Maps to OTEL_PROTOCOL.
Protocol string
// Insecure disables TLS on the collector connection. Maps to OTEL_INSECURE.
Insecure bool
// MetricInterval controls how often metrics are pushed to the collector.
// Defaults to 30 seconds.
MetricInterval time.Duration
}
Options configures the OTEL telemetry providers. All fields are optional — zero values are filled from environment variables (see getOptions).
Click to show internal directories.
Click to hide internal directories.