Skip to content

Commit

Permalink
Fix: set "java" platform to transactions (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Mar 18, 2021
1 parent fa1b8b7 commit 59dfb95
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,15 @@ 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 <init> ()V
protected fun <init> (Lio/sentry/protocol/SentryId;)V
public fun getContexts ()Lio/sentry/protocol/Contexts;
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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/MainEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions sentry/src/main/java/io/sentry/SentryBaseEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* transaction.
*/
public abstract class SentryBaseEvent {
public static final String DEFAULT_PLATFORM = "java";
/**
* Unique identifier of this event.
*
Expand Down Expand Up @@ -60,6 +61,19 @@ public abstract class SentryBaseEvent {
*/
private String environment;

/**
* Platform identifier of this event (defaults to "other").
*
* <p>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.
*
* <p>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;

Expand Down Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
20 changes: 0 additions & 20 deletions sentry/src/main/java/io/sentry/SentryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ public final class SentryEvent extends SentryBaseEvent implements IUnknownProper
* <p>This is supposed to be a hostname.
*/
private String serverName;
/**
* Platform identifier of this event (defaults to "other").
*
* <p>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.
*
* <p>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.
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 59dfb95

Please sign in to comment.