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

fix invalid profiles when the transaction name is empty #3747

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixes

- fix invalid profiles when the transaction name is empty ([#3747](https://github.com/getsentry/sentry-java/pull/3747))
- Deprecate `enableTracing` option ([#3777](https://github.com/getsentry/sentry-java/pull/3777))
- Vendor `java.util.Random` and replace `java.security.SecureRandom` usages ([#3783](https://github.com/getsentry/sentry-java/pull/3783))
- Fix potential ANRs due to NDK scope sync ([#3754](https://github.com/getsentry/sentry-java/pull/3754))
Expand Down
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
Loading