Home

Awesome

fiber_tracing is middleware for fiber framework

fiber_tracing Middleware trace requests on Fiber framework with OpenTracing API. You can use every tracer that implement OpenTracing interface

Install

go get -u github.com/gofiber/fiber
go get -u github.com/shareed2k/fiber_tracing

Config

PropertyTypeDescriptionDefault
Traceropentracing.Tracerinitializes an opentracing tracer., possible values: jaeger, lightstep, instana, basictracer-go, ..."&opentracing.NoopTracer{}"
OperationNamefunc(*fiber.Ctx) stringSpan operation name"HTTP " + ctx.Method() + " URL: " + ctx.Path()
ComponentNamestringUsed for describing the tracing component namefiber/v2
ParentSpanKeystringcontext key string used to get span scoped to the request#defaultTracingParentSpanKey
Filterfunc(*fiber.Ctx) boolDefines a function to skip middleware.nil
Modifyfunc(*fiber.Ctx, opentracing.Span)Defines a function to edit span like add tags or logs...span.SetTag("http.remote_addr", ctx.IP()) ...

Example

package main

import (
	"github.com/gofiber/fiber"
	"github.com/shareed2k/fiber_tracing"
	"github.com/uber/jaeger-client-go/config"
)

func main() {
	app := fiber.New()

	defcfg := config.Configuration{
		ServiceName: "fiber-tracer",
		Sampler: &config.SamplerConfig{
			Type:  "const",
			Param: 1,
		},
		Reporter: &config.ReporterConfig{
			LogSpans:            true,
			BufferFlushInterval: 1 * time.Second,
		},
	}
	cfg, err := defcfg.FromEnv()
	if err != nil {
		panic("Could not parse Jaeger env vars: " + err.Error())
	}
	tracer, closer, err := cfg.NewTracer()
	if err != nil {
		panic("Could not initialize jaeger tracer: " + err.Error())
	}

	defer closer.Close()

	app.Use(fiber_tracing.NewWithConfig(fiber_tracing.Config{
		Tracer: tracer,
	}))

	// or
	/*
	app.Use(fiber_tracing.New(tracer))
	*/

	app.Get("/", func(c *fiber.Ctx) {
		c.Send("Welcome!")
	})

	app.Listen(3000)
}

Example 2 with jaeger default tracer

package main

import (
	"github.com/gofiber/fiber"
	"github.com/shareed2k/fiber_tracing"
	"github.com/uber/jaeger-client-go/config"
)

func main() {
	app := fiber.New()

	closer := fiber_tracing.NewWithJaegerTracer(app)
	defer closer.Close()

	app.Get("/", func(c *fiber.Ctx) {
		c.Send("Welcome!")
	})

	app.Listen(3000)
}