Skip to content

Commit 7a9c931

Browse files
committed
drop event if it cannot be processed to not lose the whole chunk
1 parent bb10259 commit 7a9c931

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

sentry-async-profiler/api/sentry-async-profiler.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public final class io/sentry/asyncprofiler/BuildConfig {
44
}
55

66
public final class io/sentry/asyncprofiler/convert/JfrAsyncProfilerToSentryProfileConverter : io/sentry/asyncprofiler/vendor/asyncprofiler/convert/JfrConverter {
7-
public fun <init> (Lio/sentry/asyncprofiler/vendor/asyncprofiler/jfr/JfrReader;Lio/sentry/asyncprofiler/vendor/asyncprofiler/convert/Arguments;Lio/sentry/SentryStackTraceFactory;)V
7+
public fun <init> (Lio/sentry/asyncprofiler/vendor/asyncprofiler/jfr/JfrReader;Lio/sentry/asyncprofiler/vendor/asyncprofiler/convert/Arguments;Lio/sentry/SentryStackTraceFactory;Lio/sentry/ILogger;)V
88
public static fun convertFromFileStatic (Ljava/nio/file/Path;)Lio/sentry/protocol/profiling/SentryProfile;
99
}
1010

sentry-async-profiler/src/main/java/io/sentry/asyncprofiler/convert/JfrAsyncProfilerToSentryProfileConverter.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.sentry.asyncprofiler.convert;
22

33
import io.sentry.DateUtils;
4+
import io.sentry.ILogger;
45
import io.sentry.Sentry;
6+
import io.sentry.SentryLevel;
57
import io.sentry.SentryStackTraceFactory;
68
import io.sentry.asyncprofiler.vendor.asyncprofiler.convert.Arguments;
79
import io.sentry.asyncprofiler.vendor.asyncprofiler.convert.JfrConverter;
@@ -27,13 +29,18 @@ public final class JfrAsyncProfilerToSentryProfileConverter extends JfrConverter
2729

2830
private final @NotNull SentryProfile sentryProfile = new SentryProfile();
2931
private final @NotNull SentryStackTraceFactory stackTraceFactory;
32+
private final @NotNull ILogger logger;
3033
private final @NotNull Map<SentryStackFrame, Integer> frameDeduplicationMap = new HashMap<>();
3134
private final @NotNull Map<List<Integer>, Integer> stackDeduplicationMap = new HashMap<>();
3235

3336
public JfrAsyncProfilerToSentryProfileConverter(
34-
JfrReader jfr, Arguments args, @NotNull SentryStackTraceFactory stackTraceFactory) {
37+
JfrReader jfr,
38+
Arguments args,
39+
@NotNull SentryStackTraceFactory stackTraceFactory,
40+
@NotNull ILogger logger) {
3541
super(jfr, args);
3642
this.stackTraceFactory = stackTraceFactory;
43+
this.logger = logger;
3744
}
3845

3946
@Override
@@ -60,7 +67,9 @@ protected EventCollector createCollector(Arguments args) {
6067

6168
SentryStackTraceFactory stackTraceFactory =
6269
new SentryStackTraceFactory(Sentry.getGlobalScope().getOptions());
63-
converter = new JfrAsyncProfilerToSentryProfileConverter(jfrReader, args, stackTraceFactory);
70+
ILogger logger = Sentry.getGlobalScope().getOptions().getLogger();
71+
converter =
72+
new JfrAsyncProfilerToSentryProfileConverter(jfrReader, args, stackTraceFactory, logger);
6473
converter.convert();
6574
}
6675

@@ -88,15 +97,19 @@ public ProfileEventVisitor(
8897

8998
@Override
9099
public void visit(Event event, long samples, long value) {
91-
StackTrace stackTrace = jfr.stackTraces.get(event.stackTraceId);
100+
try {
101+
StackTrace stackTrace = jfr.stackTraces.get(event.stackTraceId);
92102
long threadId = resolveThreadId(event.tid);
93103

94-
if (stackTrace != null) {
95-
if (args.threads) {
96-
processThreadMetadata(event, threadId);
97-
}
104+
if (stackTrace != null) {
105+
if (args.threads) {
106+
processThreadMetadata(event, threadId);
107+
}
98108

99-
processSampleWithStack(event, threadId, stackTrace);
109+
processSampleWithStack(event, threadId, stackTrace);
110+
}
111+
} catch (Exception e) {
112+
logger.log(SentryLevel.WARNING, "Failed to process JFR event " + event, e);
100113
}
101114
}
102115

0 commit comments

Comments
 (0)