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 proxy support #2192

Merged
merged 42 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5112a04
string based proxy config
denrase Jul 22, 2024
0eae983
add Proxy class
denrase Jul 22, 2024
f65672d
Use proxy class, Sync to android native
denrase Jul 23, 2024
eac8ee6
test io client provider
denrase Jul 23, 2024
8ec2844
rename file
denrase Jul 23, 2024
33272ed
Merge branch 'main' into feat/proxy-setup
denrase Jul 23, 2024
301fd22
update docs
denrase Jul 23, 2024
1941696
fix port parsing
denrase Jul 23, 2024
8dc9f47
Use client provider in SpotlightHttpTransport
denrase Jul 23, 2024
488007a
check if HttpClientBasicCredentials are set
denrase Jul 23, 2024
56997b9
fix init native sdk tests
denrase Jul 23, 2024
101f8fa
add cl entry and format kotlin code
denrase Jul 23, 2024
97a1c79
fix multilin issue
denrase Jul 23, 2024
8ca76d9
use toUpperCase(Locale.ROOT)
denrase Jul 23, 2024
d8a516d
fix newlines
denrase Jul 23, 2024
569400a
fix newline
denrase Jul 23, 2024
0d11ed6
format
denrase Jul 23, 2024
8e5baf1
format flutter
denrase Jul 23, 2024
6b2a062
log parse error
denrase Jul 23, 2024
a8ae146
format by running ktlint locally
denrase Jul 23, 2024
8452d39
import log
denrase Jul 23, 2024
c1ece00
Merge branch 'main' into feat/proxy-setup
denrase Jul 23, 2024
2e9926e
fix cl
denrase Jul 23, 2024
3b50810
Merge branch 'main' into feat/proxy-setup
denrase Jul 29, 2024
ef70ca4
fix cl
denrase Jul 29, 2024
a7a04d9
fix typo
denrase Jul 29, 2024
4d97570
mark client providers as internal
denrase Jul 29, 2024
16c6795
rename Proxy to SentryProxy
denrase Jul 29, 2024
67c474f
configure url session on ios
denrase Jul 29, 2024
acb2658
update changelog entry
denrase Jul 30, 2024
4bbf911
run swiftlingt —autocorrect
denrase Jul 30, 2024
f48b52d
run swiftling —autocorrect
denrase Jul 30, 2024
89c0915
run format
denrase Jul 30, 2024
b71613a
Merge branch 'main' into feat/proxy-setup
buenaflor Jul 30, 2024
c5b9a93
Merge branch 'main' into feat/proxy-setup
denrase Aug 5, 2024
b53e604
fix cl and add log
denrase Aug 5, 2024
c240fc7
update docs
denrase Aug 5, 2024
921b4d6
Merge branch 'main' into feat/proxy-setup
denrase Aug 6, 2024
242cdb1
Merge branch 'main' into feat/proxy-setup
denrase Aug 6, 2024
3c4c717
Merge branch 'main' into feat/proxy-setup
denrase Aug 6, 2024
4e25d10
disable swiftlint rules
denrase Aug 6, 2024
bd279c7
fix swiftlint issues
denrase Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

