Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only log startup moment span if it's not triggered by a lateness timer #46

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -105,6 +105,59 @@
"un": "John Doe",
"per": ["first_day"]
},
"spans": "__EMBRACE_TEST_IGNORE__",
"spans": [
{
"attributes": {
"emb.sequence_id": "2",
"emb.private": "true",
"emb.key": "true",
"emb.type": "PERFORMANCE"
},
"end_time_unix_nano": "__EMBRACE_TEST_IGNORE__",
"events": [
{
"attributes": {},
"name": "start-time",
"time_unix_nano": "__EMBRACE_TEST_IGNORE__"
}
],
"name": "emb-sdk-init",
"parent_span_id": "0000000000000000",
"span_id": "__EMBRACE_TEST_IGNORE__",
"start_time_unix_nano": "__EMBRACE_TEST_IGNORE__",
"status": "OK",
"trace_id": "__EMBRACE_TEST_IGNORE__"
},
{
"attributes": {
"emb.sequence_id": "3",
"emb.key": "true",
"emb.type": "PERFORMANCE"
},
"end_time_unix_nano": "__EMBRACE_TEST_IGNORE__",
"events": [],
"name": "emb-startup-moment",
"parent_span_id": "0000000000000000",
"span_id": "__EMBRACE_TEST_IGNORE__",
"start_time_unix_nano": "__EMBRACE_TEST_IGNORE__",
"status": "OK",
"trace_id": "__EMBRACE_TEST_IGNORE__"
},
{
"attributes": {
"emb.sequence_id": "1",
"emb.private": "true",
"emb.type": "SESSION"
},
"end_time_unix_nano": "__EMBRACE_TEST_IGNORE__",
"events": [],
"name": "emb-session-span",
"parent_span_id": "0000000000000000",
"span_id": "__EMBRACE_TEST_IGNORE__",
"start_time_unix_nano": "__EMBRACE_TEST_IGNORE__",
"status": "OK",
"trace_id": "__EMBRACE_TEST_IGNORE__"
}
],
"v": 13
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ internal class EmbraceEventService(
sessionProperties
)
if (isStartupEvent(name)) {
logStartupSpan()
if (!late) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The end moment can be ended twice if the lateness timer is invoked before the actual ending. Tracing doesn't have analogue of ending spans like this yet, and even if we do, we wouldn't do it in such a way that it causes two things to be logged.

For now, we'll only log a startup moment span if it's not "late". When we more systematically log moments as traces, we'll formalize this.

logStartupSpan()
}
logDeveloper("EmbraceEventService", "Ending Startup Ending")
startupEventInfo = eventHandler.buildStartupEventInfo(
originEventDescription.event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal class EmbraceEventServiceTest {
configService
)
gatingService = FakeGatingService(configService)
fakeWorkerThreadModule = FakeWorkerThreadModule(blockingMode = true)
fakeWorkerThreadModule = FakeWorkerThreadModule(clock = fakeClock, blockingMode = true)
spansService = EmbraceSpansService(clock = OpenTelemetryClock(embraceClock = fakeClock))
configService.addListener(spansService)
eventHandler = EventHandler(
Expand Down Expand Up @@ -431,9 +431,9 @@ internal class EmbraceEventServiceTest {
eventService.applicationStartupComplete()
val executor = fakeWorkerThreadModule.backgroundExecutor(ExecutorName.BACKGROUND_REGISTRATION)
executor.runCurrentlyBlocked()
assertEquals(1, spansService.completedSpans()?.size)
val startupSpan = spansService.completedSpans()!![0]
with(startupSpan) {
val completedSpans = checkNotNull(spansService.completedSpans())
assertEquals(1, completedSpans.size)
with(completedSpans[0]) {
assertEquals("emb-startup-moment", name)
assertEquals(TimeUnit.MILLISECONDS.toNanos(1), startTimeNanos)
assertEquals(TimeUnit.MILLISECONDS.toNanos(10), endTimeNanos)
Expand All @@ -453,18 +453,37 @@ internal class EmbraceEventServiceTest {
eventService.applicationStartupComplete()
val executor = fakeWorkerThreadModule.backgroundExecutor(ExecutorName.BACKGROUND_REGISTRATION)
executor.runCurrentlyBlocked()
assertEquals(0, spansService.completedSpans()?.size)
val completedSpans = checkNotNull(spansService.completedSpans())
assertEquals(0, completedSpans.size)

fakeClock.setCurrentTime(20L)
eventService.endEvent(STARTUP_EVENT_NAME)
executor.runCurrentlyBlocked()
assertEquals(1, spansService.completedSpans()?.size)
val completedSpansAgain = checkNotNull(spansService.completedSpans())
assertEquals(1, completedSpansAgain.size)

val startupSpan = spansService.completedSpans()!![0]
with(startupSpan) {
with(completedSpansAgain[0]) {
assertEquals("emb-startup-moment", name)
assertEquals(TimeUnit.MILLISECONDS.toNanos(1), startTimeNanos)
assertEquals(TimeUnit.MILLISECONDS.toNanos(20), endTimeNanos)
}
}

@Test
fun `startup not logged as span if startup moment is ended via a timeout`() {
spansService.initializeService(
sdkInitStartTimeNanos = TimeUnit.MILLISECONDS.toNanos(1),
sdkInitEndTimeNanos = TimeUnit.MILLISECONDS.toNanos(3)
)
configService.updateListeners()
spansService.flushSpans()
eventService.sendStartupMoment()
assertNull(eventService.getStartupMomentInfo())
fakeClock.tick(10000L)
fakeWorkerThreadModule.backgroundExecutor(ExecutorName.BACKGROUND_REGISTRATION).runCurrentlyBlocked()
fakeWorkerThreadModule.scheduledExecutor(ExecutorName.SCHEDULED_REGISTRATION).runCurrentlyBlocked()
assertNotNull(eventService.getStartupMomentInfo())
val completedSpans = checkNotNull(spansService.completedSpans())
assertEquals(0, completedSpans.size)
}
}