Documentation
¶
Overview ¶
Package otelbeat implements beat.Handler using OpenTelemetry metrics. New accepts an application-provided Meter. The application owns the SDK, Resource, Views, reader/exporter and shutdown; stop beat before the provider.
Instruments ¶
beat.run.duration records Job duration in seconds; its count counts completed runs. beat.run.saturation records Duration / Period. beat.run.lateness records nonnegative Start minus ScheduledFor in seconds. beat.processed accumulates Job-reported items. These instruments carry mode and outcome attributes. DefaultOutcome uses Record.Outcome, or "unknown" when it is empty. WithOutcome supplies a custom classifier; keep its output to a small fixed set.
beat.missed accumulates unintentional grid losses and carries mode alone. Intentional backoff is excluded. Losses arrive with the next completed Job, so shutdown or a stuck Job can prevent their delivery. Missed is zero in fixed-delay mode. The current run's outcome cannot identify the loss's cause.
All histograms have explicit advisory boundaries, overridable by SDK Views. Nonpositive Period omits saturation; zero ScheduledFor omits lateness. Negative processed and missed counts are clamped to zero.
Interpretation ¶
Metrics describe execution, not queue capacity. Scaling decisions also need queue depth, oldest-item age, arrival rate and dependency capacity. A slow Handler can cause missed points without lateness. An unchanged completion count suggests a stuck Job only with a known maximum interval between completions; backoff and telemetry failure can produce the same signal.
Put service, instance and cluster identity on the application's Resource and configure the export pipeline to retain the distinctions needed in queries. otelbeat does not modify Resource attributes. The otelbeatfx package provides an Fx integration. See the README for examples, boundaries and queries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultOutcome ¶ added in v0.3.0
DefaultOutcome reports the classification beat made in Record.Outcome: "ok", "error", "panic", "timeout" or "canceled". Build on it in a custom OutcomeFunc.
The "panic" outcome only appears when beat's recovery middleware is in use; without it a panicking Job crashes the process and produces no Record. A Record that carries no outcome at all - one assembled by hand rather than by beat - reads as "unknown" rather than as an empty label.
func New ¶
New builds a beat.Handler that records the instruments described in the package doc on meter. The application owns the meter and its exporter.
Example ¶
package main
import (
"context"
"time"
"github.com/uchaloop/beat"
"github.com/uchaloop/otelbeat"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
)
func main() {
// ManualReader permits explicit collection. A production application can
// instead supply its configured reader/exporter to the MeterProvider.
reader := sdkmetric.NewManualReader()
provider := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
handler, err := otelbeat.New(provider.Meter("beat"))
if err != nil {
panic(err)
}
runner, err := beat.MakeBeat(beat.Config{
Period: 5 * time.Minute, JobTimeout: 4 * time.Minute,
Jitter: 5 * time.Minute,
}, func(ctx context.Context) (int, error) { return 0, ctx.Err() }, handler)
if err != nil {
panic(err)
}
if err := runner.Start(context.Background()); err != nil {
panic(err)
}
// The application runs until its shutdown signal.
stopCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := runner.Stop(stopCtx); err != nil {
panic(err)
}
exportCtx, exportCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer exportCancel()
if err := provider.Shutdown(exportCtx); err != nil {
panic(err)
}
}
Output:
Types ¶
type Option ¶
type Option func(*settings)
Option configures the handler built by New.
func WithOutcome ¶ added in v0.3.0
func WithOutcome(f OutcomeFunc) Option
WithOutcome overrides how a run is classified into the "outcome" attribute. The default is DefaultOutcome. A nil func is ignored. Keep the set of returned values small - each distinct value is a separate metric series.
Example ¶
package main
import (
"context"
"errors"
"github.com/uchaloop/beat"
"github.com/uchaloop/otelbeat"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
)
func main() {
errThrottled := errors.New("throttled")
reader := sdkmetric.NewManualReader()
provider := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
defer provider.Shutdown(context.Background())
handler, err := otelbeat.New(provider.Meter("beat"),
otelbeat.WithOutcome(func(r beat.Record) string {
if r.Outcome == beat.OutcomeError && errors.Is(r.Err, errThrottled) {
return "throttled"
}
return otelbeat.DefaultOutcome(r)
}),
)
if err != nil {
panic(err)
}
_ = handler // Supply this handler to beat.MakeBeat.
}
Output:
type OutcomeFunc ¶ added in v0.3.0
OutcomeFunc classifies a run into the value of the "outcome" attribute. Use it to map domain errors to your own codes; DefaultOutcome passes through what beat already decided.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package otelbeatfx wires otelbeat into an Uber Fx application: it provides a beat.Handler that records OpenTelemetry metrics, built from the container's metric.MeterProvider.
|
Package otelbeatfx wires otelbeat into an Uber Fx application: it provides a beat.Handler that records OpenTelemetry metrics, built from the container's metric.MeterProvider. |