Skip to content

Conversation

@michel-laterman
Copy link
Contributor

@michel-laterman michel-laterman commented May 26, 2025

Add ProxyURL an ProxyHeaders support to start settings as well as the example agent.

This PR will remain as a draft until the opamp-spec for the feature is released.

@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

❌ Patch coverage is 70.14925% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.05%. Comparing base (6af85ac) to head (03de983).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
client/wsclient.go 69.04% 10 Missing and 3 partials ⚠️
client/httpclient.go 0.00% 3 Missing and 1 partial ⚠️
client/internal/httpsender.go 85.71% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #389      +/-   ##
==========================================
- Coverage   78.24%   78.05%   -0.20%     
==========================================
  Files          27       27              
  Lines        2740     2807      +67     
==========================================
+ Hits         2144     2191      +47     
- Misses        473      488      +15     
- Partials      123      128       +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@michel-laterman michel-laterman force-pushed the feat/proxy-connection-settings branch from 15a4521 to 37536d8 Compare July 23, 2025 19:17
Comment on lines +457 to +478
case "http":
// FIXME: dialer.NetDialContext is currently used as a work around instead of setting dialer.Proxy as gorilla/websockets does not have 1st class support for setting proxy connect headers
// Once https://github.com/gorilla/websocket/issues/479 is complete, we should use dialer.Proxy, and dialer.ProxyConnectHeader
if len(headers) > 0 {
dialer, err := dialer.NewProxyConnectDialer(proxyURL, &net.Dialer{}, dialer.WithProxyConnectHeaders(headers))
if err != nil {
return err
}
c.dialer.NetDialContext = dialer.DialContext
return nil
}
c.dialer.Proxy = http.ProxyURL(proxyURL) // No connect headers, use a regular proxy
case "https":
if len(headers) > 0 {
dialer, err := dialer.NewProxyConnectDialer(proxyURL, &net.Dialer{}, dialer.WithTLS(cfg), dialer.WithProxyConnectHeaders(headers))
if err != nil {
return err
}
c.dialer.NetDialTLSContext = dialer.DialContext
return nil
}
c.dialer.Proxy = http.ProxyURL(proxyURL) // No connect headers, use a regular proxy
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a little messy (as we mix setting the dialer.Proxy and dialer.NetDial*Context methods); but it's much easer to do at this point in time then it is to replace the entire websockets library.

If gorilla/websocket#988 is ever merged and released we can clean this up.

I've tested this locally using tinyproxy.
I've confirmed that when the ProxyURL and ProxyHeaders are specified, the dialer is used and the proxy is used via CONNECT.
If I only specify the ProxyURL, the c.dialer.Proxy = http.ProxyURL(proxyURL) approach is used; one thing that is interesting to note is that this still results in CONNECT request to the proxy but that may be more to do with the use of websockets.

Steps to test:

  1. install and start tinyproxy - no additional config is needed for basic testing
  2. start the example opamp server
  3. Add the ProxyURL and ProxyHeaders to the example agent start settings:
    settings := types.StartSettings{
    OpAMPServerURL: "wss://127.0.0.1:4320/v1/opamp",
    TLSConfig: agent.tlsConfig,

    For example
ProxyURL: "http://localhost:8888", // tinyproxy's default address
ProxyHeaders: http.Header{"test-proxy-key": []string{"test-val"}},
  1. Start the example agent
  2. Agent should start and connect to the server; check the proxy logs to ensure that the connection has been made through the proxy.

@michel-laterman michel-laterman marked this pull request as ready for review July 29, 2025 20:04
@michel-laterman michel-laterman requested a review from a team as a code owner July 29, 2025 20:04
@michel-laterman
Copy link
Contributor Author

@andykellr @tigrannajaryan we're able to use a custom dialer func in order to get proxy connect headers working with gorilla/websockets.
I've created a custom dialer and have included it as a dependency.

The implementation is now ready for review.

@tigrannajaryan
Copy link
Member

@andykellr I would like your confirmation as well before we go ahead with this (and the corresponding spec change).

@andykellr andykellr merged commit cc702b5 into open-telemetry:main Aug 28, 2025
9 of 11 checks passed
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