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

Add thread information when a span is created #2998

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Tag all spans with main thread flag ([#2998](https://github.com/getsentry/sentry-java/pull/2998))

## 6.32.0

### Features
Expand Down
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/SentryTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.sentry.protocol.TransactionNameSource;
import io.sentry.protocol.User;
import io.sentry.util.Objects;
import io.sentry.util.thread.MainThreadChecker;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
Expand Down Expand Up @@ -384,6 +385,8 @@ private ISpan createChild(
}
});
span.setDescription(description);
span.setData(
Copy link
Member

Choose a reason for hiding this comment

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

Did we agree to use the same blocked_main_thread key? I'd rather us choose something different, because we don't know for sure if it blocked the main thread, we know that it was just started there? Also, if we pick a different key, the current behavior for File I/O or DB spans will remain the same with blocked_main_thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, this wasn't discussed yet - thanks for bringing this up. @shruthilayaj I think Roman has some good points here, would it make sense for you as well to have a separate flag for main thread flagging?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it makes sense to have these as separate flags!

Copy link
Member Author

Choose a reason for hiding this comment

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

A bit lengthy, but how about started_on_main_thread? Would also make it clear that the flag is determined on span start.

Copy link
Member

Choose a reason for hiding this comment

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

This rfc https://github.com/getsentry/rfcs/pull/75/files got merged just a couple of days ago, so we probably should adhere to what is defined there. Here's the develop docs PR which adds the the new keys to the span data conventions getsentry/develop#1056, which means we have to send thread.id and thread.name, how does that sounds @shruthilayaj @markushi ?

Copy link
Member

Choose a reason for hiding this comment

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

h: I just wanted to make the same comment ⬆️ . Thanks @romtsn.

Copy link
Member

Choose a reason for hiding this comment

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

👍
just to confirm, sending thread.id and thread.name in addition to started_on_main_thread flag right?

Copy link
Member

Choose a reason for hiding this comment

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

mm, since in the RFC we say it's the thread the span originated from, I think thread.name: main would be the same thing pretty much, so we don't need both flags?
image

Copy link
Member

@shruthilayaj shruthilayaj Oct 23, 2023

Choose a reason for hiding this comment

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

yeah makes sense, and will thread name always be standardized to main if it started on the main thread regardless of the SDK it's coming from? (just so we know if we just look for main or need to maintain some sort of map/allow list for extracting this info in relay)

Copy link
Member

Choose a reason for hiding this comment

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

I'd start with just main, I guess we can expand it later. We can ensure that it's called main from the SDKs side

SpanDataConvention.BLOCKED_MAIN_THREAD_KEY, MainThreadChecker.getInstance().isMainThread());
this.children.add(span);
return span;
}
Expand Down
6 changes: 6 additions & 0 deletions sentry/src/test/java/io/sentry/SentryTracerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1236,4 +1236,10 @@ class SentryTracerTest {
assertTrue(tracer.isFinished)
verify(fixture.hub).captureTransaction(any(), anyOrNull(), anyOrNull(), anyOrNull())
}

@Test
fun `when a span is launched, the main thread flag is set as span data`() {
val tracer = fixture.getSut()
assertNotNull(tracer.startChild("span.op").getData(SpanDataConvention.BLOCKED_MAIN_THREAD_KEY))
}
}