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

Enable tracing in the Android/iOS SDKs by default #4032

Open
Qonstrukt opened this issue Mar 12, 2025 · 8 comments
Open

Enable tracing in the Android/iOS SDKs by default #4032

Qonstrukt opened this issue Mar 12, 2025 · 8 comments
Labels

Comments

@Qonstrukt
Copy link

Package

Sentry

.NET Flavor

.NET

.NET Version

9.0.2

OS

iOS

SDK Version

5.3.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Install Sentry NuGet package
  2. Initialise Sentry with TracesSampleRate set:
SentrySdk.Init(options =>
{
	options.Dsn = "<masked>";
	options.IsGlobalModeEnabled = true;
				
#if DEBUG
	options.Debug = true;
	options.SampleRate = 1.0F;
	options.TracesSampleRate = 1.0F;
	options.ProfilesSampleRate = 1.0F;
#else
	options.SampleRate = 0.5F;
	options.TracesSampleRate = 0.5F;
	options.ProfilesSampleRate = 1.0F
#endif
});

Expected Result

I expect traces to be collected.

Actual Result

Traces aren't enabled, because isTracingEnabled is disabled apparently as the logs say:

[Sentry] [debug] [SentrySDK:209] Starting SDK...
[Sentry] [debug] [SentryFileManager:709] SentryFileManager.cachePath: /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches
[Sentry] [debug] [SentryFileManager:50] No file to delete at /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/events
[Sentry] [debug] [SentryHttpTransport:282] sendAllCachedEnvelopes start.
[Sentry] [debug] [SentryHttpTransport:305] No envelopes left to send.
[Sentry] [debug] [SentryReachability:178] Adding observer: <SentryHttpTransport: 0x600002a6e840>
[Sentry] [debug] [SentryReachability:180] Synchronized to add observer: <SentryHttpTransport: 0x600002a6e840>
[Sentry] [debug] [SentryReachability:210] registering callback for reachability ref <SCNetworkReachability 0x106313520 [0x1e3a77680]> {name = sentry.io}
[Sentry] [debug] [SentryFileManager:541] Moving state /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/app.state to previous /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/previous.app.state.
[Sentry] [debug] [SentryFileManager:129] Dispatched deletion of old envelopes from <SentryFileManager: 0x60000330c640>
[Sentry] [debug] [SentryFileManager:50] No file to delete at /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/previous.app.state
[Sentry] [debug] [SentryFileManager:541] Moving state /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/breadcrumbs.1.state to previous /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/previous.breadcrumbs.1.state.
[Sentry] [debug] [SentryFileManager:50] No file to delete at /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/previous.breadcrumbs.1.state
[Sentry] [debug] [SentryFileManager:541] Moving state /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/breadcrumbs.2.state to previous /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/previous.breadcrumbs.2.state.
[Sentry] [debug] [SentryFileManager:50] No file to delete at /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/previous.breadcrumbs.2.state
[Sentry] [debug] [SentrySDK:230] Dispatching init work required to run on main thread.
[Sentry] [debug] [SentrySDK:232] SDK main thread init started...
[Sentry] [debug] [SentryFileManager:234] Ignoring non directory when deleting old envelopes at path: /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/async.log
[Sentry] [info] [SentryFileManager:292] Returning empty files list, as folder doesn't exist at path: (null)
[Sentry] [debug] [SentryReachability:137] SentryConnectivityCallback called with target: <SCNetworkReachability 0x106313520 [0x1e3a77680]> {name = sentry.io (complete, 35.186.247.156), flags = 0x00000002, if_index = 15}; flags: 2
[Sentry] [debug] [SentryReachability:102] Entered synchronized region of SentryConnectivityCallback with flags: 2
[Sentry] [debug] [SentryReachability:118] Notifying observers...
[Sentry] [debug] [SentryReachability:120] Notifying <SentryHttpTransport: 0x600002a6e840>
[Sentry] [debug] [SentryHttpTransport:109] Internet connection is back.
[Sentry] [debug] [SentryHttpTransport:282] sendAllCachedEnvelopes start.
[Sentry] [debug] [SentryHttpTransport:305] No envelopes left to send.
[Sentry] [debug] [SentryReachability:124] Finished notifying observers.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentrySessionReplayIntegration because sessionReplaySettings is disabled.
[Sentry] [debug] [SentryFileManager:709] SentryFileManager.cachePath: /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches
[Sentry] [debug] [SentryFileManager:50] No file to delete at /Users/stefan/Library/Developer/CoreSimulator/Devices/CF1555A0-FB73-4DB3-8A2C-C8F46A26EB75/data/Containers/Data/Application/789A0575-C6F7-4FE3-8028-6AE8102B4562/Library/Caches/io.sentry/9161f10d96c231adda6fc95de91094fbf232cb42/events
[Sentry] [debug] [SentryCrashMonitor_NSException:126] Backing up original handler.
[Sentry] [debug] [SentryCrashMonitor_NSException:129] Setting new handler.
[Sentry] [info] [SentryCrash:310] Sending 0 crash reports
[Sentry] [debug] [SentryCrash:314] Process finished with completion: 1
[Sentry] [debug] [SentryCrashInstallationReporter:46] Sent 0 crash report(s)
[Sentry] [debug] [SentrySDK:479] Integration installed: SentryCrashIntegration
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryAppStartTrackingIntegration because isTracingEnabled is disabled.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryFramesTrackingIntegration because isTracingEnabled is disabled.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryPerformanceTrackingIntegration because isTracingEnabled is disabled.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryScreenshotIntegration because attachScreenshot is disabled.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryUIEventTrackingIntegration because enableUserInteractionTracing is disabled.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryViewHierarchyIntegration because attachViewHierarchy is disabled.
[Sentry] [debug] [SentryBaseIntegration:30] Not going to enable SentryWatchdogTerminationTrackingIntegration because enableWatchdogTerminationTracking is disabled.
[Sentry] [debug] [SentryFramesTracker:124] Resetting profiling GPU timeseries data.
[Sentry] [debug] [SentryFramesTracker:88] Initialized frame tracker <SentryFramesTracker: 0x600002c7fe00>
[Sentry] [debug] [SentrySDK:479] Integration installed: SentryANRTrackingIntegration

