forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracing.go
55 lines (45 loc) · 1.87 KB
/
tracing.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
// Copyright 2021 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
// Package tracing enables dependency-injection at runtime. When used
// together with an underscore-import of `github.com/open-policy-agent/opa/features/tracing`,
// the server and its runtime will emit OpenTelemetry spans to the
// configured sink.
package tracing
import "net/http"
// Options are options for the HTTPTracingService, passed along as-is.
type Options []interface{}
// NewOptions is a helper method for constructing `tracing.Options`
func NewOptions(opts ...interface{}) Options {
return opts
}
// HTTPTracingService defines how distributed tracing comes in, server- and client-side
type HTTPTracingService interface {
// NewTransport is used when setting up an HTTP client
NewTransport(http.RoundTripper, Options) http.RoundTripper
// NewHandler is used to wrap an http.Handler in the server
NewHandler(http.Handler, string, Options) http.Handler
}
var tracing HTTPTracingService
// RegisterHTTPTracing enables a HTTPTracingService for further use.
func RegisterHTTPTracing(ht HTTPTracingService) {
tracing = ht
}
// NewTransport returns another http.RoundTripper, instrumented to emit tracing
// spans according to Options. Provided by the HTTPTracingService registered with
// this package via RegisterHTTPTracing.
func NewTransport(tr http.RoundTripper, opts Options) http.RoundTripper {
if tracing == nil {
return tr
}
return tracing.NewTransport(tr, opts)
}
// NewHandler returns another http.Handler, instrumented to emit tracing spans
// according to Options. Provided by the HTTPTracingService registered with
// this package via RegisterHTTPTracing.
func NewHandler(f http.Handler, label string, opts Options) http.Handler {
if tracing == nil {
return f
}
return tracing.NewHandler(f, label, opts)
}