-
-
Notifications
You must be signed in to change notification settings - Fork 229
feat: Network calls for Session Replay on Android #4860
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
Open
jamescrosswell
wants to merge
22
commits into
main
Choose a base branch
from
replay-network-spans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0289e93
Initial commit
jamescrosswell 588beb3
.
jamescrosswell 31fd5a0
Format code
getsentry-bot 37254e4
Allow building against local instance of Sentry Java SDK
jamescrosswell 79e9225
Fixed local maven references
jamescrosswell cabaa59
Fix issues building against local maven repository
jamescrosswell 4cdf36c
Remove unecessary assignment of default converter
jamescrosswell d05cde3
Format code
getsentry-bot 0b6c66c
Adding sample code temporarily
jamescrosswell 96e9e26
Added custom breadcrumb converter to deal with the conversion between…
jamescrosswell c3a3889
Remove unecessary changes refactored to other PRs
jamescrosswell 32b1b26
Remove changes refactored to #4873
jamescrosswell a40a7a0
Consolidate constants
jamescrosswell 85d47f7
message handler tests
jamescrosswell e51db44
fixed test
jamescrosswell 2c847fe
Added DotnetReplayBreadcrumbConverterTests
jamescrosswell 6da450a
changelog
jamescrosswell e7b460b
Merge remote-tracking branch 'origin/main' into replay-network-spans
jamescrosswell 4abdbec
Remove unintended change to samples
jamescrosswell d631418
Merge remote-tracking branch 'origin/main' into replay-network-spans
jamescrosswell 0f2f114
Fix sample app so it can be run in Rider
jamescrosswell 550a5c4
Review feedback
jamescrosswell 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
Some comments aren't visible on the classic Files Changed page.
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
60 changes: 60 additions & 0 deletions
60
src/Sentry/Platforms/Android/DotnetReplayBreadcrumbConverter.cs
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,60 @@ | ||
| using Sentry.JavaSdk; | ||
| using Sentry.JavaSdk.Android.Replay; | ||
|
|
||
| namespace Sentry.Android; | ||
|
|
||
| internal class DotnetReplayBreadcrumbConverter(Sentry.JavaSdk.SentryOptions options) | ||
| : DefaultReplayBreadcrumbConverter(options), IReplayBreadcrumbConverter | ||
| { | ||
| private const string HttpCategory = "http"; | ||
|
|
||
| public override global::IO.Sentry.Rrweb.RRWebEvent? Convert(Sentry.JavaSdk.Breadcrumb breadcrumb) | ||
| { | ||
| // The Java SDK automatically converts breadcrumbs for outgoing http requests into performance spans | ||
| // that show in the Network tab of session replays... however, it expects certain data to be stored in a | ||
| // specific format in the breadcrumb.data. It needs values for httpStartTimestamp and httpEndTimestamp | ||
| // stored as Double or Long representations of timestamps (milliseconds since epoch). | ||
| // .NET breadcrumb data is always stored as strings, so we have to convert these to numeric values here. | ||
| try | ||
| { | ||
| if (breadcrumb is { Category: HttpCategory, Data: { } data }) | ||
| { | ||
| NormalizeTimestampField(data, SentryHttpMessageHandler.HttpStartTimestampKey); | ||
| NormalizeTimestampField(data, SentryHttpMessageHandler.HttpEndTimestampKey); | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // Best-effort: never fail conversion because of parsing issues... we may be parsing breadcrumbs that don't | ||
| // originate from the .NET SDK. | ||
| } | ||
|
|
||
| return base.Convert(breadcrumb); | ||
| } | ||
|
|
||
| private static void NormalizeTimestampField(IDictionary<string, Java.Lang.Object> data, string key) | ||
| { | ||
| if (!data.TryGetValue(key, out var value) || value is Java.Lang.Number) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var str = (value as Java.Lang.String)?.ToString() ?? value.ToString(); | ||
| if (string.IsNullOrWhiteSpace(str)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (long.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asLong)) | ||
| { | ||
| data[key] = Java.Lang.Long.ValueOf(asLong); | ||
| return; | ||
| } | ||
|
|
||
| if (double.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out var asDouble)) | ||
| { | ||
| // Preserve type as Double; Java converter divides by 1000.0. | ||
| data[key] = Java.Lang.Double.ValueOf(asDouble); | ||
| } | ||
| } | ||
| } | ||
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
38 changes: 38 additions & 0 deletions
38
test/Sentry.Tests/Platforms/Android/DotnetReplayBreadcrumbConverterTests.cs
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,38 @@ | ||
| #if ANDROID | ||
| using Sentry.Android; | ||
|
|
||
| namespace Sentry.Tests.Platforms.Android; | ||
|
|
||
| public class DotnetReplayBreadcrumbConverterTests | ||
| { | ||
| [Fact] | ||
| public void Convert_HttpBreadcrumbWithStringTimestamps_ConvertsToNumeric() | ||
| { | ||
| // Arrange | ||
| var options = new Sentry.JavaSdk.SentryOptions(); | ||
| var converter = new DotnetReplayBreadcrumbConverter(options); | ||
| var breadcrumb = new Sentry.JavaSdk.Breadcrumb | ||
| { | ||
| Category = "http", | ||
| Data = | ||
| { | ||
| { "url", "https://example.com" }, | ||
| { SentryHttpMessageHandler.HttpStartTimestampKey, "1625079600000" }, | ||
| { SentryHttpMessageHandler.HttpEndTimestampKey, "1625079660000" } | ||
| } | ||
| }; | ||
|
|
||
| // Act | ||
| var rrwebEvent = converter.Convert(breadcrumb); | ||
|
|
||
| // Assert | ||
| rrwebEvent.Should().BeOfType<IO.Sentry.Rrweb.RRWebSpanEvent>(); | ||
| var rrWebSpanEvent = rrwebEvent as IO.Sentry.Rrweb.RRWebSpanEvent; | ||
| Assert.NotNull(rrWebSpanEvent); | ||
| // Note the converter divides by 1000 to get ms. | ||
| // See https://github.com/getsentry/sentry-java/blob/94bff8dc0a952ad8c1b6815a9eda5005e41b92c7/sentry-android-replay/src/main/java/io/sentry/android/replay/DefaultReplayBreadcrumbConverter.kt#L215-L228 | ||
| rrWebSpanEvent.StartTimestamp.Should().Be(1625079600L); | ||
| rrWebSpanEvent.EndTimestamp.Should().Be(1625079660L); | ||
Flash0ver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| #endif | ||
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.