This is happening for both Android and iOS. I initialise Sentry from a shared Application class that gets called from FinishedLaunching on iOS and from the Application's OnCreate on Android.

@jamescrosswell
Copy link
Collaborator

Thanks @Qonstrukt - I think I see what's going on here. It's not affecting all transactions/spans. I can do something like this in C#, for example, and the traces come through:

    private void OnCounterClicked(object sender, EventArgs e)
    {
        var transaction = SentrySdk.StartTransaction("Counter", "transaction");

        Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();

        transaction.Finish();
    }

However in your case there are some traces that should be created by the Cocoa/Java SDK on ios/android, which are not being created. I'm not actually sure how you got the Cocoa/Java SDK to do that with the options that you showed above... I'd expect something like this would be required to get this to happen:

#if ANDROID
                options.Native.EnableUserInteractionTracing = true;
                options.Native.EnableAutoActivityLifecycleTracing = true;
                options.Native.EnableActivityLifecycleTracingAutoFinish = true;
#elif IOS
                options.Native.EnableUserInteractionTracing = true;
                options.Native.EnableAutoPerformanceTracing = true;
                options.Native.EnableCoreDataTracing = true;
                options.Native.EnableFileIOTracing = true;
                options.Native.EnableUIViewControllerTracing = true;
#endif

With those options enabled, I think the native SDKs might try to instrument spans for various events and it might fail with the error message you described. The solution is to enable tracing in the native SDKs as well:

#if ANDROID || IOS
                options.Native.EnableTracing = true;
#endif

Explanation / Follow up action

We removed the SentryOptions.EnableTracing from the options in the dotnet SDK in the 5.0 release, since it's redundant/implicit. Instead, you can enable tracing by either assigning a TracesSampler or setting the TracesSampleRate to a non zero value.

Until this has been removed from the Cocoa and Java SDKs, however, we should probably still set EnableTracing in these SDKs explicitly based on whatever the implicit value is in the .NET SDK. That way you wouldn't have to set this explicitly yourself (as I've suggested above). We'll put that change in place but you should be able to set it explicitly on the native options as a workaround, in the meantime.

@jamescrosswell
Copy link
Collaborator

@bruno-garcia / @vaind it looks like maybe this was done intentionally?

