otel

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SpanMetricsLatency and rest of metrics below haven't been yet moved to the
	// pkg/internal/export/metric package as we are disabling user-provided attribute
	// selection for them. They are very specific metrics with an opinionated format
	// for Span Metrics and Service Graph Metrics functionalities
	SpanMetricsLatency = "traces_spanmetrics_latency"
	SpanMetricsCalls   = "traces_spanmetrics_calls_total"
	SpanMetricsSizes   = "traces_spanmetrics_size_total"
	TracesTargetInfo   = "traces_target_info"
	ServiceGraphClient = "traces_service_graph_request_client"
	ServiceGraphServer = "traces_service_graph_request_server"
	ServiceGraphFailed = "traces_service_graph_request_failed_total"
	ServiceGraphTotal  = "traces_service_graph_request_total"

	UsualPortGRPC = "4317"
	UsualPortHTTP = "4318"

	AggregationExplicit    = "explicit_bucket_histogram"
	AggregationExponential = "base2_exponential_bucket_histogram"

	FeatureNetwork     = "network"
	FeatureApplication = "application"
	FeatureSpan        = "application_span"
	FeatureGraph       = "application_service_graph"
)

Variables

View Source
var DefaultBuckets = Buckets{

	DurationHistogram: []float64{0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10},

	RequestSizeHistogram: []float64{0, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192},
}

Functions

func ContextWithTrace added in v1.1.0

func ContextWithTrace(parent context.Context, traceID trace.TraceID) context.Context

func ContextWithTraceParent added in v1.1.0

func ContextWithTraceParent(parent context.Context, traceID trace.TraceID, spanID trace.SpanID) context.Context

func GenerateTraces added in v1.6.0

func GenerateTraces(span *request.Span, userAttrs map[attr.Name]struct{}) ptrace.Traces

GenerateTraces creates a ptrace.Traces from a request.Span

func GetUserSelectedAttributes added in v1.6.0

func GetUserSelectedAttributes(attrs attributes.Selection) (map[attr.Name]struct{}, error)

func InstantiateMetricsExporter added in v1.3.0

func InstantiateMetricsExporter(ctx context.Context, cfg *MetricsConfig, log *slog.Logger) (metric.Exporter, error)

TODO: restore as private

func ReportMetrics

func ReportMetrics(
	ctx context.Context,
	ctxInfo *global.ContextInfo,
	cfg *MetricsConfig,
	userAttribSelection attributes.Selection,
) pipe.FinalProvider[[]request.Span]

func SetupInternalOTELSDKLogger added in v0.4.1

func SetupInternalOTELSDKLogger(levelStr string)

func SpanKindString added in v1.5.0

func SpanKindString(span *request.Span) string

func SpanStatusCode added in v1.4.0

func SpanStatusCode(span *request.Span) codes.Code

func TraceName added in v1.4.0

func TraceName(span *request.Span) string

func TracesReceiver added in v1.6.0

func TracesReceiver(ctx context.Context, cfg TracesConfig, ctxInfo *global.ContextInfo, userAttribSelection attributes.Selection) pipe.FinalProvider[[]request.Span]

TracesReceiver creates a terminal node that consumes request.Spans and sends OpenTelemetry metrics to the configured consumers.

Types

type BeylaIDGenerator added in v1.1.0

type BeylaIDGenerator struct{}

func (*BeylaIDGenerator) NewIDs added in v1.1.0

func (*BeylaIDGenerator) NewSpanID added in v1.1.0

func (e *BeylaIDGenerator) NewSpanID(ctx context.Context, _ trace.TraceID) trace.SpanID

type Buckets

type Buckets struct {
	DurationHistogram    []float64 `yaml:"duration_histogram"`
	RequestSizeHistogram []float64 `yaml:"request_size_histogram"`
}

Buckets defines the histograms bucket boundaries, and allows users to redefine them

type GrafanaConfig added in v0.4.1

