-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
53 lines (45 loc) · 1.3 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package fibertracing
import (
"github.com/gofiber/fiber/v2"
"github.com/opentracing/opentracing-go"
)
// Config defines the config of middlewares
type Config struct {
Tracer opentracing.Tracer
OperationName func(*fiber.Ctx) string
Filter func(*fiber.Ctx) bool
Modify func(*fiber.Ctx, opentracing.Span)
SkipSpanWithoutParent bool
}
// ConfigDefault is the default config
var ConfigDefault = Config{
Tracer: opentracing.NoopTracer{},
Modify: func(ctx *fiber.Ctx, span opentracing.Span) {
span.SetTag("http.method", ctx.Method()) // GET, POST
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 function to return default values
func configDefault(config ...Config) Config {
// Return default config if no config provided
if len(config) < 1 {
return ConfigDefault
}
cfg := config[0]
if cfg.Tracer == nil {
cfg.Tracer = ConfigDefault.Tracer
}
if cfg.OperationName == nil {
cfg.OperationName = ConfigDefault.OperationName
}
if cfg.Modify == nil {
cfg.Modify = ConfigDefault.Modify
}
return cfg
}