forked from micro/micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opentracing.go
39 lines (32 loc) · 1.08 KB
/
opentracing.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
package opentelemetry
import (
"strings"
mmd "github.com/tickoalcantara12/micro/v3/service/context/metadata"
"github.com/opentracing/opentracing-go"
)
var (
// DefaultOpenTracer is what anything using an opentracing.Tracer will access:
DefaultOpenTracer opentracing.Tracer = new(opentracing.NoopTracer)
)
// MicroMetadataReaderWriter satisfies both the opentracing.TextMapReader and
// opentracing.TextMapWriter interfaces.
type MicroMetadataReaderWriter struct {
mmd.Metadata
}
func (w MicroMetadataReaderWriter) Set(key, val string) {
// The GRPC HPACK implementation rejects any uppercase keys here.
//
// As such, since the HTTP_HEADERS format is case-insensitive anyway, we
// blindly lowercase the key (which is guaranteed to work in the
// Inject/Extract sense per the OpenTracing spec).
key = strings.ToLower(key)
w.Metadata.Set(key, val)
}
func (w MicroMetadataReaderWriter) ForeachKey(handler func(key, val string) error) error {
for k, v := range w.Metadata {
if err := handler(k, v); err != nil {
return err
}
}
return nil
}