type GrafanaConfig struct {
	// OTLP endpoint from Grafana Cloud.
	OTLP GrafanaOTLP `yaml:"otlp"`
}

GrafanaConfig simplifies the submission of information to Grafana Cloud, but it can be actually used for any OTEL endpoint, as it uses the standard OTEL authentication under the hood

type GrafanaOTLP added in v0.4.1

type GrafanaOTLP struct {
	// Submit accepts a comma-separated list of the kind of data that will be submitted to the
	// OTLP endpoint. It accepts `metrics` and/or `traces` as values.
	Submit []string `yaml:"cloud_submit" env:"GRAFANA_CLOUD_SUBMIT"`

	// CloudZone of your Grafana Endpoint. For example: prod-eu-west-0.
	CloudZone string `yaml:"cloud_zone" env:"GRAFANA_CLOUD_ZONE"`

	// InstanceID is your Grafana user name. It is usually a number but it must be set as a
	// string inside the YAML file.
	InstanceID string `yaml:"cloud_instance_id" env:"GRAFANA_CLOUD_INSTANCE_ID"`

	// APIKey of your Grafana Cloud account.
	APIKey string `yaml:"cloud_api_key" env:"GRAFANA_CLOUD_API_KEY"`
}

func (*GrafanaOTLP) AuthHeader added in v0.4.1

func (cfg *GrafanaOTLP) AuthHeader() string

func (*GrafanaOTLP) Endpoint added in v0.4.1

func (cfg *GrafanaOTLP) Endpoint() string

func (*GrafanaOTLP) MetricsEnabled added in v0.4.1

func (cfg *GrafanaOTLP) MetricsEnabled() bool

func (*GrafanaOTLP) TracesEnabled added in v0.4.1

func (cfg *GrafanaOTLP) TracesEnabled() bool

type LogrAdaptor added in v0.4.1

type LogrAdaptor struct {
	// contains filtered or unexported fields
}

LogrAdaptor allows using our on logger to peek any warning or error in the OTEL exporters

func (*LogrAdaptor) Enabled added in v0.4.1

func (l *LogrAdaptor) Enabled(level int) bool

Enabled returns, according to OTEL internal description: To see Warn messages use a logger with `l.V(1).Enabled() == true` To see Info messages use a logger with `l.V(4).Enabled() == true` To see Debug messages use a logger with `l.V(8).Enabled() == true`. However, we will "degrade" their info messages to our log level, as they leak many internal information that is not interesting for the final user.

func (*LogrAdaptor) Error added in v0.4.1

func (l *LogrAdaptor) Error(err error, msg string, keysAndValues ...interface{})

func (*LogrAdaptor) Info added in v0.4.1

func (l *LogrAdaptor) Info(level int, msg string, keysAndValues ...interface{})

func (*LogrAdaptor) Init added in v0.4.1

func (l *LogrAdaptor) Init(_ logr.RuntimeInfo)

func (*LogrAdaptor) WithName added in v0.4.1

func (l *LogrAdaptor) WithName(name string) logr.LogSink

func (*LogrAdaptor) WithValues added in v0.4.1

func (l *LogrAdaptor) WithValues(keysAndValues ...interface{}) logr.LogSink

type Metrics added in v0.1.0

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics is a set of metrics associated to a given OTEL MeterProvider. There is a Metrics instance for each service/process instrumented by Beyla.

type MetricsConfig

