Skip to content

Commit 9bcd4ea

Browse files
committed
use profileChunk.platform to decide how to deal with the chunk instead of file extension
1 parent 55df61c commit 9bcd4ea

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

sentry/src/main/java/io/sentry/SentryEnvelopeItem.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private static void ensureAttachmentSizeLimit(
295295
traceFile.getName()));
296296
}
297297

298-
if (traceFile.getName().endsWith(".jfr")) {
298+
if (profileChunk.getPlatform().equals("java")) {
299299
final IProfileConverter profileConverter =
300300
ProfilingServiceLoader.loadProfileConverter();
301301
if (profileConverter != null) {
@@ -307,7 +307,6 @@ private static void ensureAttachmentSizeLimit(
307307
throw new SentryEnvelopeException("Profile conversion failed");
308308
}
309309
}
310-
// If no converter is available, JFR profile conversion is skipped
311310
} else {
312311
// The payload of the profile item is a json including the trace file encoded with
313312
// base64

sentry/src/test/java/io/sentry/SentryEnvelopeItemTest.kt

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ class SentryEnvelopeItemTest {
434434
@Test
435435
fun `fromProfilingTrace with unreadable file throws`() {
436436
val file = File(fixture.pathname)
437-
val profilingTraceData = mock<ProfilingTraceData> { whenever(it.traceFile).thenReturn(file) }
437+
val profilingTraceData =
438+
mock<ProfilingTraceData> {
439+
whenever(it.traceFile).thenReturn(file)
440+
whenever(it.platform).thenReturn("android")
441+
}
438442
file.writeBytes(fixture.bytes)
439443
file.setReadable(false)
440444
assertFailsWith<IOException>(
@@ -492,7 +496,11 @@ class SentryEnvelopeItemTest {
492496
@Test
493497
fun `fromProfileChunk saves file as Base64`() {
494498
val file = File(fixture.pathname)
495-
val profileChunk = mock<ProfileChunk> { whenever(it.traceFile).thenReturn(file) }
499+
val profileChunk =
500+
mock<ProfileChunk> {
501+
whenever(it.traceFile).thenReturn(file)
502+
whenever(it.platform).thenReturn("android")
503+
}
496504

497505
file.writeBytes(fixture.bytes)
498506
val chunk = SentryEnvelopeItem.fromProfileChunk(profileChunk, mock()).data
@@ -503,7 +511,11 @@ class SentryEnvelopeItemTest {
503511
@Test
504512
fun `fromProfileChunk deletes file only after reading data`() {
505513
val file = File(fixture.pathname)
506-
val profileChunk = mock<ProfileChunk> { whenever(it.traceFile).thenReturn(file) }
514+
val profileChunk =
515+
mock<ProfileChunk> {
516+
whenever(it.traceFile).thenReturn(file)
517+
whenever(it.platform).thenReturn("android")
518+
}
507519

508520
file.writeBytes(fixture.bytes)
509521
assert(file.exists())
@@ -516,7 +528,11 @@ class SentryEnvelopeItemTest {
516528
@Test
517529
fun `fromProfileChunk with invalid file throws`() {
518530
val file = File(fixture.pathname)
519-
val profileChunk = mock<ProfileChunk> { whenever(it.traceFile).thenReturn(file) }
531+
val profileChunk =
532+
mock<ProfileChunk> {
533+
whenever(it.traceFile).thenReturn(file)
534+
whenever(it.platform).thenReturn("android")
535+
}
520536

521537
assertFailsWith<SentryEnvelopeException>(
522538
"Dropping profiling trace data, because the file ${file.path} doesn't exists"
@@ -528,7 +544,11 @@ class SentryEnvelopeItemTest {
528544
@Test
529545
fun `fromProfileChunk with unreadable file throws`() {
530546
val file = File(fixture.pathname)
531-
val profileChunk = mock<ProfileChunk> { whenever(it.traceFile).thenReturn(file) }
547+
val profileChunk =
548+
mock<ProfileChunk> {
549+
whenever(it.traceFile).thenReturn(file)
550+
whenever(it.platform).thenReturn("android")
551+
}
532552
file.writeBytes(fixture.bytes)
533553
file.setReadable(false)
534554
assertFailsWith<IOException>(
@@ -542,7 +562,11 @@ class SentryEnvelopeItemTest {
542562
fun `fromProfileChunk with empty file throws`() {
543563
val file = File(fixture.pathname)
544564
file.writeBytes(ByteArray(0))
545-
val profileChunk = mock<ProfileChunk> { whenever(it.traceFile).thenReturn(file) }
565+
val profileChunk =
566+
mock<ProfileChunk> {
567+
whenever(it.traceFile).thenReturn(file)
568+
whenever(it.platform).thenReturn("android")
569+
}
546570

547571
val chunk = SentryEnvelopeItem.fromProfileChunk(profileChunk, mock())
548572
assertFailsWith<SentryEnvelopeException>("Profiling trace file is empty") { chunk.data }
@@ -553,7 +577,11 @@ class SentryEnvelopeItemTest {
553577
val file = File(fixture.pathname)
554578
val maxSize = 50 * 1024 * 1024 // 50MB
555579
file.writeBytes(ByteArray((maxSize + 1)) { 0 })
556-
val profileChunk = mock<ProfileChunk> { whenever(it.traceFile).thenReturn(file) }
580+
val profileChunk =
581+
mock<ProfileChunk> {
582+
whenever(it.traceFile).thenReturn(file)
583+
whenever(it.platform).thenReturn("android")
584+
}
557585

558586
val exception =
559587
assertFailsWith<IOException> {

0 commit comments

Comments
 (0)