Skip to content

Commit 9412871

Browse files
docs(native): document how to set attribute on spans/transactions
1 parent 8eebbf3 commit 9412871

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

docs/platforms/native/common/tracing/instrumentation/custom-instrumentation.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ When using these functions, you should ensure that the provided timestamps are c
3838

3939
<PlatformContent includePath="performance/connect-errors-spans" />
4040

41+
<PlatformContent includePath="performance/improving-data" />
42+
4143
## Distributed Tracing
4244

4345
In order to use distributed tracing with the Native SDK, follow the <PlatformLink to="/tracing/trace-propagation/custom-instrumentation/">custom instrumentation</PlatformLink> steps.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## Improving Data on Transactions and Spans
2+
You can add Data Attributes to both Spans and Transactions. This data is visible in the trace explorer in Sentry.
3+
The data must be of type `sentry_value_t`, which can store:
4+
* 32-bit signed integers,
5+
* double-precision floating-points,
6+
* null-terminated strings, as well as
7+
* lists and string-keyed maps containing `sentry_value_t` entries
8+
9+
### Adding Data Attributes to Transactions
10+
11+
You can add data attributes to your transactions using the following API:
12+
13+
```c
14+
sentry_transaction_context_t *tx_ctx =
15+
sentry_transaction_context_new("processOrderBatch()", "task");
16+
sentry_transaction_t *tx =
17+
sentry_transaction_start(tx_ctx, sentry_value_new_null());
18+
19+
sentry_transaction_set_data(tx, "my-data-attribute-1",
20+
sentry_value_new_string("value1"));
21+
sentry_transaction_set_data(tx, "my-data-attribute-2",
22+
sentry_value_new_int32(42));
23+
sentry_transaction_set_data(tx, "my-data-attribute-3",
24+
sentry_value_new_double(3.14));
25+
sentry_transaction_set_data(tx, "my-data-attribute-4",
26+
sentry_value_new_bool(true));
27+
28+
sentry_value_t value_list = sentry_value_new_list();
29+
sentry_value_append(value_list, sentry_value_new_string("value1"));
30+
sentry_value_append(value_list, sentry_value_new_int32(42));
31+
sentry_value_append(value_list, sentry_value_new_double(3.14));
32+
sentry_value_append(value_list, sentry_value_new_bool(true));
33+
34+
sentry_transaction_set_data(tx, "my-data-attribute-5", value_list);
35+
36+
sentry_value_t value_object = sentry_value_new_object();
37+
sentry_value_set_by_key(value_object, "key_1", sentry_value_new_string("value1"));
38+
sentry_value_set_by_key(value_object, "key_2", sentry_value_new_int32(42));
39+
sentry_value_set_by_key(value_object, "key_3", sentry_value_new_double(3.14));
40+
sentry_value_set_by_key(value_object, "key_4", sentry_value_new_bool(true));
41+
42+
sentry_transaction_set_data(tx, "my-data-attribute-6", value_object);
43+
```
44+
45+
### Adding Data Attributes to Spans
46+
47+
You can add data attributes to your spans using the following API:
48+
49+
```c
50+
sentry_transaction_context_t *tx_ctx =
51+
sentry_transaction_context_new("processOrderBatch()", "task");
52+
sentry_transaction_t *tx =
53+
sentry_transaction_start(tx_ctx, sentry_value_new_null());
54+
sentry_span_t *span =
55+
sentry_transaction_start_child(tx, "task", "operation");
56+
57+
sentry_span_set_data(span, "my-data-attribute-1",
58+
sentry_value_new_string("value1"));
59+
sentry_span_set_data(span, "my-data-attribute-2",
60+
sentry_value_new_int32(42));
61+
sentry_span_set_data(span, "my-data-attribute-3",
62+
sentry_value_new_double(3.14));
63+
sentry_span_set_data(span, "my-data-attribute-4",
64+
sentry_value_new_bool(true));
65+
66+
sentry_value_t value_list = sentry_value_new_list();
67+
sentry_value_append(value_list, sentry_value_new_string("value1"));
68+
sentry_value_append(value_list, sentry_value_new_int32(42));
69+
sentry_value_append(value_list, sentry_value_new_double(3.14));
70+
sentry_value_append(value_list, sentry_value_new_bool(true));
71+
72+
sentry_span_set_data(span, "my-data-attribute-5", value_list);
73+
74+
sentry_value_t value_object = sentry_value_new_object();
75+
sentry_value_set_by_key(value_object, "key_1", sentry_value_new_string("value1"));
76+
sentry_value_set_by_key(value_object, "key_2", sentry_value_new_int32(42));
77+
sentry_value_set_by_key(value_object, "key_3", sentry_value_new_double(3.14));
78+
sentry_value_set_by_key(value_object, "key_4", sentry_value_new_bool(true));
79+
80+
sentry_span_set_data(span, "my-data-attribute-6", value_object);
81+
```

0 commit comments

Comments
 (0)