type MetricsConfig struct {
	Interval time.Duration `yaml:"interval" env:"BEYLA_METRICS_INTERVAL"`

	CommonEndpoint  string `yaml:"-" env:"OTEL_EXPORTER_OTLP_ENDPOINT"`
	MetricsEndpoint string `yaml:"endpoint" env:"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"`

	Protocol        Protocol `yaml:"protocol" env:"OTEL_EXPORTER_OTLP_PROTOCOL"`
	MetricsProtocol Protocol `yaml:"-" env:"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL"`

	// InsecureSkipVerify is not standard, so we don't follow the same naming convention
	InsecureSkipVerify bool `yaml:"insecure_skip_verify" env:"BEYLA_OTEL_INSECURE_SKIP_VERIFY"`

	// ReportTarget specifies whether http.target should be submitted as a metric attribute. It is disabled by
	// default to avoid cardinality explosion in paths with IDs. In that case, it is recommended to group these
	// requests in the Routes node
	// Deprecated. Going to be removed in Beyla 2.0. Use attributes.select instead
	ReportTarget bool `yaml:"report_target" env:"BEYLA_METRICS_REPORT_TARGET"`
	// Deprecated. Going to be removed in Beyla 2.0. Use attributes.select instead
	ReportPeerInfo bool `yaml:"report_peer" env:"BEYLA_METRICS_REPORT_PEER"`

	Buckets              Buckets `yaml:"buckets"`
	HistogramAggregation string  `yaml:"histogram_aggregation" env:"OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION"`

	ReportersCacheLen int `yaml:"reporters_cache_len" env:"BEYLA_METRICS_REPORT_CACHE_LEN"`

	// SDKLogLevel works independently from the global LogLevel because it prints GBs of logs in Debug mode
	// and the Info messages leak internal details that are not usually valuable for the final user.
	SDKLogLevel string `yaml:"otel_sdk_log_level" env:"BEYLA_OTEL_SDK_LOG_LEVEL"`

	// Features of metrics that are can be exported. Accepted values are "application" and "network".
	// envDefault is provided to avoid breaking changes
	Features []string `yaml:"features" env:"BEYLA_OTEL_METRICS_FEATURES,expand" envDefault:"${BEYLA_OTEL_METRIC_FEATURES}"  envSeparator:","`

	// TTL is the time since a metric was updated for the last time until it is
	// removed from the metrics set.
	TTL time.Duration `yaml:"ttl" env:"BEYLA_OTEL_METRICS_TTL"`

	// Grafana configuration needs to be explicitly set up before building the graph
	Grafana *GrafanaOTLP `yaml:"-"`
}

func (MetricsConfig) Enabled

func (m MetricsConfig) Enabled() bool

func (MetricsConfig) EndpointEnabled added in v1.5.0

func (m MetricsConfig) EndpointEnabled() bool

EndpointEnabled specifies that the OTEL metrics node is enabled if and only if either the OTEL endpoint and OTEL metrics endpoint is defined. If not enabled, this node won't be instantiated Reason to disable linting: it requires to be a value despite it is considered a "heavy struct". This method is invoked only once during startup time so it doesn't have a noticeable performance impact. nolint:gocritic

func (*MetricsConfig) GetProtocol

func (m *MetricsConfig) GetProtocol() Protocol

func (*MetricsConfig) GuessProtocol added in v0.2.0

func (m *MetricsConfig) GuessProtocol() Protocol

func (MetricsConfig) OTelMetricsEnabled added in v1.5.0

func (m MetricsConfig) OTelMetricsEnabled() bool

func (MetricsConfig) ServiceGraphMetricsEnabled added in v1.5.0

func (m MetricsConfig) ServiceGraphMetricsEnabled() bool

func (MetricsConfig) SpanMetricsEnabled added in v1.5.0

func (m MetricsConfig) SpanMetricsEnabled() bool

type MetricsReporter

type MetricsReporter struct {
	// contains filtered or unexported fields
}

MetricsReporter implements the graph node that receives request.Span instances and forwards them as OTEL metrics.

type Protocol

type Protocol string

Protocol values for the OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL and OTEL_EXPORTER_OTLP_METRICS_PROTOCOL standard configuration values More info: https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/

const (
	ProtocolUnset        Protocol = ""
	ProtocolGRPC         Protocol = "grpc"
	ProtocolHTTPProtobuf Protocol = "http/protobuf"
	ProtocolHTTPJSON     Protocol = "http/json"
)

