Skip to content

Commit

Permalink
Copy options tags to transactions. (#1198)
Browse files Browse the repository at this point in the history
Fixes #1163
maciejwalkowiak authored Jan 22, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3eaa67f commit 58c6970
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
* Enhancement: Enable Kotlin map-like access on CustomSamplingContext (#1192)
* Enhancement: Auto register custom ITransportFactory in Spring integration (#1194)
* Enhancement: Improve Kotlin property access in Performance API (#1193)
* Enhancement: Copy options tags to transactions (#1198)
* Enhancement: Add convenient method for accessing event's throwable (1202)

# 4.0.0-alpha.3
9 changes: 9 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
@@ -400,6 +400,15 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec
if (transaction.getEnvironment() == null) {
transaction.setEnvironment(options.getEnvironment());
}
if (transaction.getTags() == null) {
transaction.setTags(new HashMap<>(options.getTags()));
} else {
for (Map.Entry<String, String> item : options.getTags().entrySet()) {
if (!transaction.getTags().containsKey(item.getKey())) {
transaction.setTag(item.getKey(), item.getValue());
}
}
}
return transaction;
}

21 changes: 21 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
@@ -824,6 +824,27 @@ class SentryClientTest {
assertEquals("transactionEnvironment", transaction.environment)
}

@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")
val sut = fixture.getSut()
val transaction = SentryTransaction("name")
sut.captureTransaction(transaction)
assertEquals(mapOf("tag1" to "value1"), transaction.tags)
}

@Test
fun `when transaction has tags, and tags are set on options, options tags are added to transactions`() {
fixture.sentryOptions.setTag("tag1", "value1")
fixture.sentryOptions.setTag("tag2", "value2")
val sut = fixture.getSut()
val transaction = SentryTransaction("name")
transaction.setTag("tag3", "value3")
transaction.setTag("tag2", "transaction-tag")
sut.captureTransaction(transaction)
assertEquals(mapOf("tag1" to "value1", "tag2" to "transaction-tag", "tag3" to "value3"), transaction.tags)
}

private fun createScope(): Scope {
return Scope(SentryOptions()).apply {
addBreadcrumb(Breadcrumb().apply {

0 comments on commit 58c6970

Please sign in to comment.