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

Huma middleware can't access some information comming from the http.Request #590

Open
aureliar8 opened this issue Sep 27, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@aureliar8
Copy link

I'm in the process of adding opentelemetry support to one of our project that uses huma.

As I want to set the operationID that was matched to this request as a span name/attribute I need to make that at the huma middleware. (An router-level middleware wouldn't have this information)

In this middleware I need to crate a new opentelemetry span and then attach some attribute to it that describe the request.
This list of attribute is standardized. There are two attributes that are required by the standard and that can't be accessed from a huma.Context (unless I missed something)

  • Whether or not tls is used for the request
  • The http version used for the request (1.0/1.1/2.0...)

In other opentelemetry interceptors & middleware this information is extracted from the http.Request struct and specifically the r.TLS, r.Proto, r.ProtoMajor and r.ProtoMinor fields.

@danielgtaylor danielgtaylor added the enhancement New feature or request label Oct 9, 2024
@danielgtaylor
Copy link
Owner

@aureliar8 this seems like a missing feature in the adapter interface. I'll see if I can get it added to enable this use case. Thanks for reporting!

@george-rogers
Copy link

george-rogers commented Oct 18, 2024

@danielgtaylor any reason why huma.Context cannot expose the underlying *http.Request? That would save some hassle and we wouldn't have to deal with manual wiring of the adapter

It would be nice to also allow overriding the underlying http.ResponseWriter as other observability APIs automatically instrument it, eg. NewRelic

@danielgtaylor
Copy link
Owner

@george-rogers not all routers use the standard library for HTTP, for example Fiber has its own HTTP library with its own request type, so we couldn't just return an *http.Request. I've been spending some time thinking about how to simplify this but am not sure what we can do yet.

@joa23
Copy link

joa23 commented Oct 25, 2024

@danielgtaylor - just exporting the ChiContext would be sufficient for my use case. e.g. type chiContext struct { -> type ChiContext struct { as I could just cast it in the middleware. No?

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

No branches or pull requests

4 participants