Skip to content

Commit

Permalink
Merge branch 'main' into infologging_ff_controls
Browse files Browse the repository at this point in the history
  • Loading branch information
antonaudzei-outreach committed Aug 5, 2024
2 parents 66860c6 + b08997e commit d2fc214
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 48 deletions.
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ toolchain go1.21.5
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Masterminds/semver/v3 v3.2.1
github.com/briandowns/spinner v1.23.0
github.com/briandowns/spinner v1.23.1
github.com/charmbracelet/glamour v0.7.0
github.com/charmbracelet/lipgloss v0.11.0
github.com/charmbracelet/lipgloss v0.12.1
github.com/charmbracelet/log v0.4.0
github.com/creack/pty v1.1.21
github.com/davecgh/go-spew v1.1.1
Expand All @@ -28,19 +28,19 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/schollz/progressbar/v3 v3.14.4
github.com/schollz/progressbar/v3 v3.14.5
github.com/sirupsen/logrus v1.9.3
github.com/tdewolff/minify/v2 v2.20.32
github.com/tdewolff/minify/v2 v2.20.37
github.com/ulikunitz/xz v0.5.12
github.com/urfave/cli/v2 v2.27.2
github.com/versent/saml2aws/v2 v2.36.16
github.com/urfave/cli/v2 v2.27.3
github.com/versent/saml2aws/v2 v2.36.17
github.com/zalando/go-keyring v0.2.5
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
go.opentelemetry.io/otel/metric v1.28.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
golang.org/x/crypto v0.25.0
golang.org/x/oauth2 v0.21.0
Expand All @@ -55,17 +55,17 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/alecthomas/chroma/v2 v2.8.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.1.1 // indirect
github.com/charmbracelet/x/ansi v0.1.4 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/tdewolff/parse/v2 v2.7.14 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
github.com/tdewolff/parse/v2 v2.7.15 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
)
Expand All @@ -80,7 +80,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/danieljoos/wincred v1.2.2 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down Expand Up @@ -123,7 +123,7 @@ require (
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0
Expand Down
54 changes: 26 additions & 28 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions pkg/trace/propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ func (t *otelTracer) newTransport(old http.RoundTripper) http.RoundTripper {
}

type Handler struct {
handler http.Handler
operation string
handler http.Handler
operation string
publicEndpointFn func(*http.Request) bool
}

type HandlerOption func(*Handler)

func WithPublicEndpointFn(fn func(*http.Request) bool) HandlerOption {
return func(h *Handler) {
h.publicEndpointFn = fn
}
}

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand All @@ -52,18 +61,24 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
force := r.Header.Get(HeaderForceTracing)
if force != "" {
startOptions = oteltrace.WithAttributes(attribute.String(fieldForceTrace, force))
handler = otelhttp.NewHandler(h.handler, h.operation, otelhttp.WithSpanOptions(startOptions))
handler = otelhttp.NewHandler(h.handler, h.operation,
otelhttp.WithSpanOptions(startOptions),
otelhttp.WithPublicEndpointFn(h.publicEndpointFn), // passing nil function is equivalent to "not configured"
)
r = r.WithContext(forceTracing(r.Context()))
}

handler.ServeHTTP(w, r)
}

func (t *otelTracer) newHandler(handler http.Handler, operation string) http.Handler {
func (t *otelTracer) newHandler(handler http.Handler, operation string, opts ...HandlerOption) http.Handler {
h := Handler{
handler: handler,
operation: operation,
}
for _, opt := range opts {
opt(&h)
}

return &h
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/trace/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ func NewTransport(old http.RoundTripper) http.RoundTripper {
// NewHandler creates a new handlers which reads propagated headers
// from the current trace context.
//
// Supported options are:
// - WithPublicEndpointFn conditionally configure the Handler to link the span with an incoming span context
// instead of child association. Useful for public facing endpoints that don't need to attach to externally
// defined traces
//
// Usage:
//
// trace.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) *roundtripperState {
// trace.StartSpan(r.Context(), "my endpoint")
// defer trace.End(r.Context())
// ... do actual request handling ...
// }), "my endpoint")
func NewHandler(handler http.Handler, operation string) http.Handler {
func NewHandler(handler http.Handler, operation string, opts ...HandlerOption) http.Handler {
if defaultTracer == nil {
return handler
}

return defaultTracer.newHandler(handler, operation)
return defaultTracer.newHandler(handler, operation, opts...)
}
2 changes: 1 addition & 1 deletion pkg/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type tracer interface {

newTransport(http.RoundTripper) http.RoundTripper

newHandler(handler http.Handler, operation string) http.Handler
newHandler(handler http.Handler, operation string, opts ...HandlerOption) http.Handler

toHeaders(ctx context.Context) map[string][]string

Expand Down

0 comments on commit d2fc214

Please sign in to comment.