Skip to content

Commit

Permalink
feat: Move OTEL to a new 'InstrumentedFosite'
Browse files Browse the repository at this point in the history
  • Loading branch information
vivshankar committed Aug 5, 2023
1 parent 198f913 commit a0440d9
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 45 deletions.
5 changes: 0 additions & 5 deletions access_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

"github.com/ory/fosite/i18n"
"github.com/ory/x/errorsx"
"github.com/ory/x/otelx"
"go.opentelemetry.io/otel/trace"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -42,9 +40,6 @@ import (
// client MUST authenticate with the authorization server as described
// in Section 3.2.1.
func (f *Fosite) NewAccessRequest(ctx context.Context, r *http.Request, session Session) (_ AccessRequester, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewAccessRequest")
defer otelx.End(span, &err)

accessRequest := NewAccessRequest(session)
accessRequest.Request.Lang = i18n.GetLangFromRequest(f.Config.GetMessageCatalog(ctx), r)

Expand Down
5 changes: 0 additions & 5 deletions access_response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ import (
"context"

"github.com/ory/x/errorsx"
"github.com/ory/x/otelx"
"go.opentelemetry.io/otel/trace"

"github.com/pkg/errors"
)

func (f *Fosite) NewAccessResponse(ctx context.Context, requester AccessRequester) (_ AccessResponder, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewAccessResponse")
defer otelx.End(span, &err)

var tk TokenEndpointHandler

response := NewAccessResponse()
Expand Down
5 changes: 0 additions & 5 deletions authorize_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import (
"strings"

"github.com/go-jose/go-jose/v3"
"go.opentelemetry.io/otel/trace"

"github.com/ory/fosite/i18n"
"github.com/ory/fosite/token/jwt"
"github.com/ory/x/errorsx"
"github.com/ory/x/otelx"

"github.com/pkg/errors"

Expand Down Expand Up @@ -309,9 +307,6 @@ func (f *Fosite) authorizeRequestFromPAR(ctx context.Context, r *http.Request, r
}

func (f *Fosite) NewAuthorizeRequest(ctx context.Context, r *http.Request) (_ AuthorizeRequester, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewAuthorizeRequest")
defer otelx.End(span, &err)

return f.newAuthorizeRequest(ctx, r, false)
}

Expand Down
5 changes: 0 additions & 5 deletions authorize_response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import (
"net/url"

"github.com/ory/x/errorsx"
"github.com/ory/x/otelx"
"go.opentelemetry.io/otel/trace"
)

func (f *Fosite) NewAuthorizeResponse(ctx context.Context, ar AuthorizeRequester, session Session) (_ AuthorizeResponder, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewAuthorizeResponse")
defer otelx.End(span, &err)

var resp = &AuthorizeResponse{
Header: http.Header{},
Parameters: url.Values{},
Expand Down
5 changes: 0 additions & 5 deletions introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"

"github.com/ory/x/errorsx"
"github.com/ory/x/otelx"
"go.opentelemetry.io/otel/trace"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -39,9 +37,6 @@ func AccessTokenFromRequest(req *http.Request) string {
}

func (f *Fosite) IntrospectToken(ctx context.Context, token string, tokenUse TokenUse, session Session, scopes ...string) (_ TokenUse, _ AccessRequester, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.IntrospectToken")
defer otelx.End(span, &err)

var found = false
var foundTokenUse TokenUse = ""

Expand Down
5 changes: 0 additions & 5 deletions introspection_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
"net/url"
"strings"

"go.opentelemetry.io/otel/trace"
"golang.org/x/text/language"

"github.com/ory/x/errorsx"
"github.com/ory/x/otelx"
)

// NewIntrospectionRequest initiates token introspection as defined in
Expand Down Expand Up @@ -96,9 +94,6 @@ import (
//
// token=mF_9.B5f-4.1JqM&token_type_hint=access_token
func (f *Fosite) NewIntrospectionRequest(ctx context.Context, r *http.Request, session Session) (_ IntrospectionResponder, err error) {
ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("github.com/ory/fosite").Start(ctx, "Fosite.NewIntrospectionRequest")
defer otelx.End(span, &err)

ctx = context.WithValue(ctx, RequestContextKey, r)

if r.Method != "POST" {
Expand Down
Loading

0 comments on commit a0440d9

Please sign in to comment.