Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
305baf5
replace hub with scopes
adinauer Mar 27, 2024
95f5e1b
Add Scopes
adinauer Apr 2, 2024
27f2398
Introduce `IScopes` interface.
adinauer Apr 2, 2024
ce3c14f
Replace `IHub` with `IScopes` in core
adinauer Apr 2, 2024
ce615f4
Replace `IHub` with `IScopes` in android core
adinauer Apr 2, 2024
22ddc00
Replace `IHub` with `IScopes` in android integrations
adinauer Apr 2, 2024
305c217
Replace `IHub` with `IScopes` in apollo integrations
adinauer Apr 2, 2024
da927bc
Replace `IHub` with `IScopes` in okhttp integration
adinauer Apr 2, 2024
8279276
Replace `IHub` with `IScopes` in graphql integration
adinauer Apr 2, 2024
9bfc086
Replace `IHub` with `IScopes` in logging integrations
adinauer Apr 2, 2024
b998e50
Replace `IHub` with `IScopes` in more integrations
adinauer Apr 2, 2024
739827a
Replace `IHub` with `IScopes` in OTel integration
adinauer Apr 2, 2024
69f2d63
Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations
adinauer Apr 2, 2024
792d482
Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
adinauer Apr 2, 2024
9bcbce6
Replace `IHub` with `IScopes` in samples
adinauer Apr 2, 2024
3f25a4b
Merge branch 'feat/hsm-13-replacements-in-samples' into feat/hubs-sco…
adinauer Apr 2, 2024
d6fb40a
gitscopes -> github
adinauer Apr 2, 2024
7752bcc
Replace ThreadLocal with ScopesStorage
adinauer Apr 4, 2024
1e329c5
Move client and throwable to span map to scope
adinauer Apr 4, 2024
b0d89ae
Add global scope
adinauer Apr 4, 2024
cdd414a
use global scope in Scopes
adinauer Apr 4, 2024
98da9ff
Implement pushScope popScope and withScope for Scopes
adinauer Apr 4, 2024
2d26033
Add pushIsolationScope; add fork methods to ISCope
adinauer Apr 12, 2024
bbb6700
Use separate scopes for current, isolation and global scope; rename m…
adinauer Apr 12, 2024
c714b21
Allow controlling which scope configureScope uses
adinauer Apr 12, 2024
a474402
Combine scopes
adinauer Apr 12, 2024
ae93e33
Use new API for CRONS integrations
adinauer Apr 12, 2024
b01298b
Add lifecycle helper
adinauer Apr 12, 2024
b64e688
Change spring integrations to use new API
adinauer Apr 12, 2024
d06fc50
Use new API in servlet integrations
adinauer Apr 12, 2024
f0af5c3
Use new API for kotlin coroutines and wrapers for Supplier/Callable
adinauer Apr 12, 2024
2f02001
Discussion TODOs
adinauer Apr 12, 2024
bf4a7bf
Fix breadcrumb ordering
adinauer Apr 15, 2024
fb074c8
Merge branch '8.x.x' into feat/hsm-28-breadcrumb-ordering
adinauer Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SentryAppenderTest {
@BeforeTest
fun `clear MDC`() {
MDC.clear()
Sentry.close()
}

@Test
Expand Down
11 changes: 9 additions & 2 deletions sentry/src/main/java/io/sentry/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public final class Breadcrumb implements JsonUnknown, JsonSerializable, Comparab
/** A timestamp representing when the breadcrumb occurred. */
private final @NotNull Date timestamp;

private final @NotNull Long nanos;

/** If a message is provided, its rendered as text and the whitespace is preserved. */
private @Nullable String message;

Expand All @@ -46,10 +48,12 @@ public final class Breadcrumb implements JsonUnknown, JsonSerializable, Comparab
* @param timestamp the timestamp
*/
public Breadcrumb(final @NotNull Date timestamp) {
this.nanos = System.nanoTime();
this.timestamp = timestamp;
}

Breadcrumb(final @NotNull Breadcrumb breadcrumb) {
this.nanos = System.nanoTime();
this.timestamp = breadcrumb.timestamp;
this.message = breadcrumb.message;
this.type = breadcrumb.type;
Expand Down Expand Up @@ -663,8 +667,11 @@ public void setUnknown(@Nullable Map<String, Object> unknown) {
@Override
@SuppressWarnings("JavaUtilDate")
public int compareTo(@NotNull Breadcrumb o) {
// TODO also use nano time if equal
return timestamp.compareTo(o.timestamp);
int timestampCompare = timestamp.compareTo(o.timestamp);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to have consistent ordering, should we always use nanos?
We would also have to change the constructor to take a nano time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense, e.g. for OTEL where we likely have to create breadcrumbs after the fact. Will change it to only use nanos in a follow up PR.

if (timestampCompare == 0) {
return nanos.compareTo(o.nanos);
}
return timestampCompare;
}

public static final class JsonKeys {
Expand Down
72 changes: 72 additions & 0 deletions sentry/src/test/java/io/sentry/CombinedScopeViewTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.sentry

import kotlin.test.Test
import kotlin.test.assertEquals

class CombinedScopeViewTest {

@Test
fun `adds breadcrumbs from all scopes in sorted order`() {
val options = SentryOptions()
val globalScope = Scope(options)
val isolationScope = Scope(options)
val scope = Scope(options)

val combined = CombinedScopeView(globalScope, isolationScope, scope)

globalScope.addBreadcrumb(Breadcrumb.info("global 1"))
isolationScope.addBreadcrumb(Breadcrumb.info("isolation 1"))
scope.addBreadcrumb(Breadcrumb.info("current 1"))

globalScope.addBreadcrumb(Breadcrumb.info("global 2"))
isolationScope.addBreadcrumb(Breadcrumb.info("isolation 2"))
scope.addBreadcrumb(Breadcrumb.info("current 2"))

val breadcrumbs = combined.breadcrumbs
assertEquals("global 1", breadcrumbs.poll().message)
assertEquals("isolation 1", breadcrumbs.poll().message)
assertEquals("current 1", breadcrumbs.poll().message)
assertEquals("global 2", breadcrumbs.poll().message)
assertEquals("isolation 2", breadcrumbs.poll().message)
assertEquals("current 2", breadcrumbs.poll().message)
}

@Test
fun `oldest breadcrumbs are dropped first`() {
val options = SentryOptions().also { it.maxBreadcrumbs = 5 }
val globalScope = Scope(options)
val isolationScope = Scope(options)
val scope = Scope(options)

val combined = CombinedScopeView(globalScope, isolationScope, scope)

globalScope.addBreadcrumb(Breadcrumb.info("global 1"))
isolationScope.addBreadcrumb(Breadcrumb.info("isolation 1"))
scope.addBreadcrumb(Breadcrumb.info("current 1"))

globalScope.addBreadcrumb(Breadcrumb.info("global 2"))
isolationScope.addBreadcrumb(Breadcrumb.info("isolation 2"))
scope.addBreadcrumb(Breadcrumb.info("current 2"))

val breadcrumbs = combined.breadcrumbs
// assertEquals("global 1", breadcrumbs.poll().message) <-- was dropped
assertEquals("isolation 1", breadcrumbs.poll().message)
assertEquals("current 1", breadcrumbs.poll().message)
assertEquals("global 2", breadcrumbs.poll().message)
assertEquals("isolation 2", breadcrumbs.poll().message)
assertEquals("current 2", breadcrumbs.poll().message)

scope.addBreadcrumb(Breadcrumb.info("current 3"))
scope.addBreadcrumb(Breadcrumb.info("current 4"))

val breadcrumbs2 = combined.breadcrumbs
// assertEquals("global 1", breadcrumbs.poll().message) <-- was dropped
// assertEquals("isolation 1", breadcrumbs2.poll().message) <-- dropped
// assertEquals("current 1", breadcrumbs2.poll().message) <-- dropped
assertEquals("global 2", breadcrumbs2.poll().message)
assertEquals("isolation 2", breadcrumbs2.poll().message)
assertEquals("current 2", breadcrumbs2.poll().message)
assertEquals("current 3", breadcrumbs2.poll().message)
assertEquals("current 4", breadcrumbs2.poll().message)
}
}