/
tag.go
59 lines (47 loc) · 1.14 KB
/
tag.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
54
55
56
57
58
59
package tracing
import (
opentracing "github.com/opentracing/opentracing-go"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
)
type tagSpec struct {
}
type tagFilter struct {
tagName string
tagValue *eskip.Template
}
// NewTag creates a filter specification for the tracingTag filter.
func NewTag() filters.Spec {
return tagSpec{}
}
func (s tagSpec) Name() string {
return filters.TracingTagName
}
func (s tagSpec) CreateFilter(args []interface{}) (filters.Filter, error) {
if len(args) != 2 {
return nil, filters.ErrInvalidFilterParameters
}
tagName, ok := args[0].(string)
if !ok {
return nil, filters.ErrInvalidFilterParameters
}
tagValue, ok := args[1].(string)
if !ok {
return nil, filters.ErrInvalidFilterParameters
}
return tagFilter{
tagName: tagName,
tagValue: eskip.NewTemplate(tagValue),
}, nil
}
func (f tagFilter) Request(ctx filters.FilterContext) {
req := ctx.Request()
span := opentracing.SpanFromContext(req.Context())
if span == nil {
return
}
if v, ok := f.tagValue.ApplyContext(ctx); ok {
span.SetTag(f.tagName, v)
}
}
func (f tagFilter) Response(filters.FilterContext) {}