outpost: add tracing for http client
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		| @ -44,7 +44,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: GetTLSTransport(), | 		Transport: NewTracingTransport(GetTLSTransport()), | ||||||
| 	} | 	} | ||||||
| 	config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) | 	config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								internal/outpost/ak/tracing.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								internal/outpost/ak/tracing.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | package ak | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"net/http" | ||||||
|  |  | ||||||
|  | 	"github.com/getsentry/sentry-go" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type tracingTransport struct { | ||||||
|  | 	inner http.RoundTripper | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func NewTracingTransport(inner http.RoundTripper) *tracingTransport { | ||||||
|  | 	return &tracingTransport{inner} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (tt *tracingTransport) RoundTrip(r *http.Request) (*http.Response, error) { | ||||||
|  | 	span := sentry.StartSpan(r.Context(), "authentik.go.http_request") | ||||||
|  | 	span.SetTag("url", r.URL.String()) | ||||||
|  | 	span.SetTag("method", r.Method) | ||||||
|  | 	defer span.Finish() | ||||||
|  | 	return tt.inner.RoundTrip(r.WithContext(span.Context())) | ||||||
|  | } | ||||||
| @ -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.GetTLSTransport(), | 		Transport: ak.NewTracingTransport(ak.GetTLSTransport()), | ||||||
| 	} | 	} | ||||||
| 	apiClient := api.NewAPIClient(config) | 	apiClient := api.NewAPIClient(config) | ||||||
| 	return &FlowExecutor{ | 	return &FlowExecutor{ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer