Documentation

Overview

Package obsreport provides unified and consistent observability signals ( metrics, tracing, etc) for components of the OpenTelemetry collector.

The function Configure is used to control which signals are going to be generated. It provides functions for the typical operations of receivers, processors, and exporters.

Receivers should use the respective start and end according to the data type being received, ie.:

* Traces receive operations should use the pair:
	StartTracesOp/EndTracesOp

* Metrics receive operations should use the pair:
	StartMetricsOp/EndMetricsOp

* Logs receive operations should use the pair:
	StartLogsOp/EndLogsOp

Similar for exporters:

* Traces export operations should use the pair:
	StartTracesOp/EndTracesOp

* Metrics export operations should use the pair:
	StartMetricsOp/EndMetricsOp

* Metrics export operations should use the pair:
	StartLogsOp/EndLogsOp

The package is capable of generating legacy metrics by using the observability package allowing a controlled transition from legacy to the new metrics. The goal is to eventually remove the legacy metrics and use only the new metrics.

The main differences regarding the legacy metrics are:

1. "Amount of metric data" is measured as metric points (ie.: a single value in time), contrast it with number of time series used legacy. Number of metric data points is a more general concept regarding various metric formats.

2. Exporters measure the number of items, ie.: number of spans or metric points, that were sent and the ones for which the attempt to send failed. For more information about this see Notes below about reporting data loss.

3. All measurements of "amount of data" used in the new metrics for receivers and exporters should reflect their native formats, not the internal format used in the Collector. This is to facilitate reconciliation between Collector, client and backend. For instance: certain metric formats do not provide direct support for histograms and have predefined conventions to represent those, this conversion may end with a different number of time series and data points than the internal Collector format.

Notes:

* Data loss should be recorded only when the component itself remove the data from the pipeline. Legacy metrics for receivers used "dropped" in their names but these could be non-zero under normal operations and reflected no actual data loss when exporters with "sending_queue" are used. New metrics were renamed to avoid this misunderstanding. Here are the general recommendations to report data loss:

* Receivers reporting errors to clients typically result in the client
  re-sending the same data so it is more correct to report "receive errors",
  not actual data loss.

* Exporters need to report individual failures to send data, but on
  typical production pipelines processors usually take care of retries,
  so these should be reported as "send errors".

* Data "filtered out" should have its own metrics and not be confused
  with dropped data.

Naming Convention for New Metrics

Common Metrics: Metrics shared by different components should follow the convention below:

`<component>/<metric_name>`

As a label the metric should have at least `{<component>="<name>"}` where `<name>` is the name used in the configuration for the instance of the component, eg.:

`receiver/accepted_spans{receiver="opencensus",...}` `exporter/sent_spans{exporter="jaeger/prod",...}`

Component Specific Metrics: These metrics are implemented by specific components, eg.: batch processor. The general pattern is the same as the common metrics but with the addition of the component type (as it appears in the configuration) before the actual metric:

`<component>/<type>/<metric_name>`

Even metrics exclusive to a single type should follow the conventions above and also include the type (as written in the configuration) as part of the metric name since there could be multiple instances of the same type in different pipelines, eg.:

`processor/batch/batch_size_trigger_send{processor="batch/dev",...}`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildProcessorCustomMetricName

func BuildProcessorCustomMetricName(configType, metric string) string

BuildProcessorCustomMetricName is used to be build a metric name following the standards used in the Collector. The configType should be the same value used to identify the type on the config.

func EndMetricsScrapeOp

func EndMetricsScrapeOp(
	scraperCtx context.Context,
	numScrapedMetrics int,
	err error,
)

EndMetricsScrapeOp completes the scrape operation that was started with StartMetricsScrapeOp.

func ReceiverContext

func ReceiverContext(
	ctx context.Context,
	receiverID config.ComponentID,
	transport string,
) context.Context

ReceiverContext adds the keys used when recording observability metrics to the given context returning the newly created context. This context should be used in related calls to the obsreport functions so metrics are properly recorded.

func ScraperContext

func ScraperContext(
	ctx context.Context,
	receiverID config.ComponentID,
	scraper config.ComponentID,
) context.Context

ScraperContext adds the keys used when recording observability metrics to the given context returning the newly created context. This context should be used in related calls to the obsreport functions so metrics are properly recorded.

func StartMetricsScrapeOp

func StartMetricsScrapeOp(
	scraperCtx context.Context,
	receiverID config.ComponentID,
	scraper config.ComponentID,
) context.Context

StartMetricsScrapeOp is called when a scrape operation is started. The returned context should be used in other calls to the obsreport functions dealing with the same scrape operation.

Types

type Exporter

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

Exporter is a helper to add observability to a component.Exporter.

func NewExporter

func NewExporter(cfg ExporterSettings) *Exporter

NewExporter creates a new Exporter.

func (*Exporter) EndLogsOp

func (eor *Exporter) EndLogsOp(ctx context.Context, numLogRecords int, err error)

EndLogsOp completes the export operation that was started with StartLogsOp.

func (*Exporter) EndMetricsOp

func (eor *Exporter) EndMetricsOp(ctx context.Context, numMetricPoints int, err error)

EndMetricsOp completes the export operation that was started with StartMetricsOp.

func (*Exporter) EndTracesOp

func (eor *Exporter) EndTracesOp(ctx context.Context, numSpans int, err error)

EndTracesOp completes the export operation that was started with StartTracesOp.

func (*Exporter) StartLogsOp

func (eor *Exporter) StartLogsOp(ctx context.Context) context.Context

StartLogsOp is called at the start of an Export operation. The returned context should be used in other calls to the Exporter functions dealing with the same export operation.

func (*Exporter) StartMetricsOp

