Documentation
¶
Overview ¶
Package telemetry initializes OpenTelemetry global using the OpenTelemetry declarative configuration API. It also provides some deprecated legacy metrics wrapper functions and metrics configuration using github.com/hashicorp/go-metrics. By default, this package configures the github.com/hashicorp/go-metrics default instance to send all metrics to OpenTelemetry. Existing users of the legacy wrapper functions in this package should begin to migrate their code to use OpenTelemetry APIs directly.
Index ¶
- Constants
- func EnableTelemetry()deprecated
- func IncrCounter(val float32, keys ...string)deprecated
- func IncrCounterWithLabels(keys []string, val float32, labels []metrics.Label)deprecated
- func InitializeOpenTelemetry(filePath string) error
- func IsOtelLoggerEnabled() bool
- func IsTelemetryEnabled() booldeprecated
- func MeasureSince(start time.Time, keys ...string)deprecated
- func ModuleMeasureSince(module string, start time.Time, keys ...string)deprecated
- func ModuleSetGauge(module string, val float32, keys ...string)deprecated
- func NewLabel(name, value string) metrics.Labeldeprecated
- func Now() time.Timedeprecated
- func SetGauge(val float32, keys ...string)deprecated
- func SetGaugeWithLabels(keys []string, val float32, labels []metrics.Label)deprecated
- func Shutdown(ctx context.Context) error
- func TestingMain(m *testing.M, ctx context.Context)
- type Configdeprecated
- type DisplayableSinkdeprecated
- type ExtensionOptions
- type GatherResponse
- type Metricsdeprecated
Constants ¶
const ( // Deprecated: FormatDefault is the default format for metrics gathering. FormatDefault = "" // Deprecated: FormatPrometheus indicates Prometheus format for metrics gathering. FormatPrometheus = "prometheus" // Deprecated: FormatText indicates text format for metrics gathering. FormatText = "text" // Deprecated: ContentTypeText is the content type for text formatted metrics. ContentTypeText = `text/plain; version=` + expfmt.TextVersion + `; charset=utf-8` // Deprecated: MetricSinkInMem indicates in-memory metrics sink. MetricSinkInMem = "mem" // Deprecated: MetricSinkPrometheus indicates Prometheus metrics sink. MetricSinkStatsd = "statsd" // Deprecated: MetricSinkDogsStatsd indicates DogStatsD metrics sink. MetricSinkDogsStatsd = "dogstatsd" // Deprecated: MetricSinkOtel indicates OpenTelemetry metrics sink. MetricSinkOtel = "otel" )
Metrics supported format types.
const ( MetricKeyPreBlocker = "pre_blocker" MetricKeyBeginBlocker = "begin_blocker" MetricKeyEndBlocker = "end_blocker" MetricLabelNameModule = "module" )
Common metric key constants
const (
OtelFileName = "otel.yaml"
)
Variables ¶
This section is empty.
Functions ¶
func EnableTelemetry
deprecated
added in
v0.53.0
func EnableTelemetry()
Deprecated: EnableTelemetry allows for the global telemetry enabled state to be set.
func IncrCounter
deprecated
func IncrCounterWithLabels
deprecated
func InitializeOpenTelemetry ¶ added in v0.54.0
InitializeOpenTelemetry initializes the OpenTelemetry SDK. We assume that the otel configuration file is in `~/.<your_node_home>/config/otel.yaml`. An empty otel.yaml is automatically placed in the directory above in the `appd init` command.
Note that a late initialization of the open telemetry SDK causes meters/tracers to utilize a delegate, which incurs an atomic load. In our benchmarks, we saw only a few nanoseconds incurred from this atomic operation. If you wish to avoid this overhead entirely, you may set the OTEL_EXPERIMENTAL_CONFIG_FILE environment variable,' and the OpenTelemetry SDK will be instantiated via init. This will eliminate the atomic operation overhead.
func IsOtelLoggerEnabled ¶ added in v0.54.0
func IsOtelLoggerEnabled() bool
IsOtelLoggerEnabled reports whether the global OTel log pipeline has active exporters. It returns false for the noop provider or any real provider with no log processors configured.
func IsTelemetryEnabled
deprecated
added in
v0.50.6
func IsTelemetryEnabled() bool
Deprecated: IsTelemetryEnabled provides controlled access to check if telemetry is enabled.
func MeasureSince
deprecated
func ModuleMeasureSince
deprecated
func ModuleSetGauge
deprecated
func SetGaugeWithLabels
deprecated
func TestingMain ¶ added in v0.54.0
TestingMain should be used in tests where you want to run telemetry and need clean shutdown behavior at the end of the test, for instance to collect benchmark metrics. If ctx is nil, context.Background() is used. Example:
func TestMain(m *testing.M) {
telemetry.TestingMain(m, nil)
}
Types ¶
type Config
deprecated
type Config struct {
// Prefixed with keys to separate services
ServiceName string `mapstructure:"service-name"`
// Enabled enables the application telemetry functionality. When enabled,
// an in-memory sink is also enabled by default. Operators may also enable
// other sinks such as Prometheus.
Enabled bool `mapstructure:"enabled"`
// Enable prefixing gauge values with hostname
EnableHostname bool `mapstructure:"enable-hostname"`
// Enable adding hostname to labels
EnableHostnameLabel bool `mapstructure:"enable-hostname-label"`
// Enable adding service to labels
EnableServiceLabel bool `mapstructure:"enable-service-label"`
// PrometheusRetentionTime, when positive, enables a Prometheus metrics sink.
// It defines the retention duration in seconds.
PrometheusRetentionTime int64 `mapstructure:"prometheus-retention-time"`
// GlobalLabels defines a global set of name/value label tuples applied to all
// metrics emitted using the wrapper functions defined in telemetry package.
//
// Example:
// [["chain_id", "cosmoshub-1"]]
GlobalLabels [][]string `mapstructure:"global-labels"`
// MetricsSink defines the type of metrics backend to use.
// Can be one of "mem", "statsd", "dogstatsd", or "otel".
MetricsSink string `mapstructure:"metrics-sink" default:"mem"`
// StatsdAddr defines the address of a statsd server to send metrics to.
// Only utilized if MetricsSink is set to "statsd" or "dogstatsd".
StatsdAddr string `mapstructure:"statsd-addr"`
// DatadogHostname defines the hostname to use when emitting metrics to
// Datadog. Only utilized if MetricsSink is set to "dogstatsd".
DatadogHostname string `mapstructure:"datadog-hostname"`
}
Config is the telemetry configuration.
Deprecated: Use OpenTelemetry instead.
type DisplayableSink
deprecated
added in
v0.50.2
type ExtensionOptions ¶ added in v0.54.0
type ExtensionOptions struct {
// TraceFile is an optional path to a file where spans should be exported
// using the stdouttrace exporter. If empty, no file-based trace export is
// configured.
TraceFile string `json:"trace_file" yaml:"trace_file" mapstructure:"trace_file"`
// MetricsFile is an optional path to a file where metrics should be written
// using the stdoutmetric exporter. If unset, no file-based metrics export
// is performed.
MetricsFile string `json:"metrics_file" yaml:"metrics_file" mapstructure:"metrics_file"`
// MetricsFileInterval defines how frequently metric data should be flushed
// to MetricsFile. It must be a valid Go duration string (e.g. "10s",
// "1m"). If empty, the default PeriodicReader interval is used.
MetricsFileInterval string `json:"metrics_file_interval" yaml:"metrics_file_interval" mapstructure:"metrics_file_interval"`
// LogsFile is an optional output file for structured logs exported through
// the stdoutlog exporter. If unset, log exporting to file is disabled.
LogsFile string `json:"logs_file" yaml:"logs_file" mapstructure:"logs_file"`
// Instruments is a map of instrument names to their optional configuration.
// Presence of a key enables the instrument. The value is an optional map of
// instrument-specific settings. See each instrument package for available options.
//
// Example:
// instruments:
// host: {}
// runtime: {}
// diskio:
// disable_virtual_device_filter: true
Instruments map[string]map[string]any `json:"instruments" yaml:"instruments" mapstructure:"instruments"`
// Propagators configures additional or alternative TextMapPropagators
// (e.g. "tracecontext", "baggage", "b3", "b3multi", "jaeger").
Propagators []string `json:"propagators" yaml:"propagators" mapstructure:"propagators"`
}
ExtensionOptions provides configuration for OpenTelemetry features not yet supported by otelconf, such as writing traces/metrics/logs to local files, enabling additional host/runtime instrumentation, and configuring custom propagators.
When present in otel.yaml under the `extensions` key, these fields augment/override portions of the OpenTelemetry SDK initialization.
For an example configuration, see the README in this package.
type GatherResponse ¶
GatherResponse is the response type of registered metrics
Depreacated: users should switch to OpenTelemetry.
type Metrics
deprecated
type Metrics struct {
// contains filtered or unexported fields
}
Metrics defines a wrapper around application telemetry functionality. It allows metrics to be gathered at any point in time. When creating a Metrics object, internally, a global metrics is registered with a set of sinks as configured by the operator. In addition to the sinks, when a process gets a SIGUSR1, a dump of formatted recent metrics will be sent to STDERR.
Deprecated: users should switch to OpenTelemetry.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package registry provides an instrument registry for telemetry instrumentation.
|
Package registry provides an instrument registry for telemetry instrumentation. |
|
util
|
|
|
diskio
Package diskio provides an implementation of the disk I/O metrics following the OpenTelemetry semantic conventions for system metrics specified here: https://opentelemetry.io/docs/specs/semconv/system/system-metrics/.
|
Package diskio provides an implementation of the disk I/O metrics following the OpenTelemetry semantic conventions for system metrics specified here: https://opentelemetry.io/docs/specs/semconv/system/system-metrics/. |
|
host
Package host provides a telemetry instrument wrapper for host-level metrics.
|
Package host provides a telemetry instrument wrapper for host-level metrics. |
|
runtime
Package runtime provides a telemetry instrument wrapper for Go runtime metrics.
|
Package runtime provides a telemetry instrument wrapper for Go runtime metrics. |