statshandler

package module
v0.0.0-...-74c7889 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

StatsHandler is now implemented in https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc

This project is no longer needed.

otel-grpc-statshandler

PkgGoDev

otel-grpc-statshandler implements grpc.StatsHandler for recording OpenTelemetry metrics and traces.

otelgrpc uses an interceptor based approach that can miss some errors and also does not currently support metrics.

It records metrics and traces as decribed in:

PRs and patches are welcomed.

Example

package main

import (
    "google.golang.org/grpc"
    statshandler "github.com/bakins/otel-grpc-statshandler"
)

func main() {
    handler, err := statshandler.NewServerHandler()
    if err != nil {
       // handle error
    }

    server := grpc.NewServer(grpc.StatsHandler(handler))
}

LICENSE

See LICENSE

TODO

  • more test cases

Documentation

Overview

Package statshandler implements a grpc.StatsHandler that records OpenTelemetry traces and metrics

Index

Examples

Constants

View Source
const (
	// DefaultInstrumentationName is the default used when creating meters and tracers.
	DefaultInstrumentationName = "otel-grpc-statshandler"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientHandler

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

ServerHandler implements https://pkg.go.dev/google.golang.org/grpc/stats#ServerHandler It records OpenTelemetry metrics and traces.

Example
package main

import (
	"google.golang.org/grpc"

	pb "google.golang.org/grpc/examples/helloworld/helloworld"

	statshandler "github.com/bakins/otel-grpc-statshandler"
)

func main() {
	handler, err := statshandler.NewClientHandler()
	if err != nil {
		// handle error
	}

	conn, err := grpc.Dial("myaddress:port", grpc.WithStatsHandler(handler))
	if err != nil {
		// handle error
	}

	client := pb.NewGreeterClient(conn)

	_ = client // use client
}
Output:

func NewClientHandler

func NewClientHandler(options ...Option) (*ClientHandler, error)

func (*ClientHandler) HandleConn

func (c *ClientHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn exists to satisfy gRPC stats.Handler.

func (*ClientHandler) HandleRPC

func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

HandleRPC implements per-RPC tracing and stats instrumentation.

func (*ClientHandler) TagConn

TagConn exists to satisfy gRPC stats.Handler.

func (*ClientHandler) TagRPC

TagRPC implements per-RPC context management.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option applies an option value when creating a Handler

func WithInstrumentationName

func WithInstrumentationName(name string) Option

WithInstrumentationName returns an Option to use the TracerProvider when creating a Tracer.

func WithMeterProvider

func WithMeterProvider(p metric.MeterProvider) Option

WithMeterProvider returns an Option to use the MetricProvider when creating metrics.

func WithPropagators

func WithPropagators(p propagation.TextMapPropagator) Option

WithPropagator returns an Option to use the Propagator when extracting and injecting trace context from requests.

func WithTracerProvider

func WithTracerProvider(p trace.TracerProvider) Option

WithTracerProvider returns an Option to use the TracerProvider when creating a Tracer.

type ServerHandler

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

ServerHandler implements https://pkg.go.dev/google.golang.org/grpc/stats#ServerHandler It records OpenTelemetry metrics and traces.

Example
package main

import (
	"google.golang.org/grpc"

	statshandler "github.com/bakins/otel-grpc-statshandler"
)

func main() {
	handler, err := statshandler.NewServerHandler()
	if err != nil {
		// handle error
	}

	server := grpc.NewServer(grpc.StatsHandler(handler))

	_ = server // use server
}
Output:

func NewServerHandler

func NewServerHandler(options ...Option) (*ServerHandler, error)

func (*ServerHandler) HandleConn

func (s *ServerHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn exists to satisfy gRPC stats.Handler.

func (*ServerHandler) HandleRPC

func (s *ServerHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

HandleRPC implements per-RPC tracing and stats instrumentation.

func (*ServerHandler) TagConn

TagConn exists to satisfy gRPC stats.Handler.

func (*ServerHandler) TagRPC

TagRPC implements per-RPC context management.

Jump to

Keyboard shortcuts

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