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()
lreg, err := h.ObserveLeader(node) // grpcproc/leader elections, if any
defer lreg.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
- func ErrorType(err error) string
- func ReasonClass(reason string) string
- type Carrier
- type Hooks
- func (h *Hooks) Extract(ctx context.Context, md grpcproc.Metadata) context.Context
- func (h *Hooks) Observe(node *grpcproc.Node) (metric.Registration, error)
- func (h *Hooks) ObserveLeader(node *grpcproc.Node) (metric.Registration, error)
- func (h *Hooks) OnDeadLetter(_, _ grpcproc.PID, body proto.Message, reason string)
- func (h *Hooks) OnExit(p grpcproc.ProcessInfo, reason string)
- func (h *Hooks) OnLinkDown(peer grpcproc.NodeID, _ error)
- func (h *Hooks) OnLinkUp(peer grpcproc.NodeID)
- func (h *Hooks) OnMemberDown(m grpcproc.Member)
- func (h *Hooks) OnMemberUp(m grpcproc.Member)
- func (h *Hooks) OnReceive(r grpcproc.ReceiveInfo, md grpcproc.Metadata) (grpcproc.Metadata, grpcproc.Done)
- func (h *Hooks) OnSend(s grpcproc.SendInfo, md grpcproc.Metadata) (grpcproc.Metadata, grpcproc.Done)
- func (h *Hooks) OnSpawn(p grpcproc.ProcessInfo)
- type Option
Constants ¶
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") AttrCluster = attribute.Key("grpcproc.leader.cluster") // ObserveLeader AttrRole = attribute.Key("grpcproc.leader.role") // ObserveLeader's grpcproc.leader.electors 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.
const ScopeName = "github.com/floatdrop/grpcproc/otel"
ScopeName is the instrumentation scope of the meter and tracer.
Variables ¶
This section is empty.
Functions ¶
func ReasonClass ¶
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 ¶
Carrier adapts grpcproc.Metadata to OpenTelemetry propagation, the way propagation.HeaderCarrier adapts HTTP headers.
type Hooks ¶
Hooks implements grpcproc.Hooks with OpenTelemetry. Combine it with other hooks through grpcproc.JoinHooks.
func New ¶
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 ¶
Extract returns ctx carrying the trace context in md. With a Msg's Metadata it is the span handling that message.
func (*Hooks) Observe ¶
Observe registers gauges read from node's snapshots at each collection: processes, mailbox depth and oldest message age per label, and counters of traffic per peer and direction. Those add up what each link to the peer had carried at the collections that saw it, so they never go back when a link breaks; what a link carries after the last collection before it breaks is not counted. A peer this node has neither a link to nor backs off from is forgotten, and counts from 0 if it comes back. Unregister the returned registration when the node stops.
func (*Hooks) ObserveLeader ¶ added in v0.14.0
ObserveLeader registers gauges read at each collection from the electors of grpcproc/leader on node, by grpcproc.leader.cluster: one set for each election the node takes part in when the collection runs. They come from what each elector publishes through its inspect map: its role (1, with grpcproc.leader.role), its term, the nodes of its view, the quorum, how many of the view it hears from, itself included, whether the singleton runs on this node, and how many Checkpoint calls wait for a majority. The electors are asked at once. One that the node's snapshot shows on one message for a second, busy in a slow Store say, or that does not answer within a second of a collection that lasts that long, is reported as stalled, with no other gauge. Unregister the returned registration when the node stops.
func (*Hooks) OnDeadLetter ¶
func (*Hooks) OnMemberDown ¶ added in v0.14.0
func (*Hooks) OnMemberUp ¶ added in v0.14.0
func (*Hooks) OnReceive ¶
func (h *Hooks) OnReceive(r grpcproc.ReceiveInfo, md grpcproc.Metadata) (grpcproc.Metadata, grpcproc.Done)
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 ¶
func (h *Hooks) OnSend(s grpcproc.SendInfo, md grpcproc.Metadata) (grpcproc.Metadata, grpcproc.Done)
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.