Skip to content

Commit

Permalink
feat: trace web hook calls (#2154)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinei authored and aeneasr committed Feb 14, 2022
1 parent c8d55b3 commit 98ee300
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
7 changes: 3 additions & 4 deletions cmd/daemon/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func ServePublic(r driver.Registry, wg *sync.WaitGroup, cmd *cobra.Command, args
n.Use(publicLogger)
n.Use(x.HTTPLoaderContextMiddleware(r))
n.Use(sqa(ctx, cmd, r))
if tracer := r.Tracer(ctx); tracer.IsLoaded() {
n.Use(tracer)
}
n.Use(r.PrometheusManager())

router := x.NewRouterPublic()
Expand All @@ -110,10 +113,6 @@ func ServePublic(r driver.Registry, wg *sync.WaitGroup, cmd *cobra.Command, args
r.RegisterPublicRoutes(ctx, router)
r.PrometheusManager().RegisterRouter(router.Router)

if tracer := r.Tracer(ctx); tracer.IsLoaded() {
n.Use(tracer)
}

var handler http.Handler = n
options, enabled := r.Config(ctx).CORS("public")
if enabled {
Expand Down
9 changes: 7 additions & 2 deletions driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,13 @@ func (m *RegistryDefault) HTTPClient(ctx context.Context, opts ...httpx.Resilien
opts = append(opts,
httpx.ResilientClientWithLogger(m.Logger()),
httpx.ResilientClientWithMaxRetry(2),
httpx.ResilientClientWithConnectionTimeout(30*time.Second),
)
httpx.ResilientClientWithConnectionTimeout(30*time.Second))

tracer := m.Tracer(ctx)
if tracer.IsLoaded() {
opts = append(opts, httpx.ResilientClientWithTracer(tracer.Tracer()))
}

if m.Config(ctx).ClientHTTPNoPrivateIPRanges() {
opts = append(opts, httpx.ResilientClientDisallowInternalIPs())
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ require (
github.com/ory/kratos-client-go v0.6.3-alpha.1
github.com/ory/mail/v3 v3.0.0
github.com/ory/nosurf v1.2.7
github.com/ory/x v0.0.336
github.com/ory/x v0.0.337
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/pquerna/otp v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1642,8 +1642,8 @@ github.com/ory/x v0.0.205/go.mod h1:A1s4iwmFIppRXZLF3J9GGWeY/HpREVm0Dk5z/787iek=
github.com/ory/x v0.0.250/go.mod h1:jUJaVptu+geeqlb9SyQCogTKj5ztSDIF6APkhbKtwLc=
github.com/ory/x v0.0.272/go.mod h1:1TTPgJGQutrhI2OnwdrTIHE9ITSf4MpzXFzA/ncTGRc=
github.com/ory/x v0.0.288/go.mod h1:APpShLyJcVzKw1kTgrHI+j/L9YM+8BRjHlcYObc7C1U=
github.com/ory/x v0.0.336 h1:z2AHweTT3A7q+Euq6Kna8jz3wogvLl6eMo7dGuNeZvU=
github.com/ory/x v0.0.336/go.mod h1:VxITg5o/DfPfom76ni5FfFzP66Z+kLvJ/OATJxuT42c=
github.com/ory/x v0.0.337 h1:YDlmEA43NMJJxezVVAQoqXyyYl/ZZSh9+mA8JSbOECw=
github.com/ory/x v0.0.337/go.mod h1:VxITg5o/DfPfom76ni5FfFzP66Z+kLvJ/OATJxuT42c=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/parnurzeal/gorequest v0.2.15/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down
5 changes: 3 additions & 2 deletions selfservice/hook/web_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (e *WebHook) execute(ctx context.Context, data *templateContext) error {
body = bytes.NewReader(make([]byte, 0))
}

if err = doHttpCall(conf.Method, conf.URL, conf.Auth, body, httpClient); err != nil {
if err = doHttpCall(ctx, conf.Method, conf.URL, conf.Auth, body, httpClient); err != nil {
return fmt.Errorf("failed to call web hook %w", err)
}
return nil
Expand Down Expand Up @@ -317,8 +317,9 @@ func createBody(l *logrusx.Logger, templateURI string, data *templateContext, hc
}
}

func doHttpCall(method string, url string, as AuthStrategy, body io.Reader, hc *retryablehttp.Client) error {
func doHttpCall(ctx context.Context, method string, url string, as AuthStrategy, body io.Reader, hc *retryablehttp.Client) error {
req, err := retryablehttp.NewRequest(method, url, body)
req = req.WithContext(ctx)
if err != nil {
return err
}
Expand Down

0 comments on commit 98ee300

Please sign in to comment.