opencensus

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

README

OpenCensus wrappers

OpenCensus wrappers propagate traces (spans) accross services.

Usage

service := micro.NewService(
    micro.Name("go.micro.srv.greeter"),
    micro.WrapClient(opencensus.NewClientWrapper()),
    micro.WrapHandler(opencensus.NewHandlerWrapper()),
    micro.WrapSubscriber(opencensus.NewSubscriberWrapper()),
)
Views

The OpenCensus package exposes some convenience views. Don't forget to register these views:

// Register to all RPC server views.
if err := view.Register(opencensus.DefaultServerViews...); err != nil {
    log.Fatal(err)
}

// Register to all RPC client views.
if err := view.Register(opencensus.DefaultClientViews...); err != nil {
    log.Fatal(err)
}

Documentation

Overview

Package opencensus provides wrappers for OpenCensus tracing.

Index

Constants

View Source
const (
	// TracePropagationField is the key for the tracing context
	// that will be injected in go-micro's metadata.
	TracePropagationField = "X-Trace-Context"
)

Variables

View Source
var (
	ClientRequestCount = stats.Int64("opencensus.io/rpc/client/request_count", "Number of RPC requests started", stats.UnitNone)
	ClientLatency      = stats.Float64("opencensus.io/rpc/client/latency", "End-to-end latency", stats.UnitMilliseconds)
)

The following client RPC measures are supported for use in custom views.

View Source
var (
	ServerRequestCount = stats.Int64("opencensus.io/rpc/server/request_count", "Number of RPC requests received", stats.UnitNone)
	ServerLatency      = stats.Float64("opencensus.io/rpc/server/latency", "End-to-end latency", stats.UnitMilliseconds)
)

The following server RPC measures are supported for use in custom views.

View Source
var (
	// StatusCode is the RPC status code.
	StatusCode, _ = tag.NewKey("rpc.status")

	// Service is the name of the micro-service.
	Service, _ = tag.NewKey("rpc.service")

	// Method is the service method called.
	Endpoint, _ = tag.NewKey("rpc.endpoint")
)

The following tags are applied to stats recorded by this package. Service and Method are applied to all measures. StatusCode is not applied to ClientRequestCount or ServerRequestCount, since it is recorded before the status is known.

View Source
var (
	ClientRequestCountView = &view.View{
		Name:        "opencensus.io/rpc/client/request_count",
		Description: "Count of RPC requests started",
		Measure:     ClientRequestCount,
		Aggregation: view.Count(),
	}

	ClientLatencyView = &view.View{
		Name:        "opencensus.io/rpc/client/latency",
		Description: "Latency distribution of RPC requests",
		Measure:     ClientLatency,
		Aggregation: DefaultLatencyDistribution,
	}

	ClientRequestCountByMethod = &view.View{
		Name:        "opencensus.io/rpc/client/request_count_by_method",
		Description: "Client request count by RPC method",
		TagKeys:     []tag.Key{Endpoint},
		Measure:     ClientRequestCount,
		Aggregation: view.Count(),
	}

	ClientResponseCountByStatusCode = &view.View{
		Name:        "opencensus.io/rpc/client/response_count_by_status_code",
		Description: "Client response count by RPC status code",
		TagKeys:     []tag.Key{StatusCode},
		Measure:     ClientLatency,
		Aggregation: view.Count(),
	}

	ServerRequestCountView = &view.View{
		Name:        "opencensus.io/rpc/server/request_count",
		Description: "Count of RPC requests received",
		Measure:     ServerRequestCount,
		Aggregation: view.Count(),
	}

	ServerLatencyView = &view.View{
		Name:        "opencensus.io/rpc/server/latency",
		Description: "Latency distribution of RPC requests",
		Measure:     ServerLatency,
		Aggregation: DefaultLatencyDistribution,
	}

	ServerRequestCountByMethod = &view.View{
		Name:        "opencensus.io/rpc/server/request_count_by_method",
		Description: "Server request count by RPC method",
		TagKeys:     []tag.Key{Endpoint},
		Measure:     ServerRequestCount,
		Aggregation: view.Count(),
	}

	ServerResponseCountByStatusCode = &view.View{
		Name:        "opencensus.io/rpc/server/response_count_by_status_code",
		Description: "Server response count by RPC status code",
		TagKeys:     []tag.Key{StatusCode},
		Measure:     ServerLatency,
		Aggregation: view.Count(),
	}
)

This package provides some convenience views. You need to subscribe to the views for data to actually be collected.

View Source
var (
	// ClientProfile is used for RPC clients.
	ClientProfile = &StatsProfile{
		Role:           "client",
		CountMeasure:   ClientRequestCount,
		LatencyMeasure: ClientLatency,
	}

	// ServerProfile is used for RPC servers.
	ServerProfile = &StatsProfile{
		Role:           "server",
		CountMeasure:   ServerRequestCount,
		LatencyMeasure: ServerLatency,
	}
)

DefaultClientViews are the default client views provided by this package.

View Source
var (
	DefaultLatencyDistribution = view.Distribution(0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
)

Default distributions used by views in this package.

DefaultServerViews are the default server views provided by this package.

Functions

func NewClientWrapper

func NewClientWrapper() client.Wrapper

NewClientWrapper returns a client.Wrapper that adds monitoring to outgoing requests.

func NewHandlerWrapper

func NewHandlerWrapper() server.HandlerWrapper

NewHandlerWrapper returns a server.HandlerWrapper that adds tracing to incoming requests.

func NewSubscriberWrapper

func NewSubscriberWrapper() server.SubscriberWrapper

NewSubscriberWrapper returns a server.SubscriberWrapper that adds tracing to subscription requests.

Types

type StatsProfile

type StatsProfile struct {
	Role           string
	CountMeasure   *stats.Int64Measure
	LatencyMeasure *stats.Float64Measure
}

StatsProfile groups metrics-related data.

Jump to

Keyboard shortcuts

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