|
| 1 | +## Improving Data on Transactions and Spans |
| 2 | + |
| 3 | +### Adding Data Attributes to Transactions |
| 4 | + |
| 5 | +You can add data attributes to your transactions. This data is visible in the trace explorer in Sentry. Data attributes must be of type `sentry_value_t`, which can be used to store `int32_t`, `double`, `int`, `char *` as well as lists containing `sentry_value_t` entries or a map with `char *` keys and `sentry_value_t` values: |
| 6 | + |
| 7 | +```c |
| 8 | +sentry_transaction_context_t *tx_ctx = |
| 9 | + sentry_transaction_context_new("processOrderBatch()", "task"); |
| 10 | +sentry_transaction_t *tx = |
| 11 | + sentry_transaction_start(tx_ctx, sentry_value_new_null()); |
| 12 | + |
| 13 | +sentry_transaction_set_data(tx, "my-data-attribute-1", |
| 14 | + sentry_value_new_string("value1")); |
| 15 | +sentry_transaction_set_data(tx, "my-data-attribute-2", |
| 16 | + sentry_value_new_int32(42)); |
| 17 | +sentry_transaction_set_data(tx, "my-data-attribute-3", |
| 18 | + sentry_value_new_double(3.14)); |
| 19 | +sentry_transaction_set_data(tx, "my-data-attribute-4", |
| 20 | + sentry_value_new_bool(true)); |
| 21 | + |
| 22 | +sentry_value_t value_list = sentry_value_new_list(); |
| 23 | +sentry_value_append(value_list, sentry_value_new_string("value1")); |
| 24 | +sentry_value_append(value_list, sentry_value_new_int32(42)); |
| 25 | +sentry_value_append(value_list, sentry_value_new_double(3.14)); |
| 26 | +sentry_value_append(value_list, sentry_value_new_bool(true)); |
| 27 | + |
| 28 | +sentry_transaction_set_data(tx, "my-data-attribute-5", |
| 29 | + value_list); |
| 30 | + |
| 31 | +sentry_value_t value_object = sentry_value_new_object(); |
| 32 | +sentry_value_set_by_key(value_object, "key_1", sentry_value_new_string("value1")); |
| 33 | +sentry_value_set_by_key(value_object, "key_2", sentry_value_new_int32(42)); |
| 34 | +sentry_value_set_by_key(value_object, "key_3", sentry_value_new_double(3.14)); |
| 35 | +sentry_value_set_by_key(value_object, "key_4", sentry_value_new_bool(true)); |
| 36 | + |
| 37 | +sentry_transaction_set_data(tx, "my-data-attribute-6", |
| 38 | + value_object); |
| 39 | +``` |
| 40 | +
|
| 41 | +### Adding Data Attributes to Spans |
| 42 | +
|
| 43 | +You can add data attributes to your spans. This data is visible in the trace explorer in Sentry. Data attributes must be of type `sentry_value_t`, which can be used to store `int32_t`, `double`, `int`, `char *` as well as lists containing `sentry_value_t` entries or a map with `char *` keys and `sentry_value_t` values: |
| 44 | +
|
| 45 | +```c |
| 46 | +sentry_transaction_context_t *tx_ctx = |
| 47 | + sentry_transaction_context_new("processOrderBatch()", "task"); |
| 48 | +sentry_transaction_t *tx = |
| 49 | + sentry_transaction_start(tx_ctx, sentry_value_new_null()); |
| 50 | +sentry_span_t *span = |
| 51 | + sentry_transaction_start_child(tx, "task", "operation"); |
| 52 | +
|
| 53 | +sentry_span_set_data(child, "my-data-attribute-1", |
| 54 | + sentry_value_new_string("value1")); |
| 55 | +sentry_span_set_data(child, "my-data-attribute-2", |
| 56 | + sentry_value_new_int32(42)); |
| 57 | +sentry_span_set_data(child, "my-data-attribute-3", |
| 58 | + sentry_value_new_double(3.14)); |
| 59 | +sentry_span_set_data(child, "my-data-attribute-4", |
| 60 | + sentry_value_new_bool(true)); |
| 61 | +
|
| 62 | +sentry_value_t value_list = sentry_value_new_list(); |
| 63 | +sentry_value_append(value_list, sentry_value_new_string("value1")); |
| 64 | +sentry_value_append(value_list, sentry_value_new_int32(42)); |
| 65 | +sentry_value_append(value_list, sentry_value_new_double(3.14)); |
| 66 | +sentry_value_append(value_list, sentry_value_new_bool(true)); |
| 67 | +
|
| 68 | +sentry_span_set_data(child, "my-data-attribute-5", |
| 69 | + value_list); |
| 70 | +
|
| 71 | +sentry_value_t value_object = sentry_value_new_object(); |
| 72 | +sentry_value_set_by_key(value_object, "key_1", sentry_value_new_string("value1")); |
| 73 | +sentry_value_set_by_key(value_object, "key_2", sentry_value_new_int32(42)); |
| 74 | +sentry_value_set_by_key(value_object, "key_3", sentry_value_new_double(3.14)); |
| 75 | +sentry_value_set_by_key(value_object, "key_4", sentry_value_new_bool(true)); |
| 76 | +
|
| 77 | +sentry_span_set_data(child, "my-data-attribute-6", |
| 78 | + value_object); |
| 79 | +``` |
0 commit comments