tracing

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v1.0.8

Init initializes the OpenTelemetry tracer provider with the specified configuration. It sets up a trace pipeline by configuring exporters and resource attributes.

The function automatically merges provided configuration with defaults and sets up appropriate OTLP exporters based on the environment configuration. It also configures host and runtime metrics if enabled in the configuration.

Parameters:

  • ctx: The context for controlling tracer initialization lifetime
  • config: The configuration containing tracer setup options and metrics settings

Returns:

  • context.Context: Updated context with tracer provider
  • *trace.TracerProvider: Configured tracer provider for creating spans
  • error: Non-nil if initialization fails

Example:

config := tracing.Config{
    HostMetricsEnabled: true,
    RuntimeMetricsEnabled: true,
    HostMetricsInterval: 5 * time.Second,
}
ctx, provider, err := tracing.Init(context.Background(), config)
if err != nil {
    log.Fatal(err)
}
defer func() {
    if err := provider.Shutdown(ctx); err != nil {
        log.Printf("failed to shutdown provider: %v", err)
    }
}()

func Shutdown added in v1.2.0

func Shutdown(ctx context.Context, traceProvider *trace.TracerProvider) error

Shutdown gracefully shuts down the tracer provider and flushes any pending spans. It should be called when the application is terminating to ensure all traces are exported.

Parameters:

  • ctx: The context for controlling shutdown timeout
  • traceProvider: The provider instance to shut down

Returns:

  • error: Non-nil if shutdown fails

Example:

ctx := context.Background()
ctx, provider, err := tracing.Init(ctx, tracing.Config{})
if err != nil {
    log.Fatal(err)
}
defer tracing.Shutdown(ctx, provider)

Types

type Config added in v1.1.0

type Config struct {
	HostMetricsEnabled     bool          `json:"host_metrics_enabled"`     // HostMetricsEnabled specifies whether host metrics are enabled. Default is false.
	HostMetricsInterval    time.Duration `json:"host_metrics_interval"`    // HostMetricsInterval specifies the interval at which host metrics are collected. Default is 2 seconds.
	RuntimeMetricsEnabled  bool          `json:"runtime_metrics_enabled"`  // RuntimeMetricsEnabled specifies whether runtime metrics are enabled. Default is false.
	RuntimeMetricsInterval time.Duration `json:"runtime_metrics_interval"` // RuntimeMetricsInterval specifies the interval at which runtime metrics are collected. Default is 2 seconds.
}

The Config type is used to configure whether host metrics are enabled or not. @property {bool} HostMetricsEnabled - A boolean value that indicates whether host metrics are enabled or not.

Jump to

Keyboard shortcuts

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