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
- 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) 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) 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") 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, "panic", or "error" for anything a process returned.
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 traffic per link. Unregister the returned registration when the node stops.
func (*Hooks) OnDeadLetter ¶
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.