forked from the-gigi/delinkcious
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing_middleware.go
38 lines (31 loc) · 1012 Bytes
/
tracing_middleware.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
package service
import (
"github.com/opentracing/opentracing-go"
om "github.com/wrlou/delinkcious/pkg/object_model"
)
// implement function to return ServiceMiddleware
func newTracingMiddleware(tracer opentracing.Tracer) linkManagerMiddleware {
return func(next om.LinkManager) om.LinkManager {
return tracingMiddleware{next, tracer}
}
}
type tracingMiddleware struct {
next om.LinkManager
tracer opentracing.Tracer
}
func (m tracingMiddleware) GetLinks(request om.GetLinksRequest) (result om.GetLinksResult, err error) {
defer func(span opentracing.Span) {
span.Finish()
}(m.tracer.StartSpan("GetLinks"))
result, err = m.next.GetLinks(request)
return
}
func (m tracingMiddleware) AddLink(request om.AddLinkRequest) error {
return m.next.AddLink(request)
}
func (m tracingMiddleware) UpdateLink(request om.UpdateLinkRequest) error {
return m.next.UpdateLink(request)
}
func (m tracingMiddleware) DeleteLink(username string, url string) error {
return m.next.DeleteLink(username, url)
}