From 59dfb952da243011f513862a25bdaa7298b79e52 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Thu, 18 Mar 2021 14:40:11 +0100 Subject: [PATCH] Fix: set "java" platform to transactions (#1332) --- CHANGELOG.md | 1 + sentry/api/sentry.api | 5 +++-- .../java/io/sentry/MainEventProcessor.java | 2 +- .../main/java/io/sentry/SentryBaseEvent.java | 22 +++++++++++++++++++ .../src/main/java/io/sentry/SentryClient.java | 3 +++ .../src/main/java/io/sentry/SentryEvent.java | 20 ----------------- .../test/java/io/sentry/SentryClientTest.kt | 17 ++++++++++++++ 7 files changed, 47 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6fe5ba3f2..a9259c802c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Feat: Set SDK version on Transactions (#1307) * Fix: Use logger set on SentryOptions in GsonSerializer (#1308) * Fix: Use the bindToScope correctly +* Fix: set "java" platform to transactions #1332 * Feat: Add OkHttp client application interceptor (#1330) # 4.3.0 diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index f62e0e3314..5ac1612056 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -558,6 +558,7 @@ public abstract interface class io/sentry/Sentry$OptionsConfiguration { } public abstract class io/sentry/SentryBaseEvent { + public static final field DEFAULT_PLATFORM Ljava/lang/String; protected field throwable Ljava/lang/Throwable; protected fun ()V protected fun (Lio/sentry/protocol/SentryId;)V @@ -565,6 +566,7 @@ public abstract class io/sentry/SentryBaseEvent { public fun getEnvironment ()Ljava/lang/String; public fun getEventId ()Lio/sentry/protocol/SentryId; public fun getOriginThrowable ()Ljava/lang/Throwable; + public fun getPlatform ()Ljava/lang/String; public fun getRelease ()Ljava/lang/String; public fun getRequest ()Lio/sentry/protocol/Request; public fun getSdk ()Lio/sentry/protocol/SdkVersion; @@ -574,6 +576,7 @@ public abstract class io/sentry/SentryBaseEvent { public fun removeTag (Ljava/lang/String;)V public fun setEnvironment (Ljava/lang/String;)V public fun setEventId (Lio/sentry/protocol/SentryId;)V + public fun setPlatform (Ljava/lang/String;)V public fun setRelease (Ljava/lang/String;)V public fun setRequest (Lio/sentry/protocol/Request;)V public fun setSdk (Lio/sentry/protocol/SdkVersion;)V @@ -662,7 +665,6 @@ public final class io/sentry/SentryEvent : io/sentry/SentryBaseEvent, io/sentry/ public fun getLogger ()Ljava/lang/String; public fun getMessage ()Lio/sentry/protocol/Message; public fun getModule (Ljava/lang/String;)Ljava/lang/String; - public fun getPlatform ()Ljava/lang/String; public fun getServerName ()Ljava/lang/String; public fun getThreads ()Ljava/util/List; public fun getTimestamp ()Ljava/util/Date; @@ -685,7 +687,6 @@ public final class io/sentry/SentryEvent : io/sentry/SentryBaseEvent, io/sentry/ public fun setMessage (Lio/sentry/protocol/Message;)V public fun setModule (Ljava/lang/String;Ljava/lang/String;)V public fun setModules (Ljava/util/Map;)V - public fun setPlatform (Ljava/lang/String;)V public fun setServerName (Ljava/lang/String;)V public fun setThreads (Ljava/util/List;)V public fun setTransaction (Ljava/lang/String;)V diff --git a/sentry/src/main/java/io/sentry/MainEventProcessor.java b/sentry/src/main/java/io/sentry/MainEventProcessor.java index cbc188be3b..7e4b6601bd 100644 --- a/sentry/src/main/java/io/sentry/MainEventProcessor.java +++ b/sentry/src/main/java/io/sentry/MainEventProcessor.java @@ -66,7 +66,7 @@ public final class MainEventProcessor implements EventProcessor { final @NotNull SentryEvent event, final @Nullable Object hint) { if (event.getPlatform() == null) { // this actually means JVM related. - event.setPlatform("java"); + event.setPlatform(SentryBaseEvent.DEFAULT_PLATFORM); } final Throwable throwable = event.getThrowable(); diff --git a/sentry/src/main/java/io/sentry/SentryBaseEvent.java b/sentry/src/main/java/io/sentry/SentryBaseEvent.java index 6ebb11e912..e7e9ecae1f 100644 --- a/sentry/src/main/java/io/sentry/SentryBaseEvent.java +++ b/sentry/src/main/java/io/sentry/SentryBaseEvent.java @@ -16,6 +16,7 @@ * transaction. */ public abstract class SentryBaseEvent { + public static final String DEFAULT_PLATFORM = "java"; /** * Unique identifier of this event. * @@ -60,6 +61,19 @@ public abstract class SentryBaseEvent { */ private String environment; + /** + * Platform identifier of this event (defaults to "other"). + * + *

A string representing the platform the SDK is submitting from. This will be used by the + * Sentry interface to customize various components in the interface, but also to enter or skip + * stacktrace processing. + * + *

Acceptable values are: `as3`, `c`, `cfml`, `cocoa`, `csharp`, `elixir`, `haskell`, `go`, + * `groovy`, `java`, `javascript`, `native`, `node`, `objc`, `other`, `perl`, `php`, `python`, + * `ruby` + */ + private @Nullable String platform; + /** The captured Throwable */ protected transient @Nullable Throwable throwable; @@ -176,4 +190,12 @@ public String getEnvironment() { public void setEnvironment(String environment) { this.environment = environment; } + + public @Nullable String getPlatform() { + return platform; + } + + public void setPlatform(final @Nullable String platform) { + this.platform = platform; + } } diff --git a/sentry/src/main/java/io/sentry/SentryClient.java b/sentry/src/main/java/io/sentry/SentryClient.java index e6c26e7669..66a79a600c 100644 --- a/sentry/src/main/java/io/sentry/SentryClient.java +++ b/sentry/src/main/java/io/sentry/SentryClient.java @@ -401,6 +401,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec private @NotNull SentryTransaction processTransaction( final @NotNull SentryTransaction transaction) { + if (transaction.getPlatform() == null) { + transaction.setPlatform(SentryBaseEvent.DEFAULT_PLATFORM); + } if (transaction.getRelease() == null) { transaction.setRelease(options.getRelease()); } diff --git a/sentry/src/main/java/io/sentry/SentryEvent.java b/sentry/src/main/java/io/sentry/SentryEvent.java index 4d1179f64c..52a1bb0a45 100644 --- a/sentry/src/main/java/io/sentry/SentryEvent.java +++ b/sentry/src/main/java/io/sentry/SentryEvent.java @@ -37,18 +37,6 @@ public final class SentryEvent extends SentryBaseEvent implements IUnknownProper *

This is supposed to be a hostname. */ private String serverName; - /** - * Platform identifier of this event (defaults to "other"). - * - *

A string representing the platform the SDK is submitting from. This will be used by the - * Sentry interface to customize various components in the interface, but also to enter or skip - * stacktrace processing. - * - *

Acceptable values are: `as3`, `c`, `cfml`, `cocoa`, `csharp`, `elixir`, `haskell`, `go`, - * `groovy`, `java`, `javascript`, `native`, `node`, `objc`, `other`, `perl`, `php`, `python`, - * `ruby` - */ - private String platform; /** * Program's distribution identifier. @@ -166,14 +154,6 @@ public void setServerName(String serverName) { this.serverName = serverName; } - public String getPlatform() { - return platform; - } - - public void setPlatform(String platform) { - this.platform = platform; - } - public String getDist() { return dist; } diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index 9e35e212c5..95a4523eba 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -886,6 +886,23 @@ class SentryClientTest { assertEquals(mapOf("tag1" to "value1", "tag2" to "transaction-tag", "tag3" to "value3"), transaction.tags) } + @Test + fun `captured transactions without a platform, have the default platform set`() { + val sut = fixture.getSut() + val transaction = SentryTransaction(SentryTracer(TransactionContext("name", "op"), mock())) + sut.captureTransaction(transaction) + assertEquals("java", transaction.platform) + } + + @Test + fun `captured transactions with a platform, do not get the platform overwritten`() { + val sut = fixture.getSut() + val transaction = SentryTransaction(SentryTracer(TransactionContext("name", "op"), mock())) + transaction.platform = "abc" + sut.captureTransaction(transaction) + assertEquals("abc", transaction.platform) + } + private fun createScope(): Scope { return Scope(SentryOptions()).apply { addBreadcrumb(Breadcrumb().apply {