-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: set scope on transaction (#1409)
- Loading branch information
1 parent
75a8742
commit 838067f
Showing
3 changed files
with
75 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,7 +755,7 @@ class SentryClientTest { | |
@Test | ||
fun `transactions are sent using connection`() { | ||
val sut = fixture.getSut() | ||
sut.captureTransaction(SentryTransaction(SentryTracer(TransactionContext("a-transaction", "op"), mock())), mock(), null) | ||
sut.captureTransaction(SentryTransaction(SentryTracer(TransactionContext("a-transaction", "op"), mock())), Scope(fixture.sentryOptions), null) | ||
verify(fixture.transport).send(check { | ||
val transaction = it.items.first().getTransaction(fixture.sentryOptions.serializer) | ||
assertNotNull(transaction) | ||
|
@@ -771,14 +771,14 @@ class SentryClientTest { | |
span1.finish() | ||
val span2 = transaction.startChild("span2") | ||
|
||
sut.captureTransaction(SentryTransaction(transaction), mock(), null) | ||
sut.captureTransaction(SentryTransaction(transaction), Scope(fixture.sentryOptions), null) | ||
verify(fixture.transport).send(check { | ||
val sentTransaction = it.items.first().getTransaction(fixture.sentryOptions.serializer) | ||
assertNotNull(sentTransaction) { tx -> | ||
val sentSpanIds = tx.spans.map { span -> span.spanId } | ||
assertTrue(sentSpanIds.contains(span1.spanContext.spanId)) | ||
assertFalse(sentSpanIds.contains(span2.spanContext.spanId)) | ||
} | ||
assertNotNull(sentTransaction) { tx -> | ||
val sentSpanIds = tx.spans.map { span -> span.spanId } | ||
assertTrue(sentSpanIds.contains(span1.spanContext.spanId)) | ||
assertFalse(sentSpanIds.contains(span2.spanContext.spanId)) | ||
} | ||
}, eq(null)) | ||
} | ||
|
||
|
@@ -800,6 +800,28 @@ class SentryClientTest { | |
verifyAttachmentsInEnvelope(transaction.eventId) | ||
} | ||
|
||
@Test | ||
fun `when captureTransaction scope is applied to transaction`() { | ||
val sut = fixture.getSut() | ||
val scope = Scope(fixture.sentryOptions) | ||
scope.setTag("tag1", "value1") | ||
scope.setContexts("context-key", "context-value") | ||
scope.request = Request().apply { | ||
url = "/url" | ||
} | ||
sut.captureTransaction(SentryTransaction(SentryTracer(TransactionContext("a-transaction", "op"), mock())), scope, null) | ||
verify(fixture.transport).send(check { envelope -> | ||
val transaction = envelope.items.first().getTransaction(fixture.sentryOptions.serializer) | ||
assertNotNull(transaction) { | ||
assertEquals("value1", it.getTag("tag1")) | ||
assertEquals(mapOf("value" to "context-value"), it.contexts["context-key"]) | ||
assertNotNull(it.request) { request -> | ||
assertEquals("/url", request.url) | ||
} | ||
} | ||
}, eq(null)) | ||
} | ||
|
||
@Test | ||
fun `when scope's active span is a transaction, transaction context is applied to an event`() { | ||
val event = SentryEvent() | ||
|
@@ -964,17 +986,18 @@ class SentryClientTest { | |
return Session("dis", User(), "env", release) | ||
} | ||
|
||
private val userFeedback: UserFeedback get() { | ||
val eventId = SentryId("c2fb8fee2e2b49758bcb67cda0f713c7") | ||
val userFeedback = UserFeedback(eventId) | ||
userFeedback.apply { | ||
name = "John" | ||
email = "[email protected]" | ||
comments = "comment" | ||
} | ||
private val userFeedback: UserFeedback | ||
get() { | ||
val eventId = SentryId("c2fb8fee2e2b49758bcb67cda0f713c7") | ||
val userFeedback = UserFeedback(eventId) | ||
userFeedback.apply { | ||
name = "John" | ||
email = "[email protected]" | ||
comments = "comment" | ||
} | ||
|
||
return userFeedback | ||
} | ||
return userFeedback | ||
} | ||
|
||
internal class CustomTransportGate : ITransportGate { | ||
override fun isConnected(): Boolean = false | ||
|
@@ -1022,7 +1045,7 @@ class SentryClientTest { | |
|
||
val attachmentItemTooBig = attachmentItems.last() | ||
assertFailsWith<SentryEnvelopeException>("Getting data from attachment should" + | ||
"throw an exception, because the attachment is too big.") { | ||
"throw an exception, because the attachment is too big.") { | ||
attachmentItemTooBig.data | ||
} | ||
}, isNull()) | ||
|