Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitGrafana ¶
InitGrafana initializes the global tracer and metric providers for OpenTelemetry, configured to send telemetry data to Grafana Cloud or any compatible OTLP endpoint.
It sets up: - Distributed tracing using the OTLP HTTP exporter - Metrics collection via OTLP HTTP exporter - Runtime metrics for Go applications (memory, GC, goroutines, etc.) - Custom application metrics defined in the metrics package
The function returns a shutdown function that should be registered with a runner instance. This shutdown function will be called during application termination to ensure proper cleanup.
Example:
r := runner.New()
shutdown, err := otel.InitGrafana(ctx, otel.Config{
GrafanaEndpoint: "https://otlp-sentinel-prod-us-east-0.grafana.net/otlp",
Namespace: "app",
Application: "api",
Version: version.Version,
})
if err != nil {
log.Fatalf("Failed to initialize telemetry: %v", err)
}
r.RegisterShutdown(shutdown)
// The runner will call shutdown during graceful termination
Types ¶
type Config ¶
type Config struct {
// InstanceID is a unique identifier for the current service instance,
// used to distinguish between multiple instances of the same service.
InstanceID string
// CloudRegion indicates the geographic region where this service instance is running,
// which helps with identifying regional performance patterns or issues.
CloudRegion string
// Namespace indicates the service namespace
Namespace string
// Application is the name of your application, used to identify the source of telemetry data.
// This appears in Grafana dashboards and alerts.
Application string
// Version is the current version of your application, allowing you to correlate
// behavior changes with specific releases.
Version string
// TraceSampleRate controls what percentage of traces are sampled.
// Values range from 0.0 to 1.0, where:
// - 1.0 means all traces are sampled (100%)
// - 0.25 means 25% of traces are sampled (the default if not specified)
// - 0.0 means no traces are sampled (0%)
//
// As long as the sampling rate is greater than 0.0, all errors will be sampled.
TraceSampleRate float64
// PrometheusGatherer is the prometheus registry to gather metrics from when
// bridging prometheus metrics into OTLP. If nil, the default prometheus
// registry is used (which is almost certainly wrong when lazy metrics register
// to a custom registry).
PrometheusGatherer promclient.Gatherer
}
Config defines the configuration settings for OpenTelemetry integration with Grafana. It specifies connection details and application metadata needed for proper telemetry.