Skip to content

🔍opentracing middleware for ⚡️fiber framework, support jaeger-go-client.

License

Notifications You must be signed in to change notification settings

aschenmaker/fiber-opentracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fiber-opentracing 🔍 Middleware

fiber-opentraing middleware support opentracing for Fiber⚡️ framework.

How to use

go get -u github.com/gofiber/v2
go get -u github.com/aschenmaker/fiber-opentracing

default use

import (
	"github.com/gofiber/fiber/v2"
	fibertracing "github.com/aschenmaker/fiber-opentracing"
)

app.Use(fibertracing.New())

Config

Middleware has 5 configs.

type Config struct {
	Tracer                opentracing.Tracer
	OperationName         func(*fiber.Ctx) string
	Filter                func(*fiber.Ctx) bool
	Modify                func(*fiber.Ctx, opentracing.Span)
	SkipSpanWithoutParent bool
}

Example

You can run example/example.go

package main

import (
	"os"
	"os/signal"

	fibertracing "github.com/aschenmaker/fiber-opentracing"
	"github.com/aschenmaker/fiber-opentracing/fjaeger"
	"github.com/gofiber/fiber/v2"
	"github.com/opentracing/opentracing-go"
)

func main() {
	app := *fiber.New()
	// Use jaeger default config.
	// You can use Jaeger-all-in-one
	// and then check trace in JaegerUI
	fjaeger.New(fjaeger.Config{})

	app.Use(fibertracing.New(fibertracing.Config{
		Tracer: opentracing.GlobalTracer(),
		OperationName: func(ctx *fiber.Ctx) string {
			return "TEST:  HTTP " + ctx.Method() + " URL: " + ctx.Path()
		},
	}))

	go func() {
		interruptor := make(chan os.Signal, 1)
		signal.Notify(interruptor, os.Interrupt)
		for range interruptor {
			app.Shutdown()
			os.Exit(1)
		}
	}()

	api := app.Group("/api")
	api.Get("/", indexHandle)
	app.Listen(":8080")
}

func indexHandle(c *fiber.Ctx) error {
	return c.Status(200).JSON(fiber.Map{"msg": "test"})
}

About

🔍opentracing middleware for ⚡️fiber framework, support jaeger-go-client.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages