Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a middleware library for Echo #49

Open
gagbo opened this issue May 16, 2023 · 3 comments
Open

Write a middleware library for Echo #49

gagbo opened this issue May 16, 2023 · 3 comments

Comments

@gagbo
Copy link
Member

gagbo commented May 16, 2023

Pending #47 merge.

Once the PR is merged, the ability to inject a new trace ID/span ID into an Echo context will only happen through a middleware library, to properly fill the autometrics.MiddlewareTraceIDKey and SpanIDKey fields with hex-encoded byte strings of the relevant IDs

@IvanZenger
Copy link

How is this going?

@gagbo
Copy link
Member Author

gagbo commented Dec 11, 2023

Hello, I haven’t had time yet to look into this (as I don’t have a simple Echo app that I could test on, and the time has been a bit lacking).

If you want to try to get your hand at it, I think the cleanest solution would be to write the library in a separate package in this repo, like pkg/echo/middleware/middleware.go with package middleware, and from there build the function (probably named Autometrics) that takes ...Option in parameters and return a func(next echo.HandlerFunc) echo.HandlerFunc. The usage in end-user application would then be:

e.Use(middleware.Autometrics(...))

The trick is to be able to set the context properly so that the middleware and the autometrics library can agree on things. I think the way to go is to have the middleware write the relevant data to the echo.Context using internal/autometrics keys. This way the instrumentation libraries (the ones in otel and prometheus subfolders) will directly be able to read it and all will work transparently, as long as autometrics detects and uses the context from Echo when used in a signature (that very last part is handled, but not well tested yet)

If you don’t have time for it that’s fine, I’m mostly writing this up for anyone who wants to take a go at it (which might be future me), but right now I don’t see myself having enough time to make it happen in the next month or so

@IvanZenger
Copy link

@gagbo, thank you for your explanation. It would be great to contribute. I'll probably find some time to do so after my holidays. 😉Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants