diff --git a/courier/http.go b/courier/http.go index 1e70803b9cff..6542d26964af 100644 --- a/courier/http.go +++ b/courier/http.go @@ -33,7 +33,7 @@ func (c *courier) dispatchMailerEmail(ctx context.Context, msg Message) (err err ctx, span := c.deps.Tracer(ctx).Tracer().Start(ctx, "courier.http.dispatchMailerEmail") defer otelx.End(span, &err) - builder, err := request.NewBuilder(c.httpClient.RequestConfig, c.deps) + builder, err := request.NewBuilder(ctx, c.httpClient.RequestConfig, c.deps) if err != nil { return err } diff --git a/courier/sms.go b/courier/sms.go index c73673d3fb66..e6b7a1925a9b 100644 --- a/courier/sms.go +++ b/courier/sms.go @@ -83,7 +83,7 @@ func (c *courier) dispatchSMS(ctx context.Context, msg Message) error { return err } - builder, err := request.NewBuilder(c.smsClient.RequestConfig, c.deps) + builder, err := request.NewBuilder(ctx, c.smsClient.RequestConfig, c.deps) if err != nil { return err } diff --git a/go.mod b/go.mod index 0eca98e31a61..b7a72b85f39b 100644 --- a/go.mod +++ b/go.mod @@ -76,7 +76,7 @@ require ( github.com/ory/jsonschema/v3 v3.0.8 github.com/ory/mail/v3 v3.0.0 github.com/ory/nosurf v1.2.7 - github.com/ory/x v0.0.581 + github.com/ory/x v0.0.583 github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/pkg/errors v0.9.1 github.com/pquerna/otp v1.4.0 @@ -166,6 +166,7 @@ require ( github.com/gobuffalo/plush/v4 v4.1.18 // indirect github.com/gobuffalo/tags/v3 v3.1.4 // indirect github.com/gobuffalo/validate/v3 v3.3.3 // indirect + github.com/gobwas/glob v0.2.3 // indirect github.com/goccy/go-yaml v1.9.6 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/go.sum b/go.sum index cc12bfcf045d..5422e5e53752 100644 --- a/go.sum +++ b/go.sum @@ -137,7 +137,6 @@ github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvA github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= github.com/coreos/go-oidc v2.2.1+incompatible h1:mh48q/BqXqgjVHpy2ZY7WnWAbenxRjsz9N1i1YxjHAk= github.com/coreos/go-oidc v2.2.1+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -343,6 +342,8 @@ github.com/gobuffalo/tags/v3 v3.1.4 h1:X/ydLLPhgXV4h04Hp2xlbI2oc5MDaa7eub6zw8oHj github.com/gobuffalo/tags/v3 v3.1.4/go.mod h1:ArRNo3ErlHO8BtdA0REaZxijuWnWzF6PUXngmMXd2I0= github.com/gobuffalo/validate/v3 v3.3.3 h1:o7wkIGSvZBYBd6ChQoLxkz2y1pfmhbI4jNJYh6PuNJ4= github.com/gobuffalo/validate/v3 v3.3.3/go.mod h1:YC7FsbJ/9hW/VjQdmXPvFqvRis4vrRYFxr69WiNZw6g= +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/goccy/go-yaml v1.9.6 h1:KhAu1zf9JXnm3vbG49aDE0E5uEBUsM4uwD31/58ZWyI= github.com/goccy/go-yaml v1.9.6/go.mod h1:JubOolP3gh0HpiBc4BLRD4YmjEjHAmIIB2aaXKkTfoE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -367,7 +368,6 @@ github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -498,7 +498,6 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0= github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= @@ -817,8 +816,8 @@ github.com/ory/nosurf v1.2.7 h1:YrHrbSensQyU6r6HT/V5+HPdVEgrOTMJiLoJABSBOp4= github.com/ory/nosurf v1.2.7/go.mod h1:d4L3ZBa7Amv55bqxCBtCs63wSlyaiCkWVl4vKf3OUxA= github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2 h1:zm6sDvHy/U9XrGpixwHiuAwpp0Ock6khSVHkrv6lQQU= github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= -github.com/ory/x v0.0.581 h1:WjSAjuOluINj6wXn2bKbjpDbrBAkEyBFLOBgZeDfsIM= -github.com/ory/x v0.0.581/go.mod h1:zUGmLuqZ81XQPeTBmE1Fhfvr1ygEkDJky33IxvRaioA= +github.com/ory/x v0.0.583 h1:z6xkrTip16ytAcEvL+nRdK0J+jPWyBeo8qpFOAErZ1g= +github.com/ory/x v0.0.583/go.mod h1:tgk6em/hJrDRmWAlM2g1hSNnE6rmCOk4eQ/q53/2kZc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= diff --git a/request/builder.go b/request/builder.go index fae2c3d13d58..48d43856edf1 100644 --- a/request/builder.go +++ b/request/builder.go @@ -13,6 +13,10 @@ import ( "reflect" "strings" + "go.opentelemetry.io/otel/attribute" + + "github.com/ory/x/otelx" + "github.com/google/go-jsonnet" "github.com/hashicorp/go-retryablehttp" "github.com/pkg/errors" @@ -32,6 +36,7 @@ const ( type ( Dependencies interface { x.LoggingProvider + x.TracingProvider x.HTTPClientProvider jsonnetsecure.VMProvider } @@ -42,12 +47,17 @@ type ( } ) -func NewBuilder(config json.RawMessage, deps Dependencies) (*Builder, error) { +func NewBuilder(ctx context.Context, config json.RawMessage, deps Dependencies) (_ *Builder, err error) { + _, span := deps.Tracer(ctx).Tracer().Start(ctx, "request.NewBuilder") + defer otelx.End(span, &err) + c, err := parseConfig(config) if err != nil { return nil, err } + span.SetAttributes(attribute.String("url", c.URL), attribute.String("method", c.Method)) + r, err := retryablehttp.NewRequest(c.Method, c.URL, nil) if err != nil { return nil, err @@ -74,6 +84,9 @@ func (b *Builder) addAuth() error { } func (b *Builder) addBody(ctx context.Context, body interface{}) error { + ctx, span := b.deps.Tracer(ctx).Tracer().Start(ctx, "request.Builder.addBody") + defer span.End() + if isNilInterface(body) { return nil } diff --git a/request/builder_test.go b/request/builder_test.go index a947b75e2e51..cffa032cc2f9 100644 --- a/request/builder_test.go +++ b/request/builder_test.go @@ -18,6 +18,7 @@ import ( "github.com/ory/kratos/x" "github.com/ory/x/jsonnetsecure" "github.com/ory/x/logrusx" + "github.com/ory/x/otelx" ) type testRequestBody struct { @@ -244,7 +245,7 @@ func TestBuildRequest(t *testing.T) { } { t.Run( "request-type="+tc.name, func(t *testing.T) { - rb, err := NewBuilder(json.RawMessage(tc.rawConfig), newTestDependencyProvider(t)) + rb, err := NewBuilder(context.Background(), json.RawMessage(tc.rawConfig), newTestDependencyProvider(t)) require.NoError(t, err) assert.Equal(t, tc.bodyTemplateURI, rb.Config.TemplateURI) @@ -272,7 +273,7 @@ func TestBuildRequest(t *testing.T) { t.Run( "cancel request", func(t *testing.T) { - rb, err := NewBuilder(json.RawMessage( + rb, err := NewBuilder(context.Background(), json.RawMessage( `{ "url": "https://test.kratos.ory.sh/my_endpoint6", "method": "POST", @@ -296,6 +297,7 @@ func newTestDependencyProvider(t *testing.T) *testDependencyProvider { return &testDependencyProvider{ SimpleLoggerWithClient: x.SimpleLoggerWithClient{ L: logrusx.New("kratos", "test"), + T: otelx.NewNoop(nil, nil), }, TestProvider: jsonnetsecure.NewTestProvider(t), } diff --git a/selfservice/hook/web_hook.go b/selfservice/hook/web_hook.go index 474a18343c61..6a5a8f358e47 100644 --- a/selfservice/hook/web_hook.go +++ b/selfservice/hook/web_hook.go @@ -327,7 +327,7 @@ func (e *WebHook) execute(ctx context.Context, data *templateContext) error { } }() - builder, err := request.NewBuilder(e.conf, e.deps) + builder, err := request.NewBuilder(ctx, e.conf, e.deps) if err != nil { return err }