Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
11 changes: 11 additions & 0 deletions src/Sentry.Bindings.Android/DefaultReplayBreadcrumbConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if __ANDROID__
using Sentry.JavaSdk;

// ReSharper disable once CheckNamespace - match generated code namespace
namespace Sentry.JavaSdk.Android.Replay;

// Add IReplayBreadcrumbConverter interface to DefaultReplayBreadcrumbConverter, to work source generator issue
internal partial class DefaultReplayBreadcrumbConverter : IReplayBreadcrumbConverter
{
}
#endif
2 changes: 1 addition & 1 deletion src/Sentry.Bindings.Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Instead, reference one of the following:

## SDK Developers and Contributors

For .NET SDK contributors, most of the classes in this package are generated automatically.
For .NET SDK contributors, most of the classes in this package are generated automatically. These can be found in the `src/Sentry.Bindings.Android/obj/Debug/{tfm}/generated/src/` folder after building the project.

- Post generation transformations are controlled via various XML files stored in the `/Transforms` directory (see [Java Bindings Metadata documentation](https://learn.microsoft.com/en-gb/previous-versions/xamarin/android/platform/binding-java-library/customizing-bindings/java-bindings-metadata) for details).

Expand Down
58 changes: 55 additions & 3 deletions src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved most of this out to a separate PR as well, since it's just a means to an end to diagnose the problem (not actually part of the change this PR is meant to effect):

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
<TargetFrameworks>$(LatestAndroidTfm);$(PreviousAndroidTfm)</TargetFrameworks>
<SentryAndroidSdkVersion>8.29.0</SentryAndroidSdkVersion>
<SentryAndroidSdkDirectory>$(BaseIntermediateOutputPath)sdks\$(TargetFramework)\Sentry\Android\$(SentryAndroidSdkVersion)\</SentryAndroidSdkDirectory>
<!-- This gets resolved by the DownloadSentryAndroidSdk target -->
<!-- This gets resolved by the DownloadSentryAndroidSdk and ResolveSentryNativeNdkFromLocalMaven targets -->
<SentryNativeNdkVersion></SentryNativeNdkVersion>
<Description>.NET Bindings for the Sentry Android SDK</Description>

<!--
Optional dev override: enable to resolve local maven references
Example:
dotnet build -p:UseLocalSentryMavenRepo=true

To populate MavenLocal from your checkout:
cd $(LocalSentryJavaRepoDir) && ./gradlew publishToMavenLocal
cd $(LocalSentryNativeRepoDir)/ndk && ./gradlew publishToMavenLocal

Note that you may need to check out specific branches/tags to match the version defined in SentryAndroidSdkVersion
and the resulting native ndk version.
-->
<UseLocalSentryMavenRepo>true</UseLocalSentryMavenRepo>
<LocalSentryMavenRepoDir Condition="'$(LocalSentryMavenRepoDir)' == ''">$(HOME)/.m2/repository/</LocalSentryMavenRepoDir>
<LocalSentryJarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry/$(SentryAndroidSdkVersion)/sentry-$(SentryAndroidSdkVersion).jar</LocalSentryJarPath>
<LocalSentryAndroidCoreAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-core/$(SentryAndroidSdkVersion)/sentry-android-core-$(SentryAndroidSdkVersion).aar</LocalSentryAndroidCoreAarPath>
<LocalSentryAndroidNdkAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).aar</LocalSentryAndroidNdkAarPath>
<LocalSentryAndroidReplayAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-replay/$(SentryAndroidSdkVersion)/sentry-android-replay-$(SentryAndroidSdkVersion).aar</LocalSentryAndroidReplayAarPath>
<LocalSentryPomPath>$([System.String]::Copy($(LocalSentryJarPath)).Replace('.jar', '.pom'))</LocalSentryPomPath>
<LocalSentryAndroidCorePomPath>$([System.String]::Copy($(LocalSentryAndroidCoreAarPath)).Replace('.aar', '.pom'))</LocalSentryAndroidCorePomPath>
<LocalSentryAndroidNdkPomPath>$([System.String]::Copy($(LocalSentryAndroidNdkAarPath)).Replace('.aar', '.pom'))</LocalSentryAndroidNdkPomPath>
<LocalSentryAndroidReplayPomPath>$([System.String]::Copy($(LocalSentryAndroidReplayAarPath)).Replace('.aar', '.pom'))</LocalSentryAndroidReplayPomPath>

<!-- Android binding warnings - these are largely unavoidable due to Java interface circular dependencies -->
<!-- Only suppress warnings that are confirmed to be expected/unavoidable -->
<!-- BG8801: Invalid parameter types - caused by circular interface dependencies in Sentry Java SDK -->
Expand Down Expand Up @@ -73,13 +96,25 @@
</ItemGroup>

<!-- Starting with .NET 9 we can detect Java dependencies using POM files and AndroidMavenLibrary references -->
<ItemGroup>
<ItemGroup Condition="'$(UseLocalSentryMavenRepo)' != 'true'">
<AndroidMavenLibrary Include="io.sentry:sentry" Version="$(SentryAndroidSdkVersion)" />
<AndroidMavenLibrary Include="io.sentry:sentry-android-core" Version="$(SentryAndroidSdkVersion)" />
<AndroidMavenLibrary Include="io.sentry:sentry-android-ndk" Version="$(SentryAndroidSdkVersion)" />
<AndroidMavenLibrary Include="io.sentry:sentry-android-replay" Version="$(SentryAndroidSdkVersion)" />
</ItemGroup>

<!-- Resolve Java dependencies from local sentry-java build outputs instead, if appropriate -->
<ItemGroup Condition="'$(UseLocalSentryMavenRepo)' == 'true'">
<AndroidLibrary Include="$(LocalSentryJarPath)" Manifest="$(LocalSentryPomPath)"
JavaArtifact="io.sentry:sentry:$(SentryAndroidSdkVersion)" />
<AndroidLibrary Include="$(LocalSentryAndroidCoreAarPath)" Manifest="$(LocalSentryAndroidCorePomPath)"
JavaArtifact="io.sentry:sentry-android-core:$(SentryAndroidSdkVersion)" />
<AndroidLibrary Include="$(LocalSentryAndroidNdkAarPath)" Manifest="$(LocalSentryAndroidNdkPomPath)"
JavaArtifact="io.sentry:sentry-android-ndk:$(SentryAndroidSdkVersion)" />
<AndroidLibrary Include="$(LocalSentryAndroidReplayAarPath)" Manifest="$(LocalSentryAndroidReplayPomPath)"
JavaArtifact="io.sentry:sentry-android-replay:$(SentryAndroidSdkVersion)" />
</ItemGroup>

<ItemGroup>
<AndroidLibrary Include="..\..\lib\sentry-android-supplemental\bin\sentry-android-supplemental.jar" />
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\arm64-v8a\libsentrysupplemental.so" Abi="arm64-v8a" />
Expand All @@ -88,7 +123,7 @@
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\x86_64\libsentrysupplemental.so" Abi="x86_64" />
</ItemGroup>

<Target Name="DownloadSentryAndroidSdk" BeforeTargets="CollectPackageReferences">
<Target Name="DownloadSentryAndroidSdk" BeforeTargets="CollectPackageReferences" Condition="'$(UseLocalSentryMavenRepo)' != 'true'">
<!-- The native-ndk exists outside of the android-ndk now. We're downloading the POM file to get the version of the native-ndk. -->
<DownloadFile
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).pom"
Expand All @@ -109,5 +144,22 @@
</ItemGroup>
</Target>