type ReporterPool added in v0.1.0

type ReporterPool[T any] struct {
	// contains filtered or unexported fields
}

ReporterPool keeps an LRU cache of different OTEL reporters given a service name. TODO: evict reporters after a time without being accessed

func NewReporterPool added in v0.1.0

func NewReporterPool[T any](
	cacheLen int,
	callback simplelru.EvictCallback[svc.UID, T],
	itemConstructor func(id svc.ID) (T, error),
) ReporterPool[T]

NewReporterPool creates a ReporterPool instance given a cache length, an eviction callback to be invoked each time an element is removed from the cache, and a constructor function that will specify how to instantiate the generic OTEL metrics/traces reporter.

func (*ReporterPool[T]) For added in v0.1.0

func (rp *ReporterPool[T]) For(service svc.ID) (T, error)

For retrieves the associated item for the given service name, or creates a new one if it does not exist

type Sampler added in v0.4.1

type Sampler struct {
	Name string `yaml:"name" env:"OTEL_TRACES_SAMPLER"`
	Arg  string `yaml:"arg" env:"OTEL_TRACES_SAMPLER_ARG"`
}

Sampler standard configuration https://opentelemetry.io/docs/concepts/sdk-configuration/general-sdk-configuration/#otel_traces_sampler We don't support, yet, the jaeger and xray samplers.

func (*Sampler) Implementation added in v0.4.1

func (s *Sampler) Implementation() trace.Sampler

type TracesConfig

type TracesConfig struct {
	CommonEndpoint string `yaml:"-" env:"OTEL_EXPORTER_OTLP_ENDPOINT"`
	TracesEndpoint string `yaml:"endpoint" env:"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"`

	Protocol       Protocol `yaml:"protocol" env:"OTEL_EXPORTER_OTLP_PROTOCOL"`
	TracesProtocol Protocol `yaml:"-" env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"`

	// InsecureSkipVerify is not standard, so we don't follow the same naming convention
	InsecureSkipVerify bool `yaml:"insecure_skip_verify" env:"BEYLA_OTEL_INSECURE_SKIP_VERIFY"`

	Sampler Sampler `yaml:"sampler"`

	// Configuration options below this line will remain undocumented at the moment,
	// but can be useful for performance-tuning of some customers.
	MaxExportBatchSize int           `yaml:"max_export_batch_size" env:"BEYLA_OTLP_TRACES_MAX_EXPORT_BATCH_SIZE"`
	MaxQueueSize       int           `yaml:"max_queue_size" env:"BEYLA_OTLP_TRACES_MAX_QUEUE_SIZE"`
	BatchTimeout       time.Duration `yaml:"batch_timeout" env:"BEYLA_OTLP_TRACES_BATCH_TIMEOUT"`
	ExportTimeout      time.Duration `yaml:"export_timeout" env:"BEYLA_OTLP_TRACES_EXPORT_TIMEOUT"`

	ReportersCacheLen int `yaml:"reporters_cache_len" env:"BEYLA_TRACES_REPORT_CACHE_LEN"`

	// SDKLogLevel works independently from the global LogLevel because it prints GBs of logs in Debug mode
	// and the Info messages leak internal details that are not usually valuable for the final user.
	SDKLogLevel string `yaml:"otel_sdk_log_level" env:"BEYLA_OTEL_SDK_LOG_LEVEL"`

	// Grafana configuration needs to be explicitly set up before building the graph
	Grafana *GrafanaOTLP `yaml:"-"`
}

func (TracesConfig) Enabled

func (m TracesConfig) Enabled() bool

Enabled specifies that the OTEL traces node is enabled if and only if either the OTEL endpoint and OTEL traces endpoint is defined. If not enabled, this node won't be instantiated

Jump to

Keyboard shortcuts

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