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

feat: Add optional HTTP Middleware function to StartSettings for serverimpl #263

Merged

Conversation

gdfast
Copy link
Contributor

@gdfast gdfast commented Mar 15, 2024

Problem

Traces for HTTP requests to the opamp-go server break, see #253

Solution

  • Add an HTTP Handler middleware function to StartSettings
  • If this function is configured, apply it in serverimpl's Start where the HTTP Handler is set
  • (add unit tests)

Code review notes

  • This is a step in addressing opamp-go server impl is breaking traces #253 but mostly just for HTTP clients and requests. There is likely more to do for maintaining trace linkage through requests that come over websocket connections
  • I figured if users are using Attach instead of Start, they might have their own middleware configured for their HTTP server, so it makes more sense to hook this into StartSettings and the Start function

@gdfast gdfast requested a review from a team March 15, 2024 19:06
Copy link

linux-foundation-easycla bot commented Mar 15, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

…erimpl

Problem
---------------------

Traces for HTTP requests to the opamp-go server break, see open-telemetry#253

Solution
---------------------

- Add an HTTP Handler middleware function to `StartSettings`
- If this function is configured, apply it in serverimpl's `Start` where the HTTP Handler is set
- (add unit tests)

Code review notes
---------------------

- This is a step in addressing open-telemetry#253 but mostly just for HTTP clients and requests. There is likely more to do for maintaining trace linkage through requests that come over websocket connections
- I figured if users are using `Attach` instead of `Start`, they might have their own middleware configured for their HTTP server, so it makes more sense to hook this into `StartSettings` and the `Start` function
@gdfast gdfast force-pushed the gfast-add-server-middleware-hook branch from e1d08d7 to bdd080a Compare March 15, 2024 19:12
@andykellr
Copy link
Contributor

I was curious why we weren't running into this and realized that we're using Attach. I'm fine with adding this, but I would expect most users to use Attach. @tigrannajaryan @evan-bradley please have a look.

Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.98%. Comparing base (d1d6081) to head (929e0d0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #263      +/-   ##
==========================================
+ Coverage   74.70%   74.98%   +0.27%     
==========================================
  Files          25       25              
  Lines        1625     1631       +6     
==========================================
+ Hits         1214     1223       +9     
+ Misses        299      297       -2     
+ Partials      112      111       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tigrannajaryan
Copy link
Member

  • This is a step in addressing opamp-go server impl is breaking traces #253 but mostly just for HTTP clients and requests. There is likely more to do for maintaining trace linkage through requests that come over websocket connections

@gdfast Can you please post the outline of the full plan with all the steps? I want to see the big picture before we merge this PR.

@tigrannajaryan
Copy link
Member

CLA Not Signed

Please sign the CLA.

server/server.go Outdated Show resolved Hide resolved
@gdfast
Copy link
Contributor Author

gdfast commented Mar 15, 2024

CLA Not Signed

Please sign the CLA.

Working on it, it's in progress. I'm signing on as a Corprorate Contributor and am waiting for my company's CLA Manager

@gdfast
Copy link
Contributor Author

gdfast commented Mar 15, 2024

  • This is a step in addressing opamp-go server impl is breaking traces #253 but mostly just for HTTP clients and requests. There is likely more to do for maintaining trace linkage through requests that come over websocket connections

@gdfast Can you please post the outline of the full plan with all the steps? I want to see the big picture before we merge this PR.

My company/team has some HTTP Middleware code that adds OTel instrumentation that I'm planning to use in our OpAMP service that is built around opamp-go. I'm planning to follow up with my leads/management about contributing some version of this middleware in a separate, public Go module as you recommended, but I don't know what they'll say. I think giving users the ability to add their own HTTP Middleware is net good though, right?

Meanwhile, I'll need to start looking into how to propagate context for the messages that come in on a websocket connection. I imagine we may need some similar hook to add middleware in order to facilitate Otel Go SDK instrumentation, but I'm not sure.

I think I mentioned that I'm pretty new to Go and OTel instrumentation, so I'm learning as I go

@tigrannajaryan
Copy link
Member

My company/team has some HTTP Middleware code that adds OTel instrumentation that I'm planning to use in our OpAMP service that is built around opamp-go. I'm planning to follow up with my leads/management about contributing some version of this middleware in a separate, public Go module as you recommended, but I don't know what they'll say. I think giving users the ability to add their own HTTP Middleware is net good though, right?

If you end up not contributing your implementation to Otel I would still want to see some example showing how the new capability can be used. It can be a very minimal example, just to demonstrate the idea.

@gdfast
Copy link
Contributor Author

gdfast commented Mar 15, 2024

My company/team has some HTTP Middleware code that adds OTel instrumentation that I'm planning to use in our OpAMP service that is built around opamp-go. I'm planning to follow up with my leads/management about contributing some version of this middleware in a separate, public Go module as you recommended, but I don't know what they'll say. I think giving users the ability to add their own HTTP Middleware is net good though, right?

If you end up not contributing your implementation to Otel I would still want to see some example showing how the new capability can be used. It can be a very minimal example, just to demonstrate the idea.

Sure thing. Where did you have in mind for this? I could add to https://github.com/open-telemetry/opamp-go/blob/main/internal/examples/server/opampsrv/opampsrv.go but I want to be careful not to add the OTel Go SDK to the repo unnecessarily. I guess adding to the examples directory is fine though?

@tigrannajaryan
Copy link
Member

If you end up not contributing your implementation to Otel I would still want to see some example showing how the new capability can be used. It can be a very minimal example, just to demonstrate the idea.

Sure thing. Where did you have in mind for this? I could add to https://github.com/open-telemetry/opamp-go/blob/main/internal/examples/server/opampsrv/opampsrv.go but I want to be careful not to add the OTel Go SDK to the repo unnecessarily. I guess adding to the examples directory is fine though?

Yes, it is fine to add to opampsrv in the examples directory since it is a separate Go module. The example can use the Otel Go SDK.

@gdfast
Copy link
Contributor Author

gdfast commented Mar 20, 2024

If you end up not contributing your implementation to Otel I would still want to see some example showing how the new capability can be used. It can be a very minimal example, just to demonstrate the idea.

Sure thing. Where did you have in mind for this? I could add to https://github.com/open-telemetry/opamp-go/blob/main/internal/examples/server/opampsrv/opampsrv.go but I want to be careful not to add the OTel Go SDK to the repo unnecessarily. I guess adding to the examples directory is fine though?

Yes, it is fine to add to opampsrv in the examples directory since it is a separate Go module. The example can use the Otel Go SDK.

@tigrannajaryan I went with a very minimal example of using otelhttp.NewMiddleware to create the HTTP middleware, which I think should actually be a good idea for users who want to add OTel tracing!

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just one small comment to reduce the public API surface.

server/serverimpl.go Outdated Show resolved Hide resolved
@gdfast
Copy link
Contributor Author

gdfast commented Mar 21, 2024

Hoping this is good to go now @tigrannajaryan . Thanks for your guidance and feedback!

@tigrannajaryan tigrannajaryan merged commit 6e13d00 into open-telemetry:main Mar 22, 2024
7 checks passed
@tigrannajaryan
Copy link
Member

Thank you @gdfast

@gdfast gdfast deleted the gfast-add-server-middleware-hook branch March 22, 2024 14:13
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

Successfully merging this pull request may close these issues.

3 participants