-
-
Notifications
You must be signed in to change notification settings - Fork 192
feat: Added sentry_set_trace
#1137
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
Conversation
|
set_trace_id
to continue traceset_trace_id
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1137 +/- ##
==========================================
+ Coverage 82.66% 82.81% +0.15%
==========================================
Files 53 53
Lines 7954 7973 +19
Branches 1246 1247 +1
==========================================
+ Hits 6575 6603 +28
+ Misses 1266 1256 -10
- Partials 113 114 +1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides a changelog, I missed a basic test for the interaction with transactions. Something like this in test_tracing.c
:
void
apply_scope_and_check_trace_context(
sentry_options_t *options, const char *trace_id, const char *parent_span_id)
{
// simulate scope application onto an event
sentry_value_t event = sentry_value_new_object();
SENTRY_WITH_SCOPE (scope) {
sentry__scope_apply_to_event(scope, options, event, SENTRY_SCOPE_NONE);
}
// check that the event has a trace context
sentry_value_t event_contexts = sentry_value_get_by_key(event, "contexts");
TEST_CHECK(!sentry_value_is_null(event_contexts));
TEST_CHECK(
sentry_value_get_type(event_contexts) == SENTRY_VALUE_TYPE_OBJECT);
sentry_value_t event_trace_context
= sentry_value_get_by_key(event_contexts, "trace");
TEST_CHECK(!sentry_value_is_null(event_trace_context));
TEST_CHECK(
sentry_value_get_type(event_trace_context) == SENTRY_VALUE_TYPE_OBJECT);
// check trace context content
const char *event_trace_id = sentry_value_as_string(
sentry_value_get_by_key(event_trace_context, "trace_id"));
TEST_CHECK_STRING_EQUAL(event_trace_id, trace_id);
const char *event_trace_parent_span_id = sentry_value_as_string(
sentry_value_get_by_key(event_trace_context, "parent_span_id"));
TEST_CHECK_STRING_EQUAL(event_trace_parent_span_id, parent_span_id);
sentry_uuid_t event_trace_span_id = sentry__value_as_uuid(
sentry_value_get_by_key(event_trace_context, "span_id"));
TEST_CHECK(!sentry_uuid_is_nil(&event_trace_span_id));
sentry_value_decref(event);
}
SENTRY_TEST(set_trace_id_with_txn)
{
// initialize SDK so we have a scope
sentry_options_t *options = sentry_options_new();
sentry_options_set_traces_sample_rate(options, 1.0);
sentry_options_set_sample_rate(options, 1.0);
sentry_init(options);
// inject a trace via trace-header into a transaction
const char *trace_header
= "2674eb52d5874b13b560236d6c79ce8a-a0f9fdf04f1a63df-1";
const char *txn_trace_id = "2674eb52d5874b13b560236d6c79ce8a";
const char *txn_parent_span_id = "a0f9fdf04f1a63df";
sentry_transaction_context_t *tx_ctx
= sentry_transaction_context_new("wow!", NULL);
sentry_transaction_context_update_from_header(
tx_ctx, "sentry-trace", trace_header);
sentry_transaction_t *tx
= sentry_transaction_start(tx_ctx, sentry_value_new_null());
// set the direct trace first
const char *direct_trace_id = "aaaabbbbccccddddeeeeffff00001111";
const char *direct_parent_span_id = "f0f0f0f0f0f0f0f0";
sentry_set_trace(direct_trace_id, direct_parent_span_id);
// events should get that trace applied
apply_scope_and_check_trace_context(
options, direct_trace_id, direct_parent_span_id);
// now set a scoped transaction
sentry_set_transaction_object(tx);
// events should get the transaction's trace applied
apply_scope_and_check_trace_context(
options, txn_trace_id, txn_parent_span_id);
sentry_transaction_finish(tx);
// after finishing the transaction, the direct trace should hit again
apply_scope_and_check_trace_context(
options, direct_trace_id, direct_parent_span_id);
sentry_close();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, especially the Java part 🤓
You probably need to apply the code formatter + .api file generator using
./gradlew spotlessApply
+ ./gradlew :sentry-native-ndk:apiDump
to make CI happier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If downstream, y'all are also happy, let's do this.
Because @supervacuus is fine with it!
@supervacuus @bitsandfoxes Question on usage -- where do the trace and parent span ids originate from? |
Like are you just meant to make one? with |
As explained in the inline docs and changelog, this function should primarily be used by downstream SDKs. Do you plan to write one? |
Hey @supervacuus yes, I am following that -- but where does the originating trace and parent span id come from? Like what API creates them? Let's say I own an upstream SDK. How do I create the necessary parameters to this method? |
For example, imagine I have 2 applications, one is my crash reporter and other is the application it is observing. My hope is to use this new API to "share a trace" between the two apps so that I can create breadcrumbs in the primary application which get married to the crash event when a crash is reported to sentry by the other out-of-proc crash reporter application For that to work, I have to have some means of creating the traceid and parent span id from the primary application |
Ah perhaps sentry_add_breadcrumb won't work for this at all as it needs a backend. Ours is null as we generate the dump ourselves by calling breakpad directly. :( |
sorry for the noise, going to just start my own dedicated issue on this topic #1197 |
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> [Vercel Preview](https://sentry-docs-htn2uy3fb.sentry.dev/platforms/native/tracing/instrumentation/custom-instrumentation/#:~:text=it%20to%20Sentry.-,By%20default%2C,-transactions%20will%20inherit) ## DESCRIBE YOUR PR Related to the feature added in getsentry/sentry-native#1137 & the update to native tracing in getsentry/sentry-native#1200 Since transactions no longer create a new `trace_id`, we want to document how to set up a trace boundary with `sentry_set_trace()`. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> [Vercel Preview](https://sentry-docs-htn2uy3fb.sentry.dev/platforms/native/tracing/instrumentation/custom-instrumentation/#:~:text=it%20to%20Sentry.-,By%20default%2C,-transactions%20will%20inherit) ## DESCRIBE YOUR PR Related to the feature added in getsentry/sentry-native#1137 & the update to native tracing in getsentry/sentry-native#1200 Since transactions no longer create a new `trace_id`, we want to document how to set up a trace boundary with `sentry_set_trace()`. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
Motivation
Looking at it from one of the upstream SDKs (i.e.
Android SDK
,Unity SDK
) there is currently no way to connect errors and events from their environment with the events sent bysentry-native
.The idea is to provide a way for those SDKs to propagate their trace to be used and applied to events. The trace ID can then be used to link those events across multiple SDKs, languages, and layers.