Skip to content

Commit 647fb6a

Browse files
feat(native): update custom instrumentation (#11511)
* fix(native): code snippet syntax * feat(native): update sentry-trace header format * add explanation about format mismatch
1 parent b30fda8 commit 647fb6a

File tree

1 file changed

+11
-12
lines changed
  • platform-includes/distributed-tracing/custom-instrumentation

1 file changed

+11
-12
lines changed

platform-includes/distributed-tracing/custom-instrumentation/native.mdx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@ To obtain headers from a transaction so it can be continued from a downstream se
88

99
```c
1010
static void
11-
copy_headers_to(const char *key, const char *value, void *userdata)
12-
{
13-
sentry_value_t *headers
14-
= (sentry_value_t *)userdata;
15-
sentry_value_set_by_key(*headers, key, value);
11+
copy_headers_to(const char *key, const char *value, void *userdata) {
12+
sentry_value_t *headers = (sentry_value_t *)userdata;
13+
sentry_value_set_by_key(*headers, key, sentry_value_new_string(value));
1614
}
1715

1816
int main(int argc, char **argv) {
19-
...
20-
// Transaction to continue off of
17+
// Transaction to continue off of
2118
sentry_transaction_context_t *tx_ctx = sentry_transaction_context_new(
2219
"honk",
23-
NULL,
20+
NULL
2421
);
2522
sentry_transaction_t *tx = sentry_transaction_start(tx_ctx, sentry_value_new_null());
2623

27-
sentry_value_t *headers = sentry_value_new_object();
28-
sentry_transaction_iter_headers(tx, copy_headers_to, (void *)headers);
24+
sentry_value_t headers = sentry_value_new_object();
25+
sentry_transaction_iter_headers(tx, copy_headers_to, (void *) &headers);
2926
}
3027
```
3128
@@ -34,12 +31,14 @@ To create a transaction as a continuation of a trace retrieved from an upstream
3431
```c
3532
sentry_transaction_context_t *tx_ctx = sentry_transaction_context_new(
3633
"honk",
37-
NULL,
34+
NULL
3835
);
3936
sentry_transaction_context_update_from_header(
4037
tx_ctx,
4138
"sentry-trace",
42-
"atraceid-aspanid-issampled",
39+
"41c74c2ea9f2bfb184f86939de5b97aa-399b3e5cc8b83494-1"
4340
);
4441
4542
```
43+
44+
The format of the `sentry-trace` header should follow the one defined in [the telemetry docs](https://develop.sentry.dev/sdk/telemetry/traces/#header-sentry-trace). It should consist of a 32 character hexadecimal string for the `traceId`, followed by a 16 character hexadecimal string for the `spanId` and an optional single character for the `sampled` flag. If the given string doesn't match this format, the update is ignored and the values in the transaction context will remain unchanged.

0 commit comments

Comments
 (0)