fibertracing

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 4 Imported by: 0

README

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"})
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Tracer: opentracing.NoopTracer{},
	Modify: func(ctx *fiber.Ctx, span opentracing.Span) {
		span.SetTag("http.method", ctx.Method())
		span.SetTag("http.remote_address", ctx.IP())
		span.SetTag("http.path", ctx.Path())
		span.SetTag("http.host", ctx.Hostname())
		span.SetTag("http.url", ctx.OriginalURL())
	},
	OperationName: func(ctx *fiber.Ctx) string {
		return "HTTP " + ctx.Method() + " URL: " + ctx.Path()
	},
}

ConfigDefault is the default config

Functions

func New

func New(config Config) fiber.Handler

Types

type Config

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

Config defines the config of middlewares

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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