otel

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 0 Imported by: 0

README

Goxkit OpenTelemetry

License Go Doc Go Report Card

The otel package provides shared utilities for OpenTelemetry integration across the Goxkit ecosystem. It contains common functionality used by the tracing, metrics, and logging packages for working with the OpenTelemetry Protocol (OTLP).

Features

  • OTLP gRPC Integration: Utilities for creating optimized gRPC connections to OpenTelemetry collectors
  • Configuration Integration: Seamless integration with the Goxkit configs package
  • Connection Resilience: Built-in reconnection strategies, keepalive mechanisms, and backoff policies
  • Common Foundation: Shared components for use by the specialized observability packages

Overview

This package serves as a foundation for the observability tools in Goxkit. Rather than implementing complete functionality by itself, it provides shared utilities that are used by the more specialized packages:

  • github.com/goxkit/tracing: For distributed tracing
  • github.com/goxkit/metrics: For application and system metrics
  • github.com/goxkit/logging: For structured logging

The separation allows for more focused packages while sharing common code for OpenTelemetry integration.

Usage

OTLP gRPC Connection
package main

import (
	"github.com/goxkit/configs"
	"github.com/goxkit/otel/otlp_grpc"
)

func main() {
	// Get your application configs
	cfgs := &configs.Configs{
		OTLPConfigs: &configs.OTLPConfigs{
			Endpoint:               "localhost:4317",
			ExporterIdleTimeout:    30 * time.Second,
			ExporterKeepAliveTime:  5 * time.Second,
			ExporterKeepAliveTimeout: 1 * time.Second,
		},
	}
	
	// Create a gRPC connection to the OTLP collector
	conn, err := otlpgrpc.NewExporterGRPCClient(cfgs)
	if err != nil {
		panic(err)
	}
	defer conn.Close()
	
	// Use the connection with OpenTelemetry exporters
	// ...
}

Using with ConfigsBuilder

The recommended approach is to use this package indirectly through the configs_builder package, which handles proper initialization of all observability components:

package main

import (
	"github.com/goxkit/configs_builder"
)

func main() {
	// Create configurations with all observability components enabled
	cfgs, err := configsBuilder.NewConfigsBuilder().
		Otlp().    // Enables OpenTelemetry for tracing, metrics, and logging
		Build()
	if err != nil {
		panic(err)
	}
	
	// All OpenTelemetry components are now configured and ready to use
	// cfgs.Logger - configured logger
	// cfgs.TracerProvider - configured tracer provider
	// cfgs.MeterProvider - configured meter provider
}

Configuration Options

The following configuration options are used by this package:

Setting Environment Variable Description
Endpoint OTEL_EXPORTER_OTLP_ENDPOINT OTLP collector endpoint (default: localhost:4317)
ExporterIdleTimeout OTEL_EXPORTER_IDLE_TIMEOUT Maximum idle time before connection is closed
ExporterKeepAliveTime OTEL_EXPORTER_KEEPALIVE_TIME Interval between keepalive pings
ExporterKeepAliveTimeout OTEL_EXPORTER_KEEPALIVE_TIMEOUT Time to wait for keepalive ack

License

MIT

Documentation

Overview

Package otel provides OpenTelemetry integration utilities for Goxkit applications. It serves as a common foundation for observability components including tracing, metrics, and logging with OpenTelemetry Protocol (OTLP) export capabilities.

The package is designed to provide shared components across different observability packages in the Goxkit ecosystem, enabling consistent configuration and setup.

Directories

Path Synopsis
Package otlpgrpc provides gRPC client connection utilities for OpenTelemetry OTLP exporters.
Package otlpgrpc provides gRPC client connection utilities for OpenTelemetry OTLP exporters.

Jump to

Keyboard shortcuts

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