otel

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPRequestMethodKey      = attribute.Key("http.request.method")
	HTTPResponseStatusCodeKey = attribute.Key("http.response.status_code")
	HTTPUrlPathKey            = attribute.Key("url.path")
	HTTPUrlFullKey            = attribute.Key("url.full")
	ClientAddrKey             = attribute.Key("client.address")
	ClientPortKey             = attribute.Key("client.port")
	ServerAddrKey             = attribute.Key("server.address")
	ServerPortKey             = attribute.Key("server.port")
	HTTPRequestBodySizeKey    = attribute.Key("http.request.body.size")
	HTTPResponseBodySizeKey   = attribute.Key("http.response.body.size")
	SpanKindKey               = attribute.Key("span.kind")
	SpanNameKey               = attribute.Key("span.name")
	StatusCodeKey             = attribute.Key("status.code")
	SourceKey                 = attribute.Key("source")
	ServiceKey                = attribute.Key("service")
	InstanceKey               = attribute.Key("instance")
	ClientKey                 = attribute.Key("client")
	ClientNamespaceKey        = attribute.Key("client_service_namespace")
	ServerKey                 = attribute.Key("server")
	ServerNamespaceKey        = attribute.Key("server_service_namespace")
	ConnectionTypeKey         = attribute.Key("connection_type")
)

OpenTelemetry 1.23 semantic convention

View Source
const (
	HTTPServerDuration    = "http.server.request.duration"
	HTTPClientDuration    = "http.client.request.duration"
	RPCServerDuration     = "rpc.server.duration"
	RPCClientDuration     = "rpc.client.duration"
	SQLClientDuration     = "sql.client.duration"
	HTTPServerRequestSize = "http.server.request.body.size"
	HTTPClientRequestSize = "http.client.request.body.size"
	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 ClientAddr added in v0.4.2

func ClientAddr(val string) attribute.KeyValue

func ClientMetric added in v1.5.0

func ClientMetric(val string) attribute.KeyValue

func ClientNamespaceMetric added in v1.5.0

func ClientNamespaceMetric(val string) attribute.KeyValue

func ClientPort added in v0.4.2

func ClientPort(val int) attribute.KeyValue

func ConnectionTypeMetric added in v1.5.0

func ConnectionTypeMetric(val string) attribute.KeyValue

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 HTTPRequestBodySize added in v0.4.2

func HTTPRequestBodySize(val int) attribute.KeyValue

func HTTPRequestMethod added in v0.4.2

func HTTPRequestMethod(val string) attribute.KeyValue

func HTTPResponseBodySize added in v0.4.2

func HTTPResponseBodySize(val int) attribute.KeyValue

func HTTPResponseStatusCode added in v0.4.2

func HTTPResponseStatusCode(val int) attribute.KeyValue

func HTTPUrlFull added in v0.4.2

func HTTPUrlFull(val string) attribute.KeyValue

func HTTPUrlPath added in v0.4.2

func HTTPUrlPath(val string) attribute.KeyValue

func HandleTraceparent added in v1.4.0

func HandleTraceparent(parentCtx context.Context, span *request.Span) context.Context

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 RandomSpanID added in v1.5.0

func RandomSpanID() trace.SpanID

func RandomTraceID added in v1.5.0

func RandomTraceID() trace.TraceID

func ReportMetrics

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

func ReportTraces

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

func Resource added in v1.5.0

func Resource(service svc.ID) *resource.Resource

func ServerAddr added in v0.4.2

func ServerAddr(val string) attribute.KeyValue

func ServerMetric added in v1.5.0

func ServerMetric(val string) attribute.KeyValue

func ServerNamespaceMetric added in v1.5.0

func ServerNamespaceMetric(val string) attribute.KeyValue

func ServerPort added in v0.4.2

func ServerPort(val int) attribute.KeyValue

func ServiceInstanceMetric added in v1.5.0

func ServiceInstanceMetric(val string) attribute.KeyValue

func ServiceMetric added in v1.5.0

func ServiceMetric(val string) attribute.KeyValue

func SetupInternalOTELSDKLogger added in v0.4.1

func SetupInternalOTELSDKLogger(levelStr string)

func SourceMetric added in v1.5.0

func SourceMetric(val string) attribute.KeyValue

func SpanKind added in v1.4.0

func SpanKind(span *request.Span) trace2.SpanKind

func SpanKindMetric added in v1.5.0

func SpanKindMetric(val string) attribute.KeyValue

func SpanKindString added in v1.5.0

func SpanKindString(span *request.Span) string

func SpanNameMetric added in v1.5.0

func SpanNameMetric(val string) attribute.KeyValue

func SpanStartTime added in v1.4.0

func SpanStartTime(t request.Timings) time.Time

func SpanStatusCode added in v1.4.0

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

func StatusCodeMetric added in v1.5.0

func StatusCodeMetric(val int) attribute.KeyValue

func TraceAttributes added in v1.4.0

func TraceAttributes(span *request.Span) []attribute.KeyValue

func TraceName added in v1.4.0

func TraceName(span *request.Span) string

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
	ReportTarget   bool `yaml:"report_target" env:"BEYLA_METRICS_REPORT_TARGET"`
	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 Tracers added in v0.1.0

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

Tracers handles the OTEL traces providers and exporters. There is a Tracers instance for each instrumented service/process.

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

func (*TracesConfig) GetProtocol

func (m *TracesConfig) GetProtocol() Protocol

func (*TracesConfig) GuessProtocol added in v0.2.0

func (m *TracesConfig) GuessProtocol() Protocol

type TracesReporter

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

TracesReporter implement the graph node that receives request.Span instances and forwards them as OTEL traces.

Jump to

Keyboard shortcuts

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