Skip to content

Commit

Permalink
Set SDK version on Transactions. (#1314)
Browse files Browse the repository at this point in the history
Fixes #1307
  • Loading branch information
maciejwalkowiak committed Mar 10, 2021
1 parent 5226e0c commit 6611960
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Feat: Add an overload for `startTransaction` that sets the created transaction to the Scope #1313
* Ref: Separate user facing and protocol classes in the Performance feature (#1304)
* Feat: Set SDK version on Transactions (#1307)

# 4.3.0

Expand Down
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 @@ -407,6 +407,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec
if (transaction.getEnvironment() == null) {
transaction.setEnvironment(options.getEnvironment());
}
if (transaction.getSdk() == null) {
transaction.setSdk(options.getSdkVersion());
}
if (transaction.getTags() == null) {
transaction.setTags(new HashMap<>(options.getTags()));
} else {
Expand Down
20 changes: 20 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,26 @@ class SentryClientTest {
assertEquals("transactionEnvironment", transaction.environment)
}

@Test
fun `when transaction does not have SDK version set, and the SDK version is set on options, options values are applied to transactions`() {
fixture.sentryOptions.sdkVersion = SdkVersion("sdk.name", "version")
val sut = fixture.getSut()
val transaction = SentryTransaction(SentryTracer(TransactionContext("name", "op"), mock()))
sut.captureTransaction(transaction)
assertEquals(fixture.sentryOptions.sdkVersion, transaction.sdk)
}

@Test
fun `when transaction has SDK version set, and the SDK version is set on options, options values are not applied to transactions`() {
fixture.sentryOptions.sdkVersion = SdkVersion("sdk.name", "version")
val sut = fixture.getSut()
val transaction = SentryTransaction(SentryTracer(TransactionContext("name", "op"), mock()))
val sdkVersion = SdkVersion("transaction.sdk.name", "version")
transaction.sdk = sdkVersion
sut.captureTransaction(transaction)
assertEquals(sdkVersion, transaction.sdk)
}

@Test
fun `when transaction does not have tags, and tags are set on options, options values are applied to transactions`() {
fixture.sentryOptions.setTag("tag1", "value1")
Expand Down

0 comments on commit 6611960

Please sign in to comment.