Skip to content

Commit

Permalink
Set SDK version on Transactions.
Browse files Browse the repository at this point in the history
Fixes #1307
  • Loading branch information
maciejwalkowiak committed Mar 9, 2021
1 parent 6af0a42 commit 742b3e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix: Initialize Sentry in Logback appender when DSN is not set in XML config (#1296)
* Fix: Fix JUL integration SDK name (#1293)
* Feat: Activity tracing auto instrumentation
* Feat: Set SDK version on Transactions (#1307)

# 4.2.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 @@ -400,6 +400,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
21 changes: 21 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,27 @@ 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("name", "op")
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("name", "op")
val sdkVersion = SdkVersion("transaction.sdk.name", "version")
transaction.sdk = sdkVersion
transaction.environment = "transactionEnvironment"
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 742b3e2

Please sign in to comment.