Skip to content

Commit 7c2dbdb

Browse files
Improve Kotlin property access in Performance API. (#1193)
1 parent fc69ce7 commit 7c2dbdb

File tree

9 files changed

+94
-16
lines changed

9 files changed

+94
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Enhancement: Polish Performance API (#1165)
1313
* Enhancement: Set "debug" through external properties (#1186)
1414
* Enhancement: Simplify Spring integration (#1188)
15+
* Enhancement: Improve Kotlin property access in Performance API (#1193)
1516

1617
# 4.0.0-alpha.3
1718

sentry/api/sentry.api

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ public abstract interface class io/sentry/ISerializer {
285285
public abstract interface class io/sentry/ISpan {
286286
public abstract fun finish ()V
287287
public abstract fun finish (Lio/sentry/SpanStatus;)V
288+
public abstract fun getDescription ()Ljava/lang/String;
289+
public abstract fun getOperation ()Ljava/lang/String;
288290
public abstract fun getSpanContext ()Lio/sentry/SpanContext;
291+
public abstract fun getStatus ()Lio/sentry/SpanStatus;
289292
public abstract fun getThrowable ()Ljava/lang/Throwable;
290293
public abstract fun setDescription (Ljava/lang/String;)V
291294
public abstract fun setOperation (Ljava/lang/String;)V
@@ -299,9 +302,9 @@ public abstract interface class io/sentry/ISpan {
299302

300303
public abstract interface class io/sentry/ITransaction : io/sentry/ISpan {
301304
public abstract fun getContexts ()Lio/sentry/protocol/Contexts;
302-
public abstract fun getDescription ()Ljava/lang/String;
303305
public abstract fun getEventId ()Lio/sentry/protocol/SentryId;
304306
public abstract fun getLatestActiveSpan ()Lio/sentry/Span;
307+
public abstract fun getName ()Ljava/lang/String;
305308
public abstract fun getRequest ()Lio/sentry/protocol/Request;
306309
public abstract fun getSpans ()Ljava/util/List;
307310
public abstract fun getTransaction ()Ljava/lang/String;
@@ -347,8 +350,11 @@ public final class io/sentry/NoOpLogger : io/sentry/ILogger {
347350
public final class io/sentry/NoOpSpan : io/sentry/ISpan {
348351
public fun finish ()V
349352
public fun finish (Lio/sentry/SpanStatus;)V
353+
public fun getDescription ()Ljava/lang/String;
350354
public static fun getInstance ()Lio/sentry/NoOpSpan;
355+
public fun getOperation ()Ljava/lang/String;
351356
public fun getSpanContext ()Lio/sentry/SpanContext;
357+
public fun getStatus ()Lio/sentry/SpanStatus;
352358
public fun getThrowable ()Ljava/lang/Throwable;
353359
public fun setDescription (Ljava/lang/String;)V
354360
public fun setOperation (Ljava/lang/String;)V
@@ -368,9 +374,12 @@ public final class io/sentry/NoOpTransaction : io/sentry/ITransaction {
368374
public fun getEventId ()Lio/sentry/protocol/SentryId;
369375
public static fun getInstance ()Lio/sentry/NoOpTransaction;
370376
public fun getLatestActiveSpan ()Lio/sentry/Span;
377+
public fun getName ()Ljava/lang/String;
378+
public fun getOperation ()Ljava/lang/String;
371379
public fun getRequest ()Lio/sentry/protocol/Request;
372380
public fun getSpanContext ()Lio/sentry/SpanContext;
373381
public fun getSpans ()Ljava/util/List;
382+
public fun getStatus ()Lio/sentry/SpanStatus;
374383
public fun getThrowable ()Ljava/lang/Throwable;
375384
public fun getTransaction ()Ljava/lang/String;
376385
public fun isSampled ()Ljava/lang/Boolean;
@@ -833,8 +842,11 @@ public final class io/sentry/SentryTransaction : io/sentry/SentryBaseEvent, io/s
833842
public fun finish (Lio/sentry/SpanStatus;)V
834843
public fun getDescription ()Ljava/lang/String;
835844
public fun getLatestActiveSpan ()Lio/sentry/Span;
845+
public fun getName ()Ljava/lang/String;
846+
public fun getOperation ()Ljava/lang/String;
836847
public fun getSpanContext ()Lio/sentry/SpanContext;
837848
public fun getSpans ()Ljava/util/List;
849+
public fun getStatus ()Lio/sentry/SpanStatus;
838850
public fun getTransaction ()Ljava/lang/String;
839851
public fun isSampled ()Ljava/lang/Boolean;
840852
public fun setDescription (Ljava/lang/String;)V

sentry/src/main/java/io/sentry/ISpan.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,44 @@ public interface ISpan {
4949
*/
5050
void setOperation(@Nullable String operation);
5151

52+
/**
53+
* Returns the span operation.
54+
*
55+
* @return the operation
56+
*/
57+
@Nullable
58+
String getOperation();
59+
5260
/**
5361
* Sets span description.
5462
*
5563
* @param description - the description.
5664
*/
5765
void setDescription(@Nullable String description);
5866

67+
/**
68+
* Returns the span description.
69+
*
70+
* @return the description
71+
*/
72+
@Nullable
73+
String getDescription();
74+
5975
/**
6076
* Sets span status.
6177
*
6278
* @param status - the status.
6379
*/
6480
void setStatus(@Nullable SpanStatus status);
6581

82+
/**
83+
* Returns the span status
84+
*
85+
* @return the status
86+
*/
87+
@Nullable
88+
SpanStatus getStatus();
89+
6690
/**
6791
* Sets the throwable that was thrown during the execution of the span.
6892
*

sentry/src/main/java/io/sentry/ITransaction.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public interface ITransaction extends ISpan {
1818
*/
1919
void setName(@NotNull String name);
2020

21+
/**
22+
* Returns transaction name.
23+
*
24+
* @return transaction name
25+
*/
26+
@NotNull
27+
String getName();
28+
2129
/**
2230
* Attaches request information to the transaction.
2331
*
@@ -36,14 +44,6 @@ public interface ITransaction extends ISpan {
3644
@NotNull
3745
Contexts getContexts();
3846

39-
/**
40-
* Returns the transaction's description.
41-
*
42-
* @return the description
43-
*/
44-
@Nullable
45-
String getDescription();
46-
4747
@NotNull
4848
@TestOnly
4949
List<Span> getSpans();

sentry/src/main/java/io/sentry/NoOpSpan.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,27 @@ public void finish(@Nullable SpanStatus status) {}
3939
@Override
4040
public void setOperation(@Nullable String operation) {}
4141

42+
@Override
43+
public @Nullable String getOperation() {
44+
return null;
45+
}
46+
4247
@Override
4348
public void setDescription(@Nullable String description) {}
4449

50+
@Override
51+
public @Nullable String getDescription() {
52+
return null;
53+
}
54+
4555
@Override
4656
public void setStatus(@Nullable SpanStatus status) {}
4757

58+
@Override
59+
public @Nullable SpanStatus getStatus() {
60+
return null;
61+
}
62+
4863
@Override
4964
public void setThrowable(@Nullable Throwable throwable) {}
5065

sentry/src/main/java/io/sentry/NoOpTransaction.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public static NoOpTransaction getInstance() {
2121
@Override
2222
public void setName(@NotNull String name) {}
2323

24+
@Override
25+
public @NotNull String getName() {
26+
return null;
27+
}
28+
2429
@Override
2530
public @NotNull ISpan startChild(final @NotNull String operation) {
2631
return NoOpSpan.getInstance();
@@ -89,12 +94,22 @@ public void finish(@Nullable SpanStatus status) {}
8994
@Override
9095
public void setOperation(@Nullable String operation) {}
9196

97+
@Override
98+
public @Nullable String getOperation() {
99+
return null;
100+
}
101+
92102
@Override
93103
public void setDescription(@Nullable String description) {}
94104

95105
@Override
96106
public void setStatus(@Nullable SpanStatus status) {}
97107

108+
@Override
109+
public @Nullable SpanStatus getStatus() {
110+
return null;
111+
}
112+
98113
@Override
99114
public void setThrowable(@Nullable Throwable throwable) {}
100115

sentry/src/main/java/io/sentry/SentryTransaction.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@ApiStatus.Internal
1515
public final class SentryTransaction extends SentryBaseEvent implements ITransaction {
1616
/** The transaction name. */
17-
private @Nullable String transaction;
17+
private @NotNull String transaction;
1818

1919
/** The moment in time when span was started. */
2020
private final @NotNull Date startTimestamp;
@@ -72,6 +72,11 @@ public void setName(final @NotNull String name) {
7272
this.transaction = name;
7373
}
7474

75+
@Override
76+
public @NotNull String getName() {
77+
return this.transaction;
78+
}
79+
7580
/**
7681
* Starts a child Span.
7782
*
@@ -174,6 +179,11 @@ public void setOperation(@Nullable String op) {
174179
this.context.setOperation(op);
175180
}
176181

182+
@Override
183+
public @Nullable String getOperation() {
184+
return this.context.getOperation();
185+
}
186+
177187
/**
178188
* Sets transaction description.
179189
*
@@ -225,8 +235,9 @@ Date getTimestamp() {
225235
return timestamp;
226236
}
227237

238+
@Override
228239
@Nullable
229-
SpanStatus getStatus() {
240+
public SpanStatus getStatus() {
230241
return this.getContexts().getTrace().getStatus();
231242
}
232243

sentry/src/test/java/io/sentry/ScopeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ class ScopeTest {
689689
assertEquals("transaction-name", scope.transactionName)
690690
scope.setTransaction("new-name")
691691
assertEquals("new-name", scope.transactionName)
692-
sentryTransaction.setName("another-name")
692+
sentryTransaction.name = "another-name"
693693
assertEquals("another-name", scope.transactionName)
694694
}
695695

sentry/src/test/java/io/sentry/SentryTransactionTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SentryTransactionTest {
6161
val hub = mock<IHub>()
6262
val transaction = SentryTransaction("name", SpanContext(), hub)
6363
val ex = RuntimeException()
64-
transaction.setThrowable(ex)
64+
transaction.throwable = ex
6565
transaction.finish()
6666
verify(hub).setSpanContext(ex, transaction)
6767
}
@@ -140,7 +140,7 @@ class SentryTransactionTest {
140140
@Test
141141
fun `setting op sets op on TraceContext`() {
142142
val transaction = SentryTransaction("name")
143-
transaction.setOperation("op")
143+
transaction.operation = "op"
144144
transaction.finish()
145145
assertEquals("op", transaction.contexts.trace!!.operation)
146146
}
@@ -156,15 +156,15 @@ class SentryTransactionTest {
156156
@Test
157157
fun `setting status sets status on TraceContext`() {
158158
val transaction = SentryTransaction("name")
159-
transaction.setStatus(SpanStatus.ALREADY_EXISTS)
159+
transaction.status = SpanStatus.ALREADY_EXISTS
160160
transaction.finish()
161161
assertEquals(SpanStatus.ALREADY_EXISTS, transaction.contexts.trace!!.status)
162162
}
163163

164164
@Test
165165
fun `setName overwrites the transaction name`() {
166166
val transaction = SentryTransaction("initial name")
167-
transaction.setName("new name")
167+
transaction.name = "new name"
168168
assertEquals("new name", transaction.transaction)
169169
}
170170
}

0 commit comments

Comments
 (0)