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

feat(tracing): Allow setting custom span status [NATIVE-441] #648

Merged
merged 12 commits into from
Jan 13, 2022
29 changes: 29 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,35 @@ SENTRY_EXPERIMENTAL_API void sentry_span_set_data(
SENTRY_EXPERIMENTAL_API void sentry_span_remove_data(
sentry_value_t span, const char *key);

typedef enum {
SENTRY_SPAN_STATUS_OK,
SENTRY_SPAN_STATUS_CANCELLED,
SENTRY_SPAN_STATUS_UNKNOWN,
SENTRY_SPAN_STATUS_INVALID_ARGUMENT,
SENTRY_SPAN_STATUS_DEADLINE_EXCEEDED,
SENTRY_SPAN_STATUS_NOT_FOUND,
SENTRY_SPAN_STATUS_ALREADY_EXISTS,
SENTRY_SPAN_STATUS_PERMISSION_DENIED,
SENTRY_SPAN_STATUS_RESOURCE_EXHAUSTED,
SENTRY_SPAN_STATUS_FAILED_PRECONDITION,
SENTRY_SPAN_STATUS_ABORTED,
SENTRY_SPAN_STATUS_OUT_OF_RANGE,
SENTRY_SPAN_STATUS_UNIMPLEMENTED,
SENTRY_SPAN_STATUS_INTERNAL_ERROR,
SENTRY_SPAN_STATUS_UNAVAILABLE,
SENTRY_SPAN_STATUS_DATA_LOSS,
SENTRY_SPAN_STATUS_UNAUTHENTICATED
} sentry_span_status_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

i think these enum variants, as well as the num itself could use some amount of documentation (see: https://github.com/getsentry/sentry-native/pull/646/files#diff-56ab308ccaccf29afea8b2668e5d95cf96266f1ca0ef9849863ad601dfac4be3R9-R65).

a link to the documentation in the docstring for the enum itself would also help greatly (https://develop.sentry.dev/sdk/event-payloads/span/).

Copy link
Contributor

Choose a reason for hiding this comment

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

thinking about it a little, i think i'm fine with keeping all of the variants here for the time being instead of hiding them away in sentry_tracing.h, so we don't need to use the trick that i'd mentioned earlier to hide this enum's members.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied over the documentation from your PR. Two questions, though:

  1. What is the UNDEFINED status used for?
  2. Why are UNDEFINED and OK both 0?


SENTRY_EXPERIMENTAL_API sentry_value_t sentry_status_to_string(
sentry_span_status_t status);
loewenheim marked this conversation as resolved.
Show resolved Hide resolved

/**
* Sets the span's status.
*/
SENTRY_EXPERIMENTAL_API void sentry_span_set_status(
sentry_value_t span, sentry_span_status_t status);
loewenheim marked this conversation as resolved.
Show resolved Hide resolved

#endif

#ifdef __cplusplus
Expand Down
49 changes: 48 additions & 1 deletion src/sentry_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ sentry__value_new_span(sentry_value_t parent, const char *operation)
sentry_value_set_by_key(
span, "span_id", sentry__value_new_span_uuid(&span_id));

sentry_value_set_by_key(span, "status", sentry_value_new_string("ok"));
sentry_span_set_status(span, SENTRY_SPAN_STATUS_OK);

// Span creation is currently aggressively pruned prior to this function so
// once we're in here we definitely know that the span and its parent
Expand Down Expand Up @@ -1326,3 +1326,50 @@ sentry_transaction_remove_data(sentry_value_t transaction, const char *key)
{
sentry_span_remove_data(transaction, key);
}

sentry_value_t
sentry_status_to_string(sentry_span_status_t status)
{
switch (status) {
case SENTRY_SPAN_STATUS_OK:
return sentry_value_new_string("ok");
case SENTRY_SPAN_STATUS_CANCELLED:
return sentry_value_new_string("cancelled");
case SENTRY_SPAN_STATUS_UNKNOWN:
return sentry_value_new_string("unknown");
case SENTRY_SPAN_STATUS_INVALID_ARGUMENT:
return sentry_value_new_string("invalid_argument");
case SENTRY_SPAN_STATUS_DEADLINE_EXCEEDED:
return sentry_value_new_string("deadline_exceeded");
case SENTRY_SPAN_STATUS_NOT_FOUND:
return sentry_value_new_string("not_found");
case SENTRY_SPAN_STATUS_ALREADY_EXISTS:
return sentry_value_new_string("already_exists");
case SENTRY_SPAN_STATUS_PERMISSION_DENIED:
return sentry_value_new_string("permission_denied");
case SENTRY_SPAN_STATUS_RESOURCE_EXHAUSTED:
return sentry_value_new_string("resource_exhausted");
case SENTRY_SPAN_STATUS_FAILED_PRECONDITION:
return sentry_value_new_string("failed_precondition");
case SENTRY_SPAN_STATUS_ABORTED:
return sentry_value_new_string("aborted");
case SENTRY_SPAN_STATUS_OUT_OF_RANGE:
return sentry_value_new_string("out_of_range");
case SENTRY_SPAN_STATUS_UNIMPLEMENTED:
return sentry_value_new_string("unimplemented");
case SENTRY_SPAN_STATUS_INTERNAL_ERROR:
return sentry_value_new_string("internal_error");
case SENTRY_SPAN_STATUS_UNAVAILABLE:
return sentry_value_new_string("unavailable");
case SENTRY_SPAN_STATUS_DATA_LOSS:
return sentry_value_new_string("data_loss");
case SENTRY_SPAN_STATUS_UNAUTHENTICATED:
return sentry_value_new_string("unauthenticated");
}
}

void
sentry_span_set_status(sentry_value_t span, sentry_span_status_t status)
{
sentry_value_set_by_key(span, "status", sentry_status_to_string(status));
}