Skip to content

Commit

Permalink
when the transaction name is empty, the profiles default to "unknown"
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanosiano committed Oct 3, 2024
1 parent 7e57220 commit 4f7660b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ class AndroidTransactionProfilerTest {
verify(mockExecutorService, never()).submit(any<Callable<*>>())
}

@Test
fun `profiling transaction with empty name fallbacks to unknown`() {
val profiler = fixture.getSut(context)
profiler.start()
profiler.bindTransaction(fixture.transaction1)
val profilingTraceData = profiler.onTransactionFinish(fixture.transaction1, null, fixture.options)
assertNotNull(profilingTraceData)
assertEquals("unknown", profilingTraceData.transactionName)
assertEquals("unknown", profilingTraceData.transactions.first().name)
}

@Test
fun `profiler does not throw if traces cannot be written to disk`() {
File(fixture.options.profilingTracesDirPath!!).setWritable(false)
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/ProfilingTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public ProfilingTraceData(

// Transaction info
this.transactions = transactions;
this.transactionName = transactionName;
this.transactionName = transactionName.isEmpty() ? "unknown" : transactionName;
this.durationNs = durationNanos;

// App info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProfilingTransactionData(
@NotNull ITransaction transaction, @NotNull Long startNs, @NotNull Long startCpuMs) {
this.id = transaction.getEventId().toString();
this.traceId = transaction.getSpanContext().getTraceId().toString();
this.name = transaction.getName();
this.name = transaction.getName().isEmpty() ? "unknown" : transaction.getName();
this.relativeStartNs = startNs;
this.relativeStartCpuMs = startCpuMs;
}
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/test/java/io/sentry/JsonSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class JsonSerializerTest {
mapOf(
"trace_id" to "00000000000000000000000000000000",
"relative_cpu_end_ms" to null,
"name" to "",
"name" to "unknown",
"relative_start_ns" to 1,
"relative_end_ns" to null,
"id" to "00000000000000000000000000000000",
Expand All @@ -578,7 +578,7 @@ class JsonSerializerTest {
mapOf(
"trace_id" to "00000000000000000000000000000000",
"relative_cpu_end_ms" to null,
"name" to "",
"name" to "unknown",
"relative_start_ns" to 2,
"relative_end_ns" to null,
"id" to "00000000000000000000000000000000",
Expand Down

0 comments on commit 4f7660b

Please sign in to comment.