项目作者: Shareed2k

项目描述 :
fiber_tracing is middleware for fiber framework
高级语言: Go
项目地址: git://github.com/Shareed2k/fiber_tracing.git
创建时间: 2020-04-30T14:49:10Z
项目社区:https://github.com/Shareed2k/fiber_tracing

开源协议:

下载


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

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

Config

Property Type Description Default
Tracer opentracing.Tracer initializes an opentracing tracer., possible values: jaeger, lightstep, instana, basictracer-go, … "&opentracing.NoopTracer{}"
OperationName func(*fiber.Ctx) string Span operation name "HTTP " + ctx.Method() + " URL: " + ctx.Path()
ComponentName string Used for describing the tracing component name fiber/v2
ParentSpanKey string context key string used to get span scoped to the request #defaultTracingParentSpanKey
Filter func(*fiber.Ctx) bool Defines a function to skip middleware. nil
Modify func(*fiber.Ctx, opentracing.Span) Defines a function to edit span like add tags or logs… span.SetTag("http.remote_addr", ctx.IP()) ...

Example

  1. package main
  2. import (
  3. "github.com/gofiber/fiber"
  4. "github.com/shareed2k/fiber_tracing"
  5. "github.com/uber/jaeger-client-go/config"
  6. )
  7. func main() {
  8. app := fiber.New()
  9. defcfg := config.Configuration{
  10. ServiceName: "fiber-tracer",
  11. Sampler: &config.SamplerConfig{
  12. Type: "const",
  13. Param: 1,
  14. },
  15. Reporter: &config.ReporterConfig{
  16. LogSpans: true,
  17. BufferFlushInterval: 1 * time.Second,
  18. },
  19. }
  20. cfg, err := defcfg.FromEnv()
  21. if err != nil {
  22. panic("Could not parse Jaeger env vars: " + err.Error())
  23. }
  24. tracer, closer, err := cfg.NewTracer()
  25. if err != nil {
  26. panic("Could not initialize jaeger tracer: " + err.Error())
  27. }
  28. defer closer.Close()
  29. app.Use(fiber_tracing.NewWithConfig(fiber_tracing.Config{
  30. Tracer: tracer,
  31. }))
  32. // or
  33. /*
  34. app.Use(fiber_tracing.New(tracer))
  35. */
  36. app.Get("/", func(c *fiber.Ctx) {
  37. c.Send("Welcome!")
  38. })
  39. app.Listen(3000)
  40. }

Example 2 with jaeger default tracer

  1. package main
  2. import (
  3. "github.com/gofiber/fiber"
  4. "github.com/shareed2k/fiber_tracing"
  5. "github.com/uber/jaeger-client-go/config"
  6. )
  7. func main() {
  8. app := fiber.New()
  9. closer := fiber_tracing.NewWithJaegerTracer(app)
  10. defer closer.Close()
  11. app.Get("/", func(c *fiber.Ctx) {
  12. c.Send("Welcome!")
  13. })
  14. app.Listen(3000)
  15. }