- Support `ignoredExceptionsForType` ([#2150](https://github.com/getsentry/sentry-dart/pull/2150))
- Filter out exception types by calling `SentryOptions.addExceptionFilterForType(Type exceptionType)`

- Add proxy support ([#2192](https://github.com/getsentry/sentry-dart/pull/2192))
denrase marked this conversation as resolved.
Show resolved Hide resolved

### Fixes

- Disable sff & frame delay detection on web, linux and windows ([#2182](https://github.com/getsentry/sentry-dart/pull/2182))
Expand Down
2 changes: 2 additions & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ export 'src/sentry_span_operations.dart';
export 'src/utils.dart';
// spotlight debugging
export 'src/spotlight.dart';
// proxy
export 'src/proxy.dart';
13 changes: 13 additions & 0 deletions dart/lib/src/http_client/client_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:http/http.dart';

import '../sentry_options.dart';

ClientProvider getClientProvider() {
denrase marked this conversation as resolved.
Show resolved Hide resolved
return ClientProvider();

Check warning on line 6 in dart/lib/src/http_client/client_provider.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/http_client/client_provider.dart#L5-L6

Added lines #L5 - L6 were not covered by tests
}

class ClientProvider {
Client getClient(SentryOptions options) {
return Client();

Check warning on line 11 in dart/lib/src/http_client/client_provider.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/http_client/client_provider.dart#L10-L11

Added lines #L10 - L11 were not covered by tests
}
}
64 changes: 64 additions & 0 deletions dart/lib/src/http_client/io_client_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:io';

import 'package:http/http.dart';
import 'package:http/io_client.dart';

import '../protocol.dart';
import '../proxy.dart';
import '../sentry_options.dart';
import 'client_provider.dart';

ClientProvider getClientProvider() {
return IoClientProvider(
() {
return HttpClient();

Check warning on line 14 in dart/lib/src/http_client/io_client_provider.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/http_client/io_client_provider.dart#L13-L14

Added lines #L13 - L14 were not covered by tests
},
(user, pass) {
return HttpClientBasicCredentials(user, pass);
},

Check warning on line 18 in dart/lib/src/http_client/io_client_provider.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/http_client/io_client_provider.dart#L16-L18

Added lines #L16 - L18 were not covered by tests
);
}

class IoClientProvider implements ClientProvider {
final HttpClient Function() _httpClient;
final HttpClientCredentials Function(String, String) _httpClientCredentials;

IoClientProvider(this._httpClient, this._httpClientCredentials);

@override
Client getClient(SentryOptions options) {
final proxy = options.proxy;
if (proxy == null) {
return Client();
}
final pac = proxy.toPacString();
if (proxy.type == ProxyType.socks) {
options.logger(
SentryLevel.warning,
"Setting proxy '$pac' is not supported.",
);
return Client();
}
options.logger(
SentryLevel.info,
"Setting proxy '$pac'",
);
final httpClient = _httpClient();
httpClient.findProxy = (url) => pac;

final host = proxy.host;
final port = proxy.port;
final user = proxy.user;
final pass = proxy.pass;

if (host != null && port != null && user != null && pass != null) {
httpClient.addProxyCredentials(
host,
port,
'',
_httpClientCredentials(user, pass),
);
}
return IOClient(httpClient);
}
}
62 changes: 62 additions & 0 deletions dart/lib/src/proxy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Proxy {
denrase marked this conversation as resolved.
Show resolved Hide resolved
denrase marked this conversation as resolved.
Show resolved Hide resolved
final ProxyType type;
final String? host;
final int? port;
final String? user;
final String? pass;

Proxy({required this.type, this.host, this.port, this.user, this.pass});

String toPacString() {
String type = 'DIRECT';
switch (this.type) {
case ProxyType.direct:
return 'DIRECT';
case ProxyType.http:
type = 'PROXY';
break;
case ProxyType.socks:
type = 'SOCKS';
break;
}
if (host != null && port != null) {
return '$type $host:$port';
} else if (host != null) {
return '$type $host';
} else {
return 'DIRECT';
}
}

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
return {
if (host != null) 'host': host,
if (port != null) 'port': port,
'type': type.toString().split('.').last.toUpperCase(),
if (user != null) 'user': user,
if (pass != null) 'pass': pass,
};
}

Proxy copyWith({
String? host,
int? port,
ProxyType? type,
String? user,
String? pass,
}) =>
Proxy(
host: host ?? this.host,
port: port ?? this.port,
type: type ?? this.type,
user: user ?? this.user,
pass: pass ?? this.pass,
);
}

enum ProxyType {
direct,
http,
socks;
}
13 changes: 13 additions & 0 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,19 @@ class SentryOptions {
/// ```
Spotlight spotlight = Spotlight(enabled: false);

/// Configure a proxy to use for SDK API calls.
///
/// On io platforms without native SDKs (dart, linux, windows), this will use
/// an 'IOClient' with inner 'HTTPClient' for http communication.
/// A http proxy will be set in returned for 'HttpClient.findProxy' in the
/// form 'PROXY <your_host>:<your_port>'.
/// When setting 'user' and 'pass', the 'HttpClient.addProxyCredentials'
/// method will be called wit empty 'realm'.
denrase marked this conversation as resolved.
Show resolved Hide resolved
///
/// On Android, the proxy settings are handled by the native SDK.
/// iOS and macOS native SDKs do not support proxy settings.
denrase marked this conversation as resolved.
Show resolved Hide resolved
Proxy? proxy;

SentryOptions({this.dsn, PlatformChecker? checker}) {
if (checker != null) {
platformChecker = checker;
Expand Down
5 changes: 3 additions & 2 deletions dart/lib/src/transport/http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import '../sentry_options.dart';
import '../sentry_envelope.dart';
import 'transport.dart';
import 'rate_limiter.dart';
import '../http_client/client_provider.dart'
if (dart.library.io) '../http_client/io_client_provider.dart';

/// A transport is in charge of sending the event to the Sentry server.
class HttpTransport implements Transport {
Expand All @@ -22,9 +24,8 @@ class HttpTransport implements Transport {

factory HttpTransport(SentryOptions options, RateLimiter rateLimiter) {
if (options.httpClient is NoOpClient) {
options.httpClient = Client();
options.httpClient = getClientProvider().getClient(options);
}

return HttpTransport._(options, rateLimiter);
}

Expand Down
4 changes: 3 additions & 1 deletion dart/lib/src/transport/spotlight_http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'http_transport_request_handler.dart';

import '../../sentry.dart';
import '../noop_client.dart';
import '../http_client/client_provider.dart'
if (dart.library.io) '../http_client/io_client_provider.dart';

/// Spotlight HTTP transport decorator that sends Sentry envelopes to both Sentry and Spotlight.
class SpotlightHttpTransport extends Transport {
Expand All @@ -13,7 +15,7 @@ class SpotlightHttpTransport extends Transport {

factory SpotlightHttpTransport(SentryOptions options, Transport transport) {
if (options.httpClient is NoOpClient) {
options.httpClient = Client();
options.httpClient = getClientProvider().getClient(options);
}
return SpotlightHttpTransport._(options, transport);
}
Expand Down
Loading
Loading