From 296280e9b57548b6d9a586d66bbbeab84a8cce98 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Thu, 21 Jan 2021 12:35:13 +0100 Subject: [PATCH 1/2] Improve Kotlin property access in Performance API. --- sentry/api/sentry.api | 14 ++++++++++- sentry/src/main/java/io/sentry/ISpan.java | 24 +++++++++++++++++++ .../src/main/java/io/sentry/ITransaction.java | 16 ++++++------- sentry/src/main/java/io/sentry/NoOpSpan.java | 15 ++++++++++++ .../main/java/io/sentry/NoOpTransaction.java | 15 ++++++++++++ .../java/io/sentry/SentryTransaction.java | 15 ++++++++++-- sentry/src/test/java/io/sentry/ScopeTest.kt | 2 +- .../java/io/sentry/SentryTransactionTest.kt | 8 +++---- 8 files changed, 93 insertions(+), 16 deletions(-) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 5b9c617553..84d977e7c3 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -285,7 +285,10 @@ public abstract interface class io/sentry/ISerializer { public abstract interface class io/sentry/ISpan { public abstract fun finish ()V public abstract fun finish (Lio/sentry/SpanStatus;)V + public abstract fun getDescription ()Ljava/lang/String; + public abstract fun getOperation ()Ljava/lang/String; public abstract fun getSpanContext ()Lio/sentry/SpanContext; + public abstract fun getStatus ()Lio/sentry/SpanStatus; public abstract fun getThrowable ()Ljava/lang/Throwable; public abstract fun setDescription (Ljava/lang/String;)V public abstract fun setOperation (Ljava/lang/String;)V @@ -299,9 +302,9 @@ public abstract interface class io/sentry/ISpan { public abstract interface class io/sentry/ITransaction : io/sentry/ISpan { public abstract fun getContexts ()Lio/sentry/protocol/Contexts; - public abstract fun getDescription ()Ljava/lang/String; public abstract fun getEventId ()Lio/sentry/protocol/SentryId; public abstract fun getLatestActiveSpan ()Lio/sentry/Span; + public abstract fun getName ()Ljava/lang/String; public abstract fun getRequest ()Lio/sentry/protocol/Request; public abstract fun getSpans ()Ljava/util/List; public abstract fun getTransaction ()Ljava/lang/String; @@ -347,8 +350,11 @@ public final class io/sentry/NoOpLogger : io/sentry/ILogger { public final class io/sentry/NoOpSpan : io/sentry/ISpan { public fun finish ()V public fun finish (Lio/sentry/SpanStatus;)V + public fun getDescription ()Ljava/lang/String; public static fun getInstance ()Lio/sentry/NoOpSpan; + public fun getOperation ()Ljava/lang/String; public fun getSpanContext ()Lio/sentry/SpanContext; + public fun getStatus ()Lio/sentry/SpanStatus; public fun getThrowable ()Ljava/lang/Throwable; public fun setDescription (Ljava/lang/String;)V public fun setOperation (Ljava/lang/String;)V @@ -368,9 +374,12 @@ public final class io/sentry/NoOpTransaction : io/sentry/ITransaction { public fun getEventId ()Lio/sentry/protocol/SentryId; public static fun getInstance ()Lio/sentry/NoOpTransaction; public fun getLatestActiveSpan ()Lio/sentry/Span; + public fun getName ()Ljava/lang/String; + public fun getOperation ()Ljava/lang/String; public fun getRequest ()Lio/sentry/protocol/Request; public fun getSpanContext ()Lio/sentry/SpanContext; public fun getSpans ()Ljava/util/List; + public fun getStatus ()Lio/sentry/SpanStatus; public fun getThrowable ()Ljava/lang/Throwable; public fun getTransaction ()Ljava/lang/String; public fun isSampled ()Ljava/lang/Boolean; @@ -833,8 +842,11 @@ public final class io/sentry/SentryTransaction : io/sentry/SentryBaseEvent, io/s public fun finish (Lio/sentry/SpanStatus;)V public fun getDescription ()Ljava/lang/String; public fun getLatestActiveSpan ()Lio/sentry/Span; + public fun getName ()Ljava/lang/String; + public fun getOperation ()Ljava/lang/String; public fun getSpanContext ()Lio/sentry/SpanContext; public fun getSpans ()Ljava/util/List; + public fun getStatus ()Lio/sentry/SpanStatus; public fun getTransaction ()Ljava/lang/String; public fun isSampled ()Ljava/lang/Boolean; public fun setDescription (Ljava/lang/String;)V diff --git a/sentry/src/main/java/io/sentry/ISpan.java b/sentry/src/main/java/io/sentry/ISpan.java index 39b7dc0861..230ba66566 100644 --- a/sentry/src/main/java/io/sentry/ISpan.java +++ b/sentry/src/main/java/io/sentry/ISpan.java @@ -49,6 +49,14 @@ public interface ISpan { */ void setOperation(@Nullable String operation); + /** + * Returns the span operation. + * + * @return the operation + */ + @Nullable + String getOperation(); + /** * Sets span description. * @@ -56,6 +64,14 @@ public interface ISpan { */ void setDescription(@Nullable String description); + /** + * Returns the span description. + * + * @return the description + */ + @Nullable + String getDescription(); + /** * Sets span status. * @@ -63,6 +79,14 @@ public interface ISpan { */ void setStatus(@Nullable SpanStatus status); + /** + * Returns the span status + * + * @return the status + */ + @Nullable + SpanStatus getStatus(); + /** * Sets the throwable that was thrown during the execution of the span. * diff --git a/sentry/src/main/java/io/sentry/ITransaction.java b/sentry/src/main/java/io/sentry/ITransaction.java index ddfbab8fea..641cfa6fad 100644 --- a/sentry/src/main/java/io/sentry/ITransaction.java +++ b/sentry/src/main/java/io/sentry/ITransaction.java @@ -18,6 +18,14 @@ public interface ITransaction extends ISpan { */ void setName(@NotNull String name); + /** + * Returns transaction name. + * + * @return transaction name + */ + @NotNull + String getName(); + /** * Attaches request information to the transaction. * @@ -36,14 +44,6 @@ public interface ITransaction extends ISpan { @NotNull Contexts getContexts(); - /** - * Returns the transaction's description. - * - * @return the description - */ - @Nullable - String getDescription(); - @NotNull @TestOnly List getSpans(); diff --git a/sentry/src/main/java/io/sentry/NoOpSpan.java b/sentry/src/main/java/io/sentry/NoOpSpan.java index aeed5699a3..96b37d682e 100644 --- a/sentry/src/main/java/io/sentry/NoOpSpan.java +++ b/sentry/src/main/java/io/sentry/NoOpSpan.java @@ -39,12 +39,27 @@ public void finish(@Nullable SpanStatus status) {} @Override public void setOperation(@Nullable String operation) {} + @Override + public @Nullable String getOperation() { + return null; + } + @Override public void setDescription(@Nullable String description) {} + @Override + public @Nullable String getDescription() { + return null; + } + @Override public void setStatus(@Nullable SpanStatus status) {} + @Override + public @Nullable SpanStatus getStatus() { + return null; + } + @Override public void setThrowable(@Nullable Throwable throwable) {} diff --git a/sentry/src/main/java/io/sentry/NoOpTransaction.java b/sentry/src/main/java/io/sentry/NoOpTransaction.java index 71de87696b..e263e9b864 100644 --- a/sentry/src/main/java/io/sentry/NoOpTransaction.java +++ b/sentry/src/main/java/io/sentry/NoOpTransaction.java @@ -21,6 +21,11 @@ public static NoOpTransaction getInstance() { @Override public void setName(@NotNull String name) {} + @Override + public @NotNull String getName() { + return null; + } + @Override public @NotNull ISpan startChild(final @NotNull String operation) { return NoOpSpan.getInstance(); @@ -89,12 +94,22 @@ public void finish(@Nullable SpanStatus status) {} @Override public void setOperation(@Nullable String operation) {} + @Override + public @Nullable String getOperation() { + return null; + } + @Override public void setDescription(@Nullable String description) {} @Override public void setStatus(@Nullable SpanStatus status) {} + @Override + public @Nullable SpanStatus getStatus() { + return null; + } + @Override public void setThrowable(@Nullable Throwable throwable) {} diff --git a/sentry/src/main/java/io/sentry/SentryTransaction.java b/sentry/src/main/java/io/sentry/SentryTransaction.java index 0bd944517a..224605cb90 100644 --- a/sentry/src/main/java/io/sentry/SentryTransaction.java +++ b/sentry/src/main/java/io/sentry/SentryTransaction.java @@ -14,7 +14,7 @@ @ApiStatus.Internal public final class SentryTransaction extends SentryBaseEvent implements ITransaction { /** The transaction name. */ - private @Nullable String transaction; + private @NotNull String transaction; /** The moment in time when span was started. */ private final @NotNull Date startTimestamp; @@ -72,6 +72,11 @@ public void setName(final @NotNull String name) { this.transaction = name; } + @Override + public @NotNull String getName() { + return this.transaction; + } + /** * Starts a child Span. * @@ -174,6 +179,11 @@ public void setOperation(@Nullable String op) { this.context.setOperation(op); } + @Override + public @Nullable String getOperation() { + return this.context.getOperation(); + } + /** * Sets transaction description. * @@ -225,8 +235,9 @@ Date getTimestamp() { return timestamp; } + @Override @Nullable - SpanStatus getStatus() { + public SpanStatus getStatus() { return this.getContexts().getTrace().getStatus(); } diff --git a/sentry/src/test/java/io/sentry/ScopeTest.kt b/sentry/src/test/java/io/sentry/ScopeTest.kt index dfe5cb412a..d4b778d3aa 100644 --- a/sentry/src/test/java/io/sentry/ScopeTest.kt +++ b/sentry/src/test/java/io/sentry/ScopeTest.kt @@ -689,7 +689,7 @@ class ScopeTest { assertEquals("transaction-name", scope.transactionName) scope.setTransaction("new-name") assertEquals("new-name", scope.transactionName) - sentryTransaction.setName("another-name") + sentryTransaction.name = "another-name" assertEquals("another-name", scope.transactionName) } diff --git a/sentry/src/test/java/io/sentry/SentryTransactionTest.kt b/sentry/src/test/java/io/sentry/SentryTransactionTest.kt index 5ac7c075f4..d4b393a816 100644 --- a/sentry/src/test/java/io/sentry/SentryTransactionTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTransactionTest.kt @@ -61,7 +61,7 @@ class SentryTransactionTest { val hub = mock() val transaction = SentryTransaction("name", SpanContext(), hub) val ex = RuntimeException() - transaction.setThrowable(ex) + transaction.throwable = ex transaction.finish() verify(hub).setSpanContext(ex, transaction) } @@ -140,7 +140,7 @@ class SentryTransactionTest { @Test fun `setting op sets op on TraceContext`() { val transaction = SentryTransaction("name") - transaction.setOperation("op") + transaction.operation = "op" transaction.finish() assertEquals("op", transaction.contexts.trace!!.operation) } @@ -156,7 +156,7 @@ class SentryTransactionTest { @Test fun `setting status sets status on TraceContext`() { val transaction = SentryTransaction("name") - transaction.setStatus(SpanStatus.ALREADY_EXISTS) + transaction.status = SpanStatus.ALREADY_EXISTS transaction.finish() assertEquals(SpanStatus.ALREADY_EXISTS, transaction.contexts.trace!!.status) } @@ -164,7 +164,7 @@ class SentryTransactionTest { @Test fun `setName overwrites the transaction name`() { val transaction = SentryTransaction("initial name") - transaction.setName("new name") + transaction.name = "new name" assertEquals("new name", transaction.transaction) } } From 1c3e17462ccad978504544cf8742ad576b923af3 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Thu, 21 Jan 2021 12:58:01 +0100 Subject: [PATCH 2/2] Changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2409f706af..990c652d78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Enhancement: Polish Performance API (#1165) * Enhancement: Set "debug" through external properties (#1186) * Enhancement: Simplify Spring integration (#1188) +* Enhancement: Improve Kotlin property access in Performance API (#1193) # 4.0.0-alpha.3