<Target Name="ResolveSentryNativeNdkFromLocalMaven" BeforeTargets="CollectPackageReferences" Condition="'$(UseLocalSentryMavenRepo)' == 'true'">
<PropertyGroup>
<_LocalAndroidNdkPom>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).pom</_LocalAndroidNdkPom>
</PropertyGroup>

<XmlPeek
XmlInputPath="$(_LocalAndroidNdkPom)"
Query="//*[local-name()='dependency' and .//*[local-name()='artifactId' and text()='sentry-native-ndk']]/*[local-name()='version']/text()"
Condition="Exists('$(_LocalAndroidNdkPom)')">
<Output TaskParameter="Result" PropertyName="SentryNativeNdkVersion" />
</XmlPeek>

<ItemGroup Condition="'$(SentryNativeNdkVersion)' != ''">
<AndroidMavenLibrary Include="io.sentry:sentry-native-ndk" Version="$(SentryNativeNdkVersion)" />
</ItemGroup>
</Target>

<UsingTask TaskName="XmlPeek" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</Project>
6 changes: 2 additions & 4 deletions src/Sentry.Bindings.Android/Transforms/Metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<attr path="/api/package[@name='io.sentry.android.core.internal.threaddump']" name="managedName">Sentry.JavaSdk.Android.Core.Internal.ThreadDump</attr>
<attr path="/api/package[@name='io.sentry.android.core.internal.util']" name="managedName">Sentry.JavaSdk.Android.Core.Internal.Util</attr>
<attr path="/api/package[@name='io.sentry.android.ndk']" name="managedName">Sentry.JavaSdk.Android.Ndk</attr>
<attr path="/api/package[@name='io.sentry.android.replay']" name="managedName">Sentry.JavaSdk.Android.Replay</attr>
<attr path="/api/package[@name='io.sentry.android.supplemental']" name="managedName">Sentry.JavaSdk.Android.Supplemental</attr>
<attr path="/api/package[@name='io.sentry.cache']" name="managedName">Sentry.JavaSdk.Cache</attr>
<!-- Renaming 'clientreport' to 'clientreports' (plural) as a workaround for typename matching namespace: io.sentry.clientreport.clientreport -->
Expand Down Expand Up @@ -111,7 +112,7 @@
-->
<remove-node path="/api/package[@name='io.sentry']/interface[@name='BackfillingEventProcessor']" />
<remove-node path="/api/package[@name='io.sentry.android.core']/class[@name='AnrV2EventProcessor']" />

