Skip to content

Commit b832e7c

Browse files
committed
remove tombstone-native correlation via processStateSummary
1 parent cd970cb commit b832e7c

File tree

6 files changed

+5
-135
lines changed

6 files changed

+5
-135
lines changed

sentry-android-core/api/sentry-android-core.api

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,10 @@ public final class io/sentry/android/core/NativeEventCollector {
295295
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;)V
296296
public fun collect ()V
297297
public fun deleteNativeEventFile (Lio/sentry/android/core/NativeEventCollector$NativeEventData;)Z
298-
public fun findAndRemoveMatchingNativeEvent (JLjava/lang/String;)Lio/sentry/android/core/NativeEventCollector$NativeEventData;
298+
public fun findAndRemoveMatchingNativeEvent (J)Lio/sentry/android/core/NativeEventCollector$NativeEventData;
299299
}
300300

301301
public final class io/sentry/android/core/NativeEventCollector$NativeEventData {
302-
public fun getCorrelationId ()Ljava/lang/String;
303302
public fun getEnvelope ()Lio/sentry/SentryEnvelope;
304303
public fun getEvent ()Lio/sentry/SentryEvent;
305304
public fun getFile ()Ljava/io/File;
@@ -354,7 +353,6 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
354353
public fun getBeforeViewHierarchyCaptureCallback ()Lio/sentry/android/core/SentryAndroidOptions$BeforeCaptureCallback;
355354
public fun getDebugImagesLoader ()Lio/sentry/android/core/IDebugImagesLoader;
356355
public fun getFrameMetricsCollector ()Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;
357-
public fun getNativeCrashCorrelationId ()Ljava/lang/String;
358356
public fun getNativeSdkName ()Ljava/lang/String;
359357
public fun getNdkHandlerStrategy ()I
360358
public fun getStartupCrashDurationThresholdMillis ()J
@@ -408,7 +406,6 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
408406
public fun setEnableSystemEventBreadcrumbs (Z)V
409407
public fun setEnableSystemEventBreadcrumbsExtras (Z)V
410408
public fun setFrameMetricsCollector (Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V
411-
public fun setNativeCrashCorrelationId (Ljava/lang/String;)V
412409
public fun setNativeHandlerStrategy (Lio/sentry/android/core/NdkHandlerStrategy;)V
413410
public fun setNativeSdkName (Ljava/lang/String;)V
414411
public fun setReportHistoricalAnrs (Z)V

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static io.sentry.android.core.NdkIntegration.SENTRY_NDK_CLASS_NAME;
44

5-
import android.app.ActivityManager;
65
import android.app.Application;
76
import android.content.Context;
87
import android.content.pm.PackageInfo;
@@ -58,10 +57,8 @@
5857
import io.sentry.util.Objects;
5958
import io.sentry.util.thread.NoOpThreadChecker;
6059
import java.io.File;
61-
import java.nio.charset.StandardCharsets;
6260
import java.util.ArrayList;
6361
import java.util.List;
64-
import java.util.UUID;
6562
import org.jetbrains.annotations.NotNull;
6663
import org.jetbrains.annotations.Nullable;
6764
import org.jetbrains.annotations.TestOnly;
@@ -248,11 +245,6 @@ static void initializeIntegrationsAndProcessors(
248245
options.setSocketTagger(AndroidSocketTagger.getInstance());
249246
}
250247

251-
// Set native crash correlation ID before NDK integration is registered
252-
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.R) {
253-
setNativeCrashCorrelationId(context, options);
254-
}
255-
256248
if (options.getPerformanceCollectors().isEmpty()) {
257249
options.addPerformanceCollector(new AndroidMemoryCollector());
258250
options.addPerformanceCollector(new AndroidCpuCollector(options.getLogger()));
@@ -506,33 +498,4 @@ private static void readDefaultOptionValues(
506498
static @NotNull File getCacheDir(final @NotNull Context context) {
507499
return new File(context.getCacheDir(), "sentry");
508500
}
509-
510-
/**
511-
* Sets a native crash correlation ID that can be used to associate native crash events (from
512-
* sentry-native) with tombstone events (from ApplicationExitInfo). The ID is stored via
513-
* ActivityManager.setProcessStateSummary() and passed to the native SDK.
514-
*
515-
* @param context the Application context
516-
* @param options the SentryAndroidOptions
517-
*/
518-
private static void setNativeCrashCorrelationId(
519-
final @NotNull Context context, final @NotNull SentryAndroidOptions options) {
520-
final String correlationId = UUID.randomUUID().toString();
521-
options.setNativeCrashCorrelationId(correlationId);
522-
523-
try {
524-
final ActivityManager am =
525-
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
526-
if (am != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
527-
am.setProcessStateSummary(correlationId.getBytes(StandardCharsets.UTF_8));
528-
options
529-
.getLogger()
530-
.log(SentryLevel.DEBUG, "Native crash correlation ID set: %s", correlationId);
531-
}
532-
} catch (Throwable e) {
533-
options
534-
.getLogger()
535-
.log(SentryLevel.WARNING, "Failed to set process state summary for correlation ID", e);
536-
}
537-
}
538501
}

sentry-android-core/src/main/java/io/sentry/android/core/NativeEventCollector.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,6 @@ public static final class NativeEventData {
7878
public long getTimestampMs() {
7979
return timestampMs;
8080
}
81-
82-
/**
83-
* Extracts the correlation ID from the event's extra data.
84-
*
85-
* @return the correlation ID, or null if not present
86-
*/
87-
public @Nullable String getCorrelationId() {
88-
final @Nullable Object correlationId = event.getExtra("sentry.native.correlation_id");
89-
if (correlationId instanceof String) {
90-
return (String) correlationId;
91-
}
92-
return null;
93-
}
9481
}
9582

9683
/**
@@ -151,36 +138,20 @@ public void collect() {
151138
}
152139

153140
/**
154-
* Finds a native event that matches the given tombstone timestamp or correlation ID. If a match
155-
* is found, it is removed from the internal list so it won't be matched again.
141+
* Finds a native event that matches the given tombstone timestamp. If a match is found, it is
142+
* removed from the internal list so it won't be matched again.
156143
*
157144
* <p>This method will lazily collect native events from the outbox on first call.
158145
*
159146
* @param tombstoneTimestampMs the timestamp from ApplicationExitInfo
160-
* @param correlationId the correlation ID from processStateSummary, or null
161147
* @return the matching native event data, or null if no match found
162148
*/
163149
public @Nullable NativeEventData findAndRemoveMatchingNativeEvent(
164-
final long tombstoneTimestampMs, final @Nullable String correlationId) {
150+
final long tombstoneTimestampMs) {
165151

166152
// Lazily collect on first use (runs on executor thread, not main thread)
167153
collect();
168154

169-
// First, try to match by correlation ID (when sentry-native supports it)
170-
if (correlationId != null) {
171-
for (final NativeEventData nativeEvent : nativeEvents) {
172-
final @Nullable String nativeCorrelationId = nativeEvent.getCorrelationId();
173-
if (correlationId.equals(nativeCorrelationId)) {
174-
options
175-
.getLogger()
176-
.log(SentryLevel.DEBUG, "Matched native event by correlation ID: %s", correlationId);
177-
nativeEvents.remove(nativeEvent);
178-
return nativeEvent;
179-
}
180-
}
181-
}
182-
183-
// Fall back to timestamp-based matching
184155
for (final NativeEventData nativeEvent : nativeEvents) {
185156
final long timeDiff = Math.abs(tombstoneTimestampMs - nativeEvent.getTimestampMs());
186157
if (timeDiff <= TIMESTAMP_TOLERANCE_MS) {

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,6 @@ public final class SentryAndroidOptions extends SentryOptions {
174174
*/
175175
private boolean enableScopeSync = true;
176176

177-
/**
178-
* A correlation ID used to associate native crash events (from sentry-native) with tombstone
179-
* events (from ApplicationExitInfo). This is set via ActivityManager.setProcessStateSummary() and
180-
* passed to the native SDK during initialization.
181-
*/
182-
private @Nullable String nativeCrashCorrelationId;
183-
184177
/**
185178
* Whether to enable automatic trace ID generation. This is mainly used by the Hybrid SDKs to
186179
* control the trace ID generation from the outside.
@@ -614,27 +607,6 @@ public void setEnableScopeSync(boolean enableScopeSync) {
614607
this.enableScopeSync = enableScopeSync;
615608
}
616609

617-
/**
618-
* Returns the correlation ID used to associate native crash events with tombstone events.
619-
*
620-
* @return the correlation ID, or null if not set
621-
*/
622-
@ApiStatus.Internal
623-
public @Nullable String getNativeCrashCorrelationId() {
624-
return nativeCrashCorrelationId;
625-
}
626-
627-
/**
628-
* Sets the correlation ID used to associate native crash events with tombstone events. This is
629-
* typically set automatically during SDK initialization.
630-
*
631-
* @param nativeCrashCorrelationId the correlation ID
632-
*/
633-
@ApiStatus.Internal
634-
public void setNativeCrashCorrelationId(final @Nullable String nativeCrashCorrelationId) {
635-
this.nativeCrashCorrelationId = nativeCrashCorrelationId;
636-
}
637-
638610
public boolean isReportHistoricalAnrs() {
639611
return reportHistoricalAnrs;
640612
}

sentry-android-core/src/main/java/io/sentry/android/core/TombstoneIntegration.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.io.Closeable;
3535
import java.io.IOException;
3636
import java.io.InputStream;
37-
import java.nio.charset.StandardCharsets;
3837
import java.time.Instant;
3938
import java.time.format.DateTimeFormatter;
4039
import java.util.List;
@@ -181,17 +180,9 @@ public boolean shouldReportHistorical() {
181180
final long tombstoneTimestamp = exitInfo.getTimestamp();
182181
event.setTimestamp(DateUtils.getDateTime(tombstoneTimestamp));
183182

184-
// Extract correlation ID from process state summary (if set during previous session)
185-
final @Nullable String correlationId = extractCorrelationId(exitInfo);
186-
if (correlationId != null) {
187-
options
188-
.getLogger()
189-
.log(SentryLevel.DEBUG, "Tombstone correlation ID found: %s", correlationId);
190-
}
191-
192183
// Try to find and remove matching native event from outbox
193184
final @Nullable NativeEventData matchingNativeEvent =
194-
nativeEventCollector.findAndRemoveMatchingNativeEvent(tombstoneTimestamp, correlationId);
185+
nativeEventCollector.findAndRemoveMatchingNativeEvent(tombstoneTimestamp);
195186

196187
if (matchingNativeEvent != null) {
197188
options
@@ -248,24 +239,6 @@ private SentryEvent mergeNativeCrashes(
248239

249240
return nativeEvent;
250241
}
251-
252-
@RequiresApi(api = Build.VERSION_CODES.R)
253-
private @Nullable String extractCorrelationId(final @NotNull ApplicationExitInfo exitInfo) {
254-
try {
255-
final byte[] summary = exitInfo.getProcessStateSummary();
256-
if (summary != null && summary.length > 0) {
257-
return new String(summary, StandardCharsets.UTF_8);
258-
}
259-
} catch (Throwable e) {
260-
options
261-
.getLogger()
262-
.log(
263-
SentryLevel.DEBUG,
264-
"Failed to extract correlation ID from process state summary",
265-
e);
266-
}
267-
return null;
268-
}
269242
}
270243

271244
@ApiStatus.Internal

sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ public static void init(@NotNull final SentryAndroidOptions options) {
7373
ndkOptions.setTracesSampleRate(tracesSampleRate.floatValue());
7474
}
7575

76-
// TODO: Pass correlation ID to native SDK when sentry-native supports it
77-
// final @Nullable String correlationId = options.getNativeCrashCorrelationId();
78-
// if (correlationId != null) {
79-
// ndkOptions.setCorrelationId(correlationId);
80-
// }
81-
8276
//noinspection UnstableApiUsage
8377
io.sentry.ndk.SentryNdk.init(ndkOptions);
8478

0 commit comments

Comments
 (0)