Skip to content

Commit

Permalink
tracing: Add transaction/span tag methods [NATIVE-442] (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored Jan 11, 2022
1 parent c5c31e5 commit cd50cca
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
53 changes: 53 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,59 @@ SENTRY_EXPERIMENTAL_API sentry_value_t sentry_span_start_child(
*/
SENTRY_EXPERIMENTAL_API void sentry_span_finish(
sentry_value_t root_transaction, sentry_value_t span);

/**
* Sets a tag on a transaction to the given string value.
*
* Tags longer than 200 bytes will be truncated.
*/
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);

/**
* Sets a tag on a span to the given string value.
*
* Tags longer than 200 bytes will be truncated.
*/
SENTRY_EXPERIMENTAL_API void sentry_span_set_tag(
sentry_value_t span, const char *tag, const char *value);

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

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

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

#endif

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

sentry_event_add_thread(event, thread);
}

void
sentry_span_set_tag(sentry_value_t span, const char *tag, const char *value)
{
sentry_value_t tags = sentry_value_get_by_key(span, "tags");
if (sentry_value_is_null(tags)) {
tags = sentry_value_new_object();
sentry_value_set_by_key(span, "tags", tags);
}

char *s = sentry__string_clonen(value, 200);
if (s) {
sentry_value_set_by_key(tags, tag, sentry__value_new_string_owned(s));
} else {
sentry_value_set_by_key(tags, tag, sentry_value_new_null());
}
}

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

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

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

void
sentry_transaction_set_tag(
sentry_value_t transaction, const char *tag, const char *value)
{
sentry_span_set_tag(transaction, tag, value);
}

void
sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag)
{
sentry_span_remove_tag(transaction, tag);
}

void
sentry_transaction_set_data(
sentry_value_t transaction, const char *key, sentry_value_t value)
{
sentry_span_set_data(transaction, key, value);
}

void
sentry_transaction_remove_data(sentry_value_t transaction, const char *key)
{
sentry_span_remove_data(transaction, key);
}

0 comments on commit cd50cca

Please sign in to comment.