opencensus

package
v2.3.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: OSL-3.0 Imports: 14 Imported by: 0

README

Opencensus

General usage

First, if you're not sure what opencensus is, please visit https://opencensus.io/ to learn more about it.

Opencensus allows you to collect data for your application and process them via e.g. Prometheus, Jaeger, etc. The core package already collects metrics automatically for routers, prefixrouters and pugtemplate rendering times out of the box. Also traces for request handling are done by default.

Adding your own metrics

The most likely usecase is in a controller, but to have your own metric, please import the following packages:

  • "flamingo.me/flamingo/framework/opencensus"
  • "go.opencensus.io/stats"
  • "go.opencensus.io/stats/view"

Then, create a variable for your metric. See below example:

var stat = stats.Int64("flamingo/package/mystat", "my stat records 5 milliseconds per call", stats.UnitMilliseconds)

The Variable name of rt is totally arbitrary here. But "flamingo/package/mystat" is actually the metric id you're recording to. Normally, this should be a pattern of "yourproject/subpackage/yourstat". Followed up by a description of your metric and the Unit which is recorded (use stats.UnitDimensionless for simple counters).

To be actuall able to transmit this metic, register it in an init method:

	// register view in opencensus
	func init() {
		opencensus.View("flamingo/package/mystat/sum", stat, view.Sum())
		opencensus.View("flamingo/package/mystat/count", stat, view.Count())
	}

Thats all that is needed as Setup. You can add to your metric in your code now. It's as simple as adding an increment:

    // measure mystat
	func (c *Controller) Get(ctx context.Context, r *web.Request) web.Response {
		// ...

		// record 5ms per call
		stats.Record(ctx, stat.M(5))

		// ...
	}

For a simple counter where rt is a stats.UnitDimensionless metric, you´d simply increment by one, i.e.

		// record increment of 1 per call
		stats.Record(ctx, stat.M(1))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KeyArea, _ = tag.NewKey("area")
	Sampler    = trace.NeverSample()
)

Functions

func View

func View(name string, m stats.Measure, aggr *view.Aggregation, tagKeys ...tag.Key)

Types

type Module

type Module struct {
	Endpoint     string `inject:"config:opencensus.jaeger.endpoint"`
	ServiceName  string `inject:"config:opencensus.serviceName"`
	ServiceAddr  string `inject:"config:opencensus.serviceAddr"`
	JaegerEnable bool   `inject:"config:opencensus.jaeger.enable"`
}

func (*Module) Configure

func (m *Module) Configure(injector *dingo.Injector)

func (*Module) DefaultConfig

func (m *Module) DefaultConfig() config.Map

Jump to

Keyboard shortcuts

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