wakatime / wakatime-cli

Command line interface used by all WakaTime text editor plugins
https://wakatime.com/plugins
BSD 3-Clause "New" or "Revised" License
266 stars 41 forks source link

Zscaler corporate proxy companion app is not working with wakatime #768

Open mt3o opened 1 year ago

mt3o commented 1 year ago

Hi, i have issue with current version of Wakatime client app - it can't get thru corporate proxy. The proxy is running on http://localhost:9000 and other programs seem to respect this setting, however WakaTime replies as follows:

{"caller":"pkg/api/diagnostic.go:28","func":"api.(*Client)","level":"debug","message":"sending diagnostic data to api at https://api.wakatime.com/api/v1/plugins/errors","now":"2022-08-26T09:45:14+02:00","version":"v1.54.0"}
{"caller":"cmd/run.go:276","func":"cmd.runCmd","level":"warning","message":"failed to send diagnostics: failed to send diagnostics to the API: failed making request to \"https://api.wakatime.com/api/v1/plugins/errors\": Post \"https://api.wakatime.com/api/v1/plugins/errors\": proxyconnect tcp: dial tcp :0: connectex: The requested address is not valid in its context.","now":"2022-08-26T09:45:14+02:00","version":"v1.54.0"}

I'm not sure if you are verifying somehow the proxy address in the new version, but it's not working as it should. It was working with python version.

Issue is remotely related to https://github.com/wakatime/jetbrains-wakatime/issues/127 but this time i checked deeper - trying the cli.

gandarez commented 1 year ago

Hi @mt3o

It doesn't auto-detect proxy settings from the machine. Please try setting up proxy into your ~/.wakatime.cfg file. For more information on how to do please refer to proxy here.

mt3o commented 1 year ago

Hi @gandarez

Of course the ~/.wakatime.cfg file has the proper line regarding the proxy. At least the same value that lets wget do to its job. I tried all sorts of setups, pointing to either zscaler companion app, listening on port 9000 on localhost, or company gateway. I tried also setting it by inline argument --proxy for wakatime-cli. Here is what I get at best:

"AppData\Roaming\WakaTime\wakatime-cli\wakatime-cli.exe" --proxy http://localhost:9000 --log-to-stdout --verbose --sync-offline-activity 1000
INFO 2022/08/29 08:46:19 attempting to merge in config file
INFO 2022/08/29 08:46:19 attempting to merge in config file
INFO 2022/08/29 08:46:19 attempting to merge in config file
INFO 2022/08/29 08:46:19 attempting to merge in config file
{"caller":"cmd/run.go:111","func":"cmd.Run","level":"debug","message":"command: sync-offline-activity","now":"2022-08-29T08:46:19+02:00","version":"v1.54.0"}
{"caller":"pkg/offline/offline.go:106","func":"offline.WithSync","level":"debug","message":"execute offline sync with file C:\\Users\\xxxx\\.wakatime.bdb","now":"2022-08-29T08:46:19+02:00","version":"v1.54.0"}
{"caller":"pkg/offline/offline.go:151","func":"offline.Sync","level":"debug","message":"send 25 heartbeats on sync run 1","now":"2022-08-29T08:46:19+02:00","version":"v1.54.0"}
{"caller":"pkg/apikey/apikey.go:31","func":"apikey.WithReplacing","level":"debug","message":"execute api key replacing","now":"2022-08-29T08:46:19+02:00","version":"v1.54.0"}
{"caller":"pkg/api/heartbeat.go:27","func":"api.(*Client)","level":"debug","message":"sending 25 heartbeat(s) to api at https://api.wakatime.com/api/v1/users/current/heartbeats.bulk","now":"2022-08-29T08:46:19+02:00","version":"v1.54.0"}

...

{"caller":"cmd/run.go:270","func":"cmd.runCmd","level":"error","message":"failed to run command: offline sync failed: failed to sync offline heartbeats: failed making request to \"https://api.wakatime.com/api/v1/users/current/heartbeats.bulk\": Post \"https://api.wakatime.com/api/v1/users/current/heartbeats.bulk\": read tcp [::1]:53718->[::1]:9000: wsarecv: An existing connection was forcibly closed by the remote host.","now":"2022-08-29T08:43:52+02:00","version":"v1.54.0"}
{"caller":"pkg/api/diagnostic.go:28","func":"api.(*Client)","level":"debug","message":"sending diagnostic data to api at https://api.wakatime.com/api/v1/plugins/errors","now":"2022-08-29T08:43:52+02:00","version":"v1.54.0"}
{"caller":"cmd/run.go:276","func":"cmd.runCmd","level":"warning","message":"failed to send diagnostics: failed to send diagnostics to the API: failed making request to \"https://api.wakatime.com/api/v1/plugins/errors\": Post \"https://api.wakatime.com/api/v1/plugins/errors\": read tcp [::1]:53719->[::1]:9000: wsarecv: An existing connection was forcibly closed by the remote host.","now":"2022-08-29T08:43:52+02:00","version":"v1.54.0"}

or

"AppData\Roaming\WakaTime\wakatime-cli\wakatime-cli.exe" --proxy http://gateway.zscaler.net --log-to-stdout --verbose --sync-offline-activity 1000
INFO 2022/08/29 08:48:13 attempting to merge in config file
INFO 2022/08/29 08:48:13 attempting to merge in config file
INFO 2022/08/29 08:48:13 attempting to merge in config file
INFO 2022/08/29 08:48:13 attempting to merge in config file
{"caller":"cmd/run.go:111","func":"cmd.Run","level":"debug","message":"command: sync-offline-activity","now":"2022-08-29T08:48:13+02:00","version":"v1.54.0"}
{"caller":"pkg/offline/offline.go:106","func":"offline.WithSync","level":"debug","message":"execute offline sync with file C:\\Users\\xxxx\\.wakatime.bdb","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}
{"caller":"pkg/offline/offline.go:151","func":"offline.Sync","level":"debug","message":"send 25 heartbeats on sync run 1","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}
{"caller":"pkg/apikey/apikey.go:31","func":"apikey.WithReplacing","level":"debug","message":"execute api key replacing","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}
{"caller":"pkg/api/heartbeat.go:27","func":"api.(*Client)","level":"debug","message":"sending 25 heartbeat(s) to api at https://api.wakatime.com/api/v1/users/current/heartbeats.bulk","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}

...

{"caller":"cmd/run.go:270","func":"cmd.runCmd","level":"error","message":"failed to run command: offline sync failed: failed to sync offline heartbeats: failed making request to \"https://api.wakatime.com/api/v1/users/current/heartbeats.bulk\": Post \"https://api.wakatime.com/api/v1/users/current/heartbeats.bulk\": Forbidden","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}
{"caller":"pkg/api/diagnostic.go:28","func":"api.(*Client)","level":"debug","message":"sending diagnostic data to api at https://api.wakatime.com/api/v1/plugins/errors","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}
{"caller":"cmd/run.go:276","func":"cmd.runCmd","level":"warning","message":"failed to send diagnostics: failed to send diagnostics to the API: failed making request to \"https://api.wakatime.com/api/v1/plugins/errors\": Post \"https://api.wakatime.com/api/v1/plugins/errors\": Forbidden","now":"2022-08-29T08:48:14+02:00","version":"v1.54.0"}

Here is the ~/.wakatime.cfg:

[settings]
api_key = xxxx
proxy = localhost:9000
debug = true

status_bar_enabled = true

The messages from cli are a little different from what log tells when using intellij, but still there is no success in pushing the events.

gandarez commented 1 year ago

Do you need authentication in order to use proxy? Try setting user and pass like so http://user:pass@localhost:9000.

mt3o commented 1 year ago

@gandarez usual programs don't need authentication. If they do, explicit login form is being shown in the browser. However tools like npm, maven or just wget don't have problems when proxy is configured. What brings issues - is ssl mismatch, as the proxy replaces certificates. Of couse i have no_ssl_verify = true in the config file.