grpcprocotel

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

grpcproc/otel

OpenTelemetry for grpcproc: a span for every send, call and handled message, chained across processes and nodes, and metrics keyed by process label. A separate module, so grpcproc itself does not depend on OpenTelemetry.

go get github.com/floatdrop/grpcproc/otel
h, err := grpcprocotel.New() // global meter/tracer providers and propagator; see Options
node, err := grpcproc.NewNode(grpcproc.Config{…, Hooks: grpcproc.JoinHooks(h, myHooks)})
reg, err := h.Observe(node) // gauges read from node snapshots at each collection
defer reg.Unregister()

Traces

Where Span Kind Parent
Send send <message type> producer the context the sender carries
Call call <message type> client the context the sender carries
a process takes a message process <message type> consumer (server for a call) the sender's span
a process takes a Down process grpcproc.Down consumer —
a process that traps exits takes an Exited process grpcproc.Exited consumer —

A handling span lasts until the process calls Receive again, or exits (with an error status if abnormally). Everything the process sends meanwhile is its child, because grpcproc hands a process's sends the metadata of the message it is handling, and these hooks put the span there. No context has to be threaded through handlers for the chain to form.

For a handler's own spans (a database call), take the handling span from the message, in the message's context, which ends when its caller stops waiting:

ctx, cancel := m.Context(p.Context())
defer cancel()
ctx, span := tracer.Start(h.Extract(ctx, m.Metadata), "load order")

Spans carry messaging.system=grpcproc, messaging.operation.type, messaging.destination.name, grpcproc.message.type, grpcproc.label, grpcproc.pid; failed sends and calls carry error.type.

Metrics

No metric carries a PID: the process label (grpcproc.WithLabel, default the message type) is the unit, and every other attribute is bounded.

Name Type Attributes
grpcproc.messages.sent counter grpcproc.label (sender), grpcproc.call, grpcproc.remote
grpcproc.messages.received counter grpcproc.label
grpcproc.mailbox.wait histogram, s grpcproc.label
grpcproc.process.duration histogram, s grpcproc.label — time from taking a message to the next Receive
grpcproc.call.duration histogram, s grpcproc.label, grpcproc.remote, error.type on failure
grpcproc.processes.spawned counter grpcproc.label
grpcproc.processes.exited counter grpcproc.label, grpcproc.reason (normal, shutdown, killed, noproc, noconnection, type; max restarts from actor, timeout and replaced from cron, demoted from leader; panic, error)
grpcproc.dead_letters counter grpcproc.reason, grpcproc.message.type
grpcproc.links.up, grpcproc.links.down counter grpcproc.peer
grpcproc.processes gauge (Observe) grpcproc.label
grpcproc.mailbox.depth gauge (Observe) grpcproc.label, summed
grpcproc.mailbox.oldest gauge (Observe), s grpcproc.label, maximum
grpcproc.link.messages, grpcproc.link.bytes counter (Observe) grpcproc.peer, grpcproc.direction

error.type is one of noproc, type, busy (the link to the peer was full: Config.MaxQueued), noconnection, timeout, canceled, remote (the handler returned an error), other.

Documentation

Overview

Package grpcprocotel records grpcproc activity with OpenTelemetry: a span for every send, call and handled message, chained across processes and nodes through grpcproc.Metadata, and metrics keyed by process label.

h, err := grpcprocotel.New()                 // global providers and propagator
node, err := grpcproc.NewNode(grpcproc.Config{…, Hooks: h})
reg, err := h.Observe(node)                // gauges from snapshots
defer reg.Unregister()

Inside a handler, h.Extract(ctx, m.Metadata) is a context whose span is the one handling m, for the handler's own spans (a database call, an HTTP request).

Index

Constants

View Source
const (
	AttrLabel       = attribute.Key("grpcproc.label")
	AttrCall        = attribute.Key("grpcproc.call")
	AttrRemote      = attribute.Key("grpcproc.remote")
	AttrReason      = attribute.Key("grpcproc.reason")
	AttrMessageType = attribute.Key("grpcproc.message.type")
	AttrPeer        = attribute.Key("grpcproc.peer")
	AttrDirection   = attribute.Key("grpcproc.direction")
	AttrPID         = attribute.Key("grpcproc.pid") // spans only
	AttrErrorType   = attribute.Key("error.type")
)

Attribute keys. Metrics never carry a PID: the label is the unit of aggregation, and everything else is bounded.

View Source
const ScopeName = "github.com/floatdrop/grpcproc/otel"

ScopeName is the instrumentation scope of the meter and tracer.

Variables

This section is empty.

Functions

func ErrorType

func ErrorType(err error) string

ErrorType maps a send or call error to a bounded set, for error.type.

func ReasonClass

func ReasonClass(reason string) string

ReasonClass maps an exit reason to a bounded set, for metrics: the well-known reasons, grpcproc's packages' own included, "panic", or "error" for anything else a process returned. A leader's singleton demoted, or a cron run replaced, is then no error on a dashboard.

Types

type Carrier

type Carrier grpcproc.Metadata

Carrier adapts grpcproc.Metadata to OpenTelemetry propagation, the way propagation.HeaderCarrier adapts HTTP headers.

func (Carrier) Get

func (c Carrier) Get(key string) string

func (Carrier) Keys

func (c Carrier) Keys() []string

func (Carrier) Set

func (c Carrier) Set(key, value string)

type Hooks

type Hooks struct {
	grpcproc.NopHooks
	// contains filtered or unexported fields
}

Hooks implements grpcproc.Hooks with OpenTelemetry. Combine it with other hooks through grpcproc.JoinHooks.

func New

func New(opts ...Option) (*Hooks, error)

New creates the instruments. With no options it uses the global meter and tracer providers and the global propagator, read once, now.

func (*Hooks) Extract

func (h *Hooks) Extract(ctx context.Context, md grpcproc.Metadata) context.Context

Extract returns ctx carrying the trace context in md. With a Msg's Metadata it is the span handling that message.

func (*Hooks) Observe

func (h *Hooks) Observe(node *grpcproc.Node) (metric.Registration, error)

Observe registers gauges read from node's snapshots at each collection: processes, mailbox depth and oldest message age per label, and traffic per link. Unregister the returned registration when the node stops.

func (*Hooks) OnDeadLetter

func (h *Hooks) OnDeadLetter(_, _ grpcproc.PID, body proto.Message, reason string)

func (*Hooks) OnExit

func (h *Hooks) OnExit(p grpcproc.ProcessInfo, reason string)

func (*Hooks) OnLinkDown

func (h *Hooks) OnLinkDown(peer grpcproc.NodeID, _ error)

func (*Hooks) OnLinkUp

func (h *Hooks) OnLinkUp(peer grpcproc.NodeID)

func (*Hooks) OnReceive

OnReceive starts the span that covers handling the message, a consumer span (a server span for a call) whose parent is the sender's span, and makes it what the process's own sends inherit.

func (*Hooks) OnSend

OnSend starts a producer span for a send, a client span for a call, and injects it into what leaves.

func (*Hooks) OnSpawn

func (h *Hooks) OnSpawn(p grpcproc.ProcessInfo)

type Option

type Option func(*config)

Option configures New.

func WithMeterProvider

func WithMeterProvider(mp metric.MeterProvider) Option

WithMeterProvider records metrics with mp instead of the global provider.

func WithPropagator

func WithPropagator(p propagation.TextMapPropagator) Option

WithPropagator carries trace context with p instead of the global propagator.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider records spans with tp instead of the global provider.

Jump to

Keyboard shortcuts

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