// These options we have behind feature flags
if (options is { IsPerformanceMonitoringEnabled: true, Native.EnableTracing: true })
{

Do we want instrumentation that gets added by the Native SDKs to be disabled unless people enable this explicitly (and separately from enabling tracing in the managed SDK)?

@Qonstrukt
Copy link
Author

Qonstrukt commented Mar 13, 2025

Thanks for looking into it @jamescrosswell!

These options should be enabled by default right?

#if ANDROID
                options.Native.EnableUserInteractionTracing = true;
                options.Native.EnableAutoActivityLifecycleTracing = true;
                options.Native.EnableActivityLifecycleTracingAutoFinish = true;
#elif IOS
                options.Native.EnableUserInteractionTracing = true;
                options.Native.EnableAutoPerformanceTracing = true;
                options.Native.EnableCoreDataTracing = true;
                options.Native.EnableFileIOTracing = true;
                options.Native.EnableUIViewControllerTracing = true;
#endif

This actually solves my issue:

#if ANDROID || IOS
                options.Native.EnableTracing = true;
#endif

Following the documentation, this shouldn't of course be necessary, but good that I have a solution for now. 😊

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 13, 2025
@vaind
Copy link
Collaborator

vaind commented Mar 13, 2025

@bruno-garcia / @vaind it looks like maybe this was done intentionally?

sentry-dotnet/src/Sentry/Platforms/Cocoa/SentrySdk.cs

Lines 70 to 72 in b330e67

// These options we have behind feature flags
if (options is { IsPerformanceMonitoringEnabled: true, Native.EnableTracing: true })
{
Do we want instrumentation that gets added by the Native SDKs to be disabled unless people enable this explicitly (and separately from enabling tracing in the managed SDK)?

Sorry @jamescrosswell I actually don't know much about this part. I show up in git blame just because of auto-format while saving the file https://github.com/getsentry/sentry-dotnet/pull/2930/files#diff-ae79de5791c2ea5b937c18e2af1a8af1e131f8762578c0996937795300c22445R76

Maybe consider checking how native implementations handle this config?

@jamescrosswell
Copy link
Collaborator

These options should be enabled by default right?

Some of them are and some of them aren't:

/// <summary>
/// When enabled, the SDK tracks performance for <see cref="UIViewController"/> subclasses.
/// The default value is <c>true</c> (enabled).
/// </summary>
/// <remarks>
/// See https://docs.sentry.io/platforms/apple/performance/instrumentation/automatic-instrumentation/#uiviewcontroller-instrumentation
/// </remarks>
public bool EnableUIViewControllerTracing { get; set; } = true;
/// <summary>
/// When enabled, the SDK creates transactions for UI events like buttons clicks, switch toggles,
/// and other UI elements that uses <see cref="UIControl.SendAction(Selector, NSObject?, UIEvent?)"/>.
/// The default value is <c>false</c> (disabled).
/// </summary>
/// <remarks>
/// See https://docs.sentry.io/platforms/apple/performance/instrumentation/automatic-instrumentation/#user-interaction-instrumentation
/// </remarks>
public bool EnableUserInteractionTracing { get; set; } = false;

Following the documentation, this shouldn't of course be necessary, but good that I have a solution for now.

Where did you see this in the docs? Whatever we decide should be happening functionally, the docs need to match what the software is doing.

@jamescrosswell
Copy link
Collaborator

Sorry @jamescrosswell I actually don't know much about this part. I show up in git blame just because of auto-format while saving the file

OK thanks. I see originally the logic was added here:

It guess it was just a design decision Matt made.

I'll check to see what they're doing in the Flutter SDK, since they have a similar wrapper around native mobile SDKs.

@Qonstrukt
Copy link
Author

Qonstrukt commented Mar 14, 2025

Where did you see this in the docs? Whatever we decide should be happening functionally, the docs need to match what the software is doing.

This iOS docs mention this example where only tracesSampleRate is set:
https://docs.sentry.io/platforms/apple/tracing/#configure

The .NET docs mention something similar:
https://docs.sentry.io/platforms/dotnet/tracing/#configure

The options section explains it a bit more explicitly:

tracesSampleRate
A number between 0 and 1, controlling the percentage chance a given transaction will be sent to Sentry. (0 represents 0% while 1 represents 100%.) Applies equally to all transactions created in the app. Either this or tracesSampler must be defined to enable tracing.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 14, 2025
@jamescrosswell
Copy link
Collaborator

@Qonstrukt this topic is a bit nuanced. The setting you cite from the docs is a very high level setting that determines, from all transactions (those created by you manually or those automatically created by one of the Sentry SDKs or some third party library), what percentage should be captured and sent to Sentry.

Independently of that, there are various ways to enable (or disable) automatic trace creation either by Sentry or by third party libraries.

I checked how other SDKs are doing this and this was the reply:

we don't synchronize enabling tracing between flutter and the native mobile sdks since there's the risk of double instrumentation with the auto instrumented stuff from native mobile sdks (e.g app starts).
Generally we leave it to the user to enable it with options.autoInitializeSdk = false and then they initialize the native sdk with their own options and can enable tracing there if they want

For MAUI apps in particular, the .NET SDK doesn't yet automatically create any traces (yet - this is on the radar). So presently we could probably default to enabling tracing for the iOS SDK. Once the .NET SDK starts to collect traces itself though, we might run the same risk of double instrumentation. We can cross that bridge when we come to it though, I think.

@jamescrosswell jamescrosswell changed the title Tracing not working in mobile Android/iOS project Enable tracing in the Android/iOS SDKs by default Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Status: No status
Development

No branches or pull requests

3 participants