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

Add otelhttp.NewMiddleware #2964

Merged
merged 2 commits into from May 31, 2023
Merged

Add otelhttp.NewMiddleware #2964

merged 2 commits into from May 31, 2023

Conversation

alnr
Copy link
Contributor

@alnr alnr commented Nov 2, 2022

For better compatiblity with third-party HTTP routers and middleware chainers (e.g. github.com/urfave/negroni or github.com/go-chi/chi).

The key difference between the existing otelhttp.Handler and the new otelhttp.Middleware is that Middleware takes the next handler as an argument after construction, wheres the existing Handler works by wrapping one specific http.Handler at construction time. The existing interfaces are unchanged.

Is there interest in principle in merging this? If yes I'll deal with the CLA etc.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 2, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: alnr / name: Arne Luenser (e3d5d21)

@Aneurysm9 Aneurysm9 added enhancement New feature or request blocked: CLA Waiting on CLA to be signed before progress can be made area: instrumentation Related to an instrumentation package labels Nov 2, 2022
@MrAlias
Copy link
Contributor

MrAlias commented Nov 3, 2022

@alnr thanks for the contribution, please sign the CLA so these changes can be considered.

@codecov
Copy link

codecov bot commented Nov 3, 2022

Codecov Report

Merging #2964 (8a00920) into main (75d0c13) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2964   +/-   ##
=====================================
  Coverage   79.3%   79.3%           
=====================================
  Files        165     165           
  Lines      10422   10426    +4     
=====================================
+ Hits        8274    8278    +4     
  Misses      2012    2012           
  Partials     136     136           
Impacted Files Coverage Δ
instrumentation/net/http/otelhttp/handler.go 83.1% <100.0%> (+0.3%) ⬆️

@alnr
Copy link
Contributor Author

alnr commented Dec 31, 2022

Hey. I'll do the paperwork early next year, sorry for the delay.

Have a great new year!

@RangelReale
Copy link
Contributor

I also would like this change, will this be followed up?

@dmathieu
Copy link
Member

It looks like @alnr never signed the CLA. So we can't use his work there.
If he doesn't intend to follow-up on this PR, there's nothing preventing someone from restarting the work from scratch to achieve the same thing though.

@RangelReale
Copy link
Contributor

I'll see if he answer today, if not I'll submit a followup tomorrow.

@alnr
Copy link
Contributor Author

alnr commented Apr 24, 2023

Sorry, this got lost among the paperwork. CLA signed.


// / NewMiddleware returns a tracing middleware from the given operation name and
// options.
func NewMiddleware(operation string, opts ...Option) *Middleware {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The middlewares I usually see are like the one for gorilla mux, in the form:

type MiddlewareFunc func(http.Handler) http.Handler

is this different in chi? I think most http middleware library accepts this form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func(http.Handler) http.Handler is most common, I agree. It's simple enough to write adapters for other uses.

I've pushed another commit, which gets rid of the otelhttp.Handler type. That's not strictly backwards compatible. Is that OK?

Copy link
Member

@pellared pellared Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed another commit, which gets rid of the otelhttp.Handler type. That's not strictly backwards compatible. Is that OK?

I think it is fine as the type does not make any sense. However, in future I would rather propose to do such changes in a separate PR.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@pellared pellared changed the title Add otelhttp.Middleware Add otelhttp.NewMiddleware Apr 26, 2023
@alnr
Copy link
Contributor Author

alnr commented Apr 26, 2023

Rebased and fixed lint (I hope?)

instrumentation/net/http/otelhttp/handler.go Outdated Show resolved Hide resolved
@pellared pellared removed the blocked: CLA Waiting on CLA to be signed before progress can be made label Apr 26, 2023
@alnr
Copy link
Contributor Author

alnr commented May 5, 2023

Gentle bump for review or merge :)

@pellared
Copy link
Member

pellared commented May 8, 2023

@alnr Can you please update the branch (and resolve the conflicts)?

alnr and others added 2 commits May 31, 2023 09:52
…TTP routers and middleware chainers

The key difference between the existing otelhttp.NewHandler and
otelhttp.NewMiddleware is that the middleware takes the `next` handler
as an argument after construction, wheres NewHandler works by wrapping
one specific http.Handler at construction time.
@alnr
Copy link
Contributor Author

alnr commented May 31, 2023

@alnr Can you please update the branch (and resolve the conflicts)?

done

@pellared pellared merged commit ba7a210 into open-telemetry:main May 31, 2023
22 checks passed
@MrAlias MrAlias added this to the v0.43.0 milestone Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: instrumentation Related to an instrumentation package enhancement New feature or request instrumentation: otelhttp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants