-
-
Notifications
You must be signed in to change notification settings - Fork 278
Feat: Sentry Performance for HTTP client #603
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c6e6164
Feat: Sentry Performance for HTTP client
marandaneto e7d0ad1
create transaction for example
marandaneto 2491ba2
review
marandaneto e014acf
fix
marandaneto d6a5652
tests
marandaneto 4a1643d
remove import
marandaneto 7a2c010
fix
marandaneto 19d7a35
docs
marandaneto 47c54ca
new test
marandaneto 798e703
add factory to sentry header
marandaneto 82d9b42
fix
marandaneto 9ebaad7
add missing test
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import 'package:http/http.dart'; | ||
| import '../hub.dart'; | ||
| import '../hub_adapter.dart'; | ||
| import '../protocol.dart'; | ||
|
|
||
| /// A [http](https://pub.dev/packages/http)-package compatible HTTP client | ||
| /// which adds support to Sentry Performance feature. | ||
| /// https://develop.sentry.dev/sdk/performance | ||
| class TracingClient extends BaseClient { | ||
| TracingClient({Client? client, Hub? hub}) | ||
| : _hub = hub ?? HubAdapter(), | ||
| _client = client ?? Client(); | ||
|
|
||
| final Client _client; | ||
| final Hub _hub; | ||
|
|
||
| @override | ||
| Future<StreamedResponse> send(BaseRequest request) async { | ||
| // see https://develop.sentry.dev/sdk/performance/#header-sentry-trace | ||
| final currentSpan = _hub.getSpan(); | ||
| final span = currentSpan?.startChild( | ||
| 'http.client', | ||
| description: '${request.method} ${request.url}', | ||
| ); | ||
|
|
||
| StreamedResponse? response; | ||
| try { | ||
| if (span != null) { | ||
| final traceHeader = span.toSentryTrace(); | ||
| request.headers[traceHeader.name] = traceHeader.value; | ||
| } | ||
|
|
||
| // TODO: tracingOrigins support | ||
|
|
||
| response = await _client.send(request); | ||
| span?.status = SpanStatus.fromHttpStatusCode(response.statusCode); | ||
| } catch (exception) { | ||
| span?.throwable = exception; | ||
| span?.status = SpanStatus.internalError(); | ||
|
|
||
| rethrow; | ||
| } finally { | ||
| await span?.finish(); | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return response; | ||
| } | ||
|
|
||
| @override | ||
| void close() => _client.close(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class InvalidSentryTraceHeaderException implements Exception { | ||
| final String _message; | ||
| InvalidSentryTraceHeaderException(this._message); | ||
|
|
||
| @override | ||
| String toString() => 'Exception: $_message'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| import '../invalid_sentry_trace_header_exception.dart'; | ||
| import '../protocol.dart'; | ||
|
|
||
| /// Represents HTTP header "sentry-trace". | ||
| @immutable | ||
| class SentryTraceHeader { | ||
| static const _traceHeader = 'sentry-trace'; | ||
|
|
||
| final SentryId traceId; | ||
| final SpanId spanId; | ||
| final bool? sampled; | ||
|
|
||
| String get name => _traceHeader; | ||
|
|
||
| String get value { | ||
| if (sampled != null) { | ||
| final sampled = this.sampled! ? '1' : '0'; | ||
| return '$traceId-$spanId-$sampled'; | ||
| } else { | ||
| return '$traceId-$spanId'; | ||
| } | ||
| } | ||
|
|
||
| SentryTraceHeader( | ||
| this.traceId, | ||
| this.spanId, { | ||
| bool? sampled, | ||
| }) : sampled = sampled; | ||
|
|
||
| factory SentryTraceHeader.fromTraceHeader(String header) { | ||
| final parts = header.split('-'); | ||
| bool? sampled; | ||
|
|
||
| if (parts.length < 2) { | ||
| throw InvalidSentryTraceHeaderException('Header: $header is invalid.'); | ||
| } else if (parts.length == 3) { | ||
| sampled = '1' == parts[2]; | ||
| } | ||
|
|
||
| final traceId = SentryId.fromId(parts[0]); | ||
| final spanId = SpanId.fromId(parts[1]); | ||
|
|
||
| return SentryTraceHeader( | ||
| traceId, | ||
| spanId, | ||
| sampled: sampled, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.