<!--
SentryEvent.serialize() expects an parameter which implements IObjectWriter.
JsonObjectWriter implements IObjectWriter in Java, but somehow this is not reflected in the generated binding.
Expand Down Expand Up @@ -162,7 +163,4 @@

<!-- Remove UpdateStatus to avoid CS0108 for conflicting _members fields in nested subclasses -->
<remove-node path="/api/package[@name='io.sentry']/class[@name='UpdateStatus']" />

<!-- error CS0050: Inconsistent accessibility: return type 'INetworkBody' is less accessible than method 'NetworkBody.FromXxx' -->
<remove-node path="/api/package[@name='io.sentry.util.network']/interface[@name='NetworkBody']" />
</metadata>
7 changes: 7 additions & 0 deletions src/Sentry/SentryHttpMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ protected internal override void HandleResponse(HttpResponseMessage response, IS
{"method", method},
{"status_code", ((int) response.StatusCode).ToString()}
};
if (span is not null)
{
// Ensure the breadcrumb can be converted to RRWeb so that it shows up in the network tab in Session Replay.
// See https://github.com/getsentry/sentry-java/blob/94bff8dc0a952ad8c1b6815a9eda5005e41b92c7/sentry-android-replay/src/main/java/io/sentry/android/replay/DefaultReplayBreadcrumbConverter.kt#L195-L199
breadcrumbData["http.start_timestamp"] = span.StartTimestamp.ToUnixTimeMilliseconds().ToString("F0", CultureInfo.InvariantCulture);
breadcrumbData["http.end_timestamp"] = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString("F0", CultureInfo.InvariantCulture);
}
_hub.AddBreadcrumb(string.Empty, "http", "http", breadcrumbData);

// Create events for failed requests
Expand Down
Loading