Skip to content

Commit be7b3b3

Browse files
committed
add code snippets
1 parent 1076eb7 commit be7b3b3

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)