outpost: fix spans being sent without parent context

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-03 18:17:08 +02:00
parent e751ce1220
commit 70d1e3a0cb
3 changed files with 7 additions and 5 deletions

View file

@ -47,7 +47,7 @@ func NewAPIController(akURL url.URL, token string) *APIController {
config.Host = akURL.Host config.Host = akURL.Host
config.Scheme = akURL.Scheme config.Scheme = akURL.Scheme
config.HTTPClient = &http.Client{ config.HTTPClient = &http.Client{
Transport: NewTracingTransport(GetTLSTransport()), Transport: NewTracingTransport(context.TODO(), GetTLSTransport()),
} }
config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token))

View file

@ -1,6 +1,7 @@
package ak package ak
import ( import (
"context"
"net/http" "net/http"
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
@ -8,14 +9,15 @@ import (
type tracingTransport struct { type tracingTransport struct {
inner http.RoundTripper inner http.RoundTripper
ctx context.Context
} }
func NewTracingTransport(inner http.RoundTripper) *tracingTransport { func NewTracingTransport(ctx context.Context, inner http.RoundTripper) *tracingTransport {
return &tracingTransport{inner} return &tracingTransport{inner, ctx}
} }
func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) { func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) {
span := sentry.StartSpan(r.Context(), "authentik.go.http_request") span := sentry.StartSpan(tt.ctx, "authentik.go.http_request")
span.SetTag("url", r.URL.String()) span.SetTag("url", r.URL.String())
span.SetTag("method", r.Method) span.SetTag("method", r.Method)
defer span.Finish() defer span.Finish()

View file

@ -61,7 +61,7 @@ func NewFlowExecutor(ctx context.Context, flowSlug string, refConfig *api.Config
config.UserAgent = constants.OutpostUserAgent() config.UserAgent = constants.OutpostUserAgent()
config.HTTPClient = &http.Client{ config.HTTPClient = &http.Client{
Jar: jar, Jar: jar,
Transport: ak.NewTracingTransport(ak.GetTLSTransport()), Transport: ak.NewTracingTransport(ctx, ak.GetTLSTransport()),
} }
apiClient := api.NewAPIClient(config) apiClient := api.NewAPIClient(config)
return &FlowExecutor{ return &FlowExecutor{