func (eor *Exporter) StartMetricsOp(ctx context.Context) context.Context

StartMetricsOp is called at the start of an Export operation. The returned context should be used in other calls to the Exporter functions dealing with the same export operation.

func (*Exporter) StartTracesOp

func (eor *Exporter) StartTracesOp(ctx context.Context) context.Context

StartTracesOp is called at the start of an Export operation. The returned context should be used in other calls to the Exporter functions dealing with the same export operation.

type ExporterSettings

type ExporterSettings struct {
	Level      configtelemetry.Level
	ExporterID config.ComponentID
}

ExporterSettings are settings for creating an Exporter.

type Processor

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

Processor is a helper to add observability to a component.Processor.

func NewProcessor

func NewProcessor(cfg ProcessorSettings) *Processor

NewProcessor creates a new Processor.

func (*Processor) LogsAccepted

func (por *Processor) LogsAccepted(ctx context.Context, numRecords int)

LogsAccepted reports that the logs were accepted.

func (*Processor) LogsDropped

func (por *Processor) LogsDropped(ctx context.Context, numRecords int)

LogsDropped reports that the logs were dropped.

func (*Processor) LogsRefused

func (por *Processor) LogsRefused(ctx context.Context, numRecords int)

LogsRefused reports that the logs were refused.

func (*Processor) MetricsAccepted

func (por *Processor) MetricsAccepted(ctx context.Context, numPoints int)

MetricsAccepted reports that the metrics were accepted.

func (*Processor) MetricsDropped

func (por *Processor) MetricsDropped(ctx context.Context, numPoints int)

MetricsDropped reports that the metrics were dropped.

func (*Processor) MetricsRefused

func (por *Processor) MetricsRefused(ctx context.Context, numPoints int)

MetricsRefused reports that the metrics were refused.

func (*Processor) TracesAccepted

func (por *Processor) TracesAccepted(ctx context.Context, numSpans int)

TracesAccepted reports that the trace data was accepted.

func (*Processor) TracesDropped

func (por *Processor) TracesDropped(ctx context.Context, numSpans int)

TracesDropped reports that the trace data was dropped.

func (*Processor) TracesRefused

func (por *Processor) TracesRefused(ctx context.Context, numSpans int)

TracesRefused reports that the trace data was refused.

type ProcessorSettings

type ProcessorSettings struct {
	Level       configtelemetry.Level
	ProcessorID config.ComponentID
}

ProcessorSettings are settings for creating a Processor.

type Receiver

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

Receiver is a helper to add obersvability to a component.Receiver.

func NewReceiver

func NewReceiver(cfg ReceiverSettings) *Receiver

NewReceiver creates a new Receiver.

func (*Receiver) EndLogsOp

func (rec *Receiver) EndLogsOp(
	receiverCtx context.Context,
	format string,
	numReceivedLogRecords int,
	err error,
)

EndLogsOp completes the receive operation that was started with StartLogsOp.

func (*Receiver) EndMetricsOp

func (rec *Receiver) EndMetricsOp(
	receiverCtx context.Context,
	format string,
	numReceivedPoints int,
	err error,
)

EndMetricsOp completes the receive operation that was started with StartMetricsOp.

func (*Receiver) EndTracesOp

func (rec *Receiver) EndTracesOp(
	receiverCtx context.Context,
	format string,
	numReceivedSpans int,
	err error,
)

EndTracesOp completes the receive operation that was started with StartTracesOp.

func (*Receiver) StartLogsOp

func (rec *Receiver) StartLogsOp(operationCtx context.Context, opt ...StartReceiveOption) context.Context

StartLogsOp is called when a request is received from a client. The returned context should be used in other calls to the obsreport functions dealing with the same receive operation.

func (*Receiver) StartMetricsOp

func (rec *Receiver) StartMetricsOp(operationCtx context.Context, opt ...StartReceiveOption) context.Context

StartMetricsOp is called when a request is received from a client. The returned context should be used in other calls to the obsreport functions dealing with the same receive operation.

func (*Receiver) StartTracesOp

func (rec *Receiver) StartTracesOp(operationCtx context.Context, opt ...StartReceiveOption) context.Context

StartTracesOp is called when a request is received from a client. The returned context should be used in other calls to the obsreport functions dealing with the same receive operation.

type ReceiverSettings

type ReceiverSettings struct {
	ReceiverID config.ComponentID
	Transport  string
}

ReceiverSettings are settings for creating an Receiver.

type StartReceiveOption

type StartReceiveOption func(*startReceiveOptions)

StartReceiveOption function applues changes to startReceiveOptions.

func WithLongLivedCtx

func WithLongLivedCtx() StartReceiveOption

WithLongLivedCtx indicates that the context passed in the call outlives the receive operation at hand. Typically the long lived context is associated to a connection, eg.: a gRPC stream or a TCP connection, for which many batches of data are received in individual operations without a corresponding new context per operation.

Example:

func (r *receiver) ClientConnect(ctx context.Context, rcvChan <-chan pdata.Traces) {
    longLivedCtx := obsreport.ReceiverContext(ctx, r.config.Name(), r.transport, "")
    for {
        // Since the context outlives the individual receive operations call obsreport using
        // WithLongLivedCtx().
        ctx := obsreport.StartTracesOp(
            longLivedCtx,
            r.config.Name(),
            r.transport,
            obsreport.WithLongLivedCtx())

        td, ok := <-rcvChan
        var err error
        if ok {
            err = r.nextConsumer.ConsumeTraces(ctx, td)
        }
        obsreport.EndTracesOp(
            ctx,
            r.format,
            len(td.Spans),
            err)
        if !ok {
            break
        }
    }
}

Directories

Path Synopsis