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

tracing: Add transaction tag methods #626

Merged
merged 13 commits into from
Jan 11, 2022
24 changes: 24 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,30 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_sampled(
SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_sampled(
sentry_value_t transaction);

/**
* Sets a tag on a transaction to the given string value.
*/
SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag(
sentry_value_t transaction, const char *tag, const char *value);

/**
* Removes a tag from a transaction.
*/
SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_tag(
sentry_value_t transaction, const char *tag);

/**
* Sets the given key in a transaction's "data" section to the given value.
*/
SENTRY_EXPERIMENTAL_API void sentry_transaction_set_data(
sentry_value_t transaction, const char *key, sentry_value_t value);

/**
* Removes a key from a transaction's "data" section.
*/
SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_data(
sentry_value_t transaction, const char *key);

#ifdef __cplusplus
}
#endif
Expand Down
43 changes: 43 additions & 0 deletions src/sentry_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,3 +1219,46 @@ sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len)

sentry_event_add_thread(event, thread);
}

void
sentry_transaction_set_tag(
sentry_value_t transaction, const char *tag, const char *value)
{
sentry_value_t tags = sentry_value_get_by_key(transaction, "tags");
if (sentry_value_is_null(tags)) {
tags = sentry_value_new_object();
sentry_value_set_by_key(transaction, "tags", tags);
}
sentry_value_t value_str = sentry_value_new_string(value);
sentry_value_set_by_key(tags, tag, value_str);
}

void
sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag)
{
sentry_value_t tags = sentry_value_get_by_key(transaction, "tags");
if (!sentry_value_is_null(tags)) {
sentry_value_remove_by_key(tags, tag);
}
}

void
sentry_transaction_set_data(
sentry_value_t transaction, const char *key, sentry_value_t value)
{
sentry_value_t data = sentry_value_get_by_key(transaction, "data");
if (sentry_value_is_null(data)) {
data = sentry_value_new_object();
sentry_value_set_by_key(transaction, "data", data);
}
sentry_value_set_by_key(data, key, value);
}

void
sentry_transaction_remove_data(sentry_value_t transaction, const char *key)
{
sentry_value_t data = sentry_value_get_by_key(transaction, "data");
if (!sentry_value_is_null(data)) {
sentry_value_remove_by_key(data, key);
}
}