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 all 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
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@
appRunner: () => runApp(MyApp()),
);
```
- Add proxy support ([#2192](https://github.com/getsentry/sentry-dart/pull/2192))
- Configure a `SentryProxy` object and set it on `SentryFlutter.init`
```dart
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://example@sentry.io/add-your-dsn-here';
options.proxy = SentryProxy(
type: SenryProxyType.http,
host: 'localhost',
port: 8080,
);
},
// Init your App.
appRunner: () => runApp(MyApp()),
);
}
```

### Improvements

Expand Down Expand Up @@ -72,7 +93,7 @@ SentryFlutter.init((options) =>
- This allows viewing the correct dart formatted raw stacktrace in the Sentry UI
- Support `ignoredExceptionsForType` ([#2150](https://github.com/getsentry/sentry-dart/pull/2150))
- Filter out exception types by calling `SentryOptions.addExceptionFilterForType(Type exceptionType)`

### 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 @@ -56,3 +56,5 @@ export 'src/sentry_span_operations.dart';
export 'src/utils.dart';
// spotlight debugging
export 'src/spotlight.dart';
// proxy
export 'src/protocol/sentry_proxy.dart';
16 changes: 16 additions & 0 deletions dart/lib/src/http_client/client_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:meta/meta.dart';
import 'package:http/http.dart';

import '../sentry_options.dart';

@internal

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#L6

Added line #L6 was not covered by tests
ClientProvider getClientProvider() {
denrase marked this conversation as resolved.
Show resolved Hide resolved
return ClientProvider();

Check warning on line 8 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#L8

Added line #L8 was not covered by tests
}

@internal
class ClientProvider {
Client getClient(SentryOptions options) {
return Client();
}
}

Check warning on line 16 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#L13-L16

Added lines #L13 - L16 were not covered by tests
67 changes: 67 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,67 @@
import 'dart:io';

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

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

@internal
ClientProvider getClientProvider() {
return IoClientProvider(
() {
return HttpClient();
},
(user, pass) {
return HttpClientBasicCredentials(user, pass);

Check warning on line 19 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#L18-L19

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

@internal
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 == SentryProxyType.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/protocol/sentry_proxy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class SentryProxy {
final SentryProxyType type;
final String? host;
final int? port;
final String? user;
final String? pass;

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

String toPacString() {
String type = 'DIRECT';
switch (this.type) {
case SentryProxyType.direct:
return 'DIRECT';
case SentryProxyType.http:
type = 'PROXY';
break;
case SentryProxyType.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,
};
}

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

enum SentryProxyType {
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 @@ -496,6 +496,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 with empty 'realm'.
///
/// On Android & iOS, the proxy settings are handled by the native SDK.
/// iOS only supports http proxies, while macOS also supports socks.
SentryProxy? 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 '../../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 @@

factory SpotlightHttpTransport(SentryOptions options, Transport transport) {
if (options.httpClient is NoOpClient) {
options.httpClient = Client();
options.httpClient = getClientProvider().getClient(options);

Check warning on line 18 in dart/lib/src/transport/spotlight_http_transport.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/transport/spotlight_http_transport.dart#L18

Added line #L18 was not covered by tests
}
return SpotlightHttpTransport._(options, transport);
}
Expand Down
Loading
Loading