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

Improve Kotlin property access in Performance API. #1193

Merged
merged 2 commits into from
Jan 21, 2021
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 @@ -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

Expand Down
14 changes: 13 additions & 1 deletion sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions sentry/src/main/java/io/sentry/ISpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,44 @@ public interface ISpan {
*/
void setOperation(@Nullable String operation);

/**
* Returns the span operation.
*
* @return the operation
*/
@Nullable
String getOperation();

/**
* Sets span description.
*
* @param description - the description.
*/
void setDescription(@Nullable String description);

/**
* Returns the span description.
*
* @return the description
*/
@Nullable
String getDescription();

/**
* Sets span status.
*
* @param status - the status.
*/
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.
*
Expand Down
16 changes: 8 additions & 8 deletions sentry/src/main/java/io/sentry/ITransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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<Span> getSpans();
Expand Down
15 changes: 15 additions & 0 deletions sentry/src/main/java/io/sentry/NoOpSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
15 changes: 15 additions & 0 deletions sentry/src/main/java/io/sentry/NoOpTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {}

Expand Down
15 changes: 13 additions & 2 deletions sentry/src/main/java/io/sentry/SentryTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -225,8 +235,9 @@ Date getTimestamp() {
return timestamp;
}

@Override
@Nullable
SpanStatus getStatus() {
public SpanStatus getStatus() {
return this.getContexts().getTrace().getStatus();
}

Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/ScopeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions sentry/src/test/java/io/sentry/SentryTransactionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SentryTransactionTest {
val hub = mock<IHub>()
val transaction = SentryTransaction("name", SpanContext(), hub)
val ex = RuntimeException()
transaction.setThrowable(ex)
transaction.throwable = ex
transaction.finish()
verify(hub).setSpanContext(ex, transaction)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -156,15 +156,15 @@ 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)
}

@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)
}
}