GithubHelp home page GithubHelp logo

Sentry APM Middleware about atreugo HOT 1 CLOSED

kunal-saini avatar kunal-saini commented on July 22, 2024
Sentry APM Middleware

from atreugo.

Comments (1)

savsgio avatar savsgio commented on July 22, 2024

Hi @kunal-saini,

Sorry for my delayed answer but i'm so busy lately and thanks for use Atreugo in your project, i'm so glad about that 😃.

I reviewed your middleware and you could change this line with:

r := new(http.Request)
if err := fasthttpadaptor.ConvertRequest(ctx.RequestCtx, r, true); err != nil {
	// handle the error as you want
}

and remove this function.

About the HandleTracer middleware, a better option it's create a wapper that implements a io.Closer and save the tracer into the wrapper, that's saved on RequestCtx, because all user values that implements io.Closer will automatically close, and remove the unnecessary HandleTracer middleware in declaration on the global server after middlewares.

For example:

type tracerCloser struct {
	ctx  *fasthttp.RequestCtx // you must use here the inherit fasthttp.RequestCtx
	span *sentry.Span
}

func newTracerCloser(ctx *atreugo.RequestCtx, span *sentry.Span) *tracerCloser {
	return &tracerCloser{
		ctx:  ctx.RequestCtx, // you must use here the inherit fasthttp.RequestCtx
		span: span,
	}
}

func (tc *tracerCloser) Close() error {
	if tracerSpan := getTracerFromContext(tc.ctx); tracerSpan != nil {
		tracerSpan.Finish()
	}

	return nil
}

func getTracerFromContext(ctx *fasthttp.RequestCtx) *sentry.Span {
	tracer := ctx.UserValue(tracerKey)
	if tracer, ok := tracer.(*tracerCloser); ok {
		return tracer.span
	}
	return nil
}
// func (h *Handler) Handle(ctx *atreugo.RequestCtx) error {
    // ...
    if h.tracer {
        // ....
        ctx.SetUserValue(tracerKey, newTracerCloser(ctx, span))
    //....

from atreugo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.