Coder Social home page Coder Social logo

buffet's Introduction

buffet

Build Status

Buffet is an OpenTracing middleware for buffalo

Usage

In your main:

	tracer, closer := initTracer()
	defer closer.Close()
	opentracing.SetGlobalTracer(tracer)

	fmt.Println(tracer)
	app := actions.App(tracer)

initTracer looks like this:

func initTracer() (opentracing.Tracer, io.Closer) {
	sampler := jaeger.NewConstSampler(true)
	transport, err := udp.NewUDPTransport("", 0)
	if err != nil {
		log.Fatal(err)
	}
	reporter := jaeger.NewRemoteReporter(transport)

	tracer, closer := jaeger.NewTracer(ServiceName, sampler, reporter)
	return tracer, closer

}

Change your App() function to accept your tracer for initialization, and add the middleware:

func App(tracer opentracing.Tracer) *buffalo.App {
	if app == nil {
    ...
		app.Use(buffet.OpenTracing(tracer))
    ...

Then instrument your handlers:

// HomeHandler is a default handler to serve up
// a home page.
func HomeHandler(c buffalo.Context) error {
	slow(c)
	return c.Render(200, r.HTML("index.html"))
}

//BadHandler returns an error
func BadHandler(c buffalo.Context) error {
	return c.Error(401, errors.New("Unauthorized!"))
}
func slow(c buffalo.Context) {
	sp := buffet.ChildSpan("slow", c)
	defer sp.Finish()
	time.Sleep(1 * time.Millisecond)
}

HomeHandler and BadHandler are automatically instrumented because of the middleware. The slow() function isn't, so we pass in the buffalo context and derive a child span from the one in the buffalo context. This creates a child span that belongs to the parent (which was created automatically in the middleware).

buffet's People

Contributors

bketelsen avatar manugupt1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

buffet's Issues

Show examples using mock tracer

The mock tracer is a really easy way to setup and test without needing a real tracer like jaeger running, etc. I think it would help a lot of people getting started with this project if they saw both examples or tests (or using examples in the tests) on how to use the mock tracer so they can see it happen as they develop, etc.

Also, very nice introduction for the middleware. Great addition to the buffalo ecosystem!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.