Skip to content

Commit 1223b68

Browse files
committed
use enum
1 parent 6b4bad0 commit 1223b68

File tree

6 files changed

+52
-47
lines changed

6 files changed

+52
-47
lines changed

agent/php_newrelic.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,9 @@ nrinistr_t
497497
dt_remote_parent_not_sampled; /* newrelic.distributed_tracing.sampler.remote_parent_not_sampled */
498498
/* decoding of newrelic.distributed_tracing.sampler.remote_parent_sampled and
499499
* newrelic.distributed_tracing.sampler.remote_parent_not_sampled.
500-
* 0 = "default"
501-
* 1 = "always_on"
502-
* -1 = "always_off"
503500
*/
504-
int dt_sampler_parent_sampled;
505-
int dt_sampler_parent_not_sampled;
501+
nr_upstream_parent_sampling_control_t dt_sampler_parent_sampled;
502+
nr_upstream_parent_sampling_control_t dt_sampler_parent_not_sampled;
506503

507504
nrinistr_t
508505
trace_observer_host; /* newrelic.infinite_tracing.trace_observer.host */

agent/php_nrini.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,21 +1989,21 @@ static PHP_INI_MH(nr_dt_sampler_remote_parent_mh) {
19891989

19901990
if (0 == nr_strcmp(NEW_VALUE, "default")) {
19911991
if (parent_sampled) {
1992-
NRPRG(dt_sampler_parent_sampled) = 0;
1992+
NRPRG(dt_sampler_parent_sampled) = DEFAULT;
19931993
} else {
1994-
NRPRG(dt_sampler_parent_not_sampled) = 0;
1994+
NRPRG(dt_sampler_parent_not_sampled) = DEFAULT;
19951995
}
19961996
} else if (0 == nr_strcmp(NEW_VALUE, "always_on")) {
19971997
if (parent_sampled) {
1998-
NRPRG(dt_sampler_parent_sampled) = 1;
1998+
NRPRG(dt_sampler_parent_sampled) = ALWAYS_KEEP;
19991999
} else {
2000-
NRPRG(dt_sampler_parent_not_sampled) = 1;
2000+
NRPRG(dt_sampler_parent_not_sampled) = ALWAYS_KEEP;
20012001
}
20022002
} else if (0 == nr_strcmp(NEW_VALUE, "always_off")) {
20032003
if (parent_sampled) {
2004-
NRPRG(dt_sampler_parent_sampled) = -1;
2004+
NRPRG(dt_sampler_parent_sampled) = ALWAYS_DROP;
20052005
} else {
2006-
NRPRG(dt_sampler_parent_not_sampled) = -1;
2006+
NRPRG(dt_sampler_parent_not_sampled) = ALWAYS_DROP;
20072007
}
20082008
} else {
20092009
nrl_warning(NRL_INIT, "Invalid %s value \"%s\"; using \"%s\" instead.",

axiom/nr_distributed_trace.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,12 +1302,12 @@ char* nr_distributed_trace_create_w3c_traceparent_header(const char* trace_id,
13021302
void nr_distributed_trace_handle_inbound_w3c_sampled_flag(
13031303
nr_distributed_trace_t* dt,
13041304
const nrobj_t* trace_headers,
1305-
int remote_parent_sampled,
1306-
int remote_parent_not_sampled) {
1305+
nr_upstream_parent_sampling_control_t remote_parent_sampled,
1306+
nr_upstream_parent_sampling_control_t remote_parent_not_sampled) {
13071307
const nrobj_t* traceparent = NULL;
13081308
int sampled = 0;
13091309
nr_status_t parse_err = NR_FAILURE;
1310-
if (0 != remote_parent_sampled || 0 != remote_parent_not_sampled) {
1310+
if (DEFAULT != remote_parent_sampled || DEFAULT != remote_parent_not_sampled) {
13111311
traceparent = nro_get_hash_value(trace_headers, "traceparent", &parse_err);
13121312
if (nrunlikely(NULL == traceparent || NR_SUCCESS != parse_err)) {
13131313
return;
@@ -1316,18 +1316,19 @@ void nr_distributed_trace_handle_inbound_w3c_sampled_flag(
13161316
if (nrunlikely(NR_SUCCESS != parse_err)) {
13171317
return;
13181318
}
1319+
/* The final bit of the trace_flags indicates the sampling decision */
13191320
if (sampled & 0x01) {
1320-
if (0 != remote_parent_sampled) {
1321-
if (1 == remote_parent_sampled) {
1321+
if (DEFAULT != remote_parent_sampled) {
1322+
if (ALWAYS_KEEP == remote_parent_sampled) {
13221323
dt->sampled = true;
13231324
dt->priority = 2;
13241325
} else {
13251326
dt->sampled = false;
13261327
}
13271328
}
13281329
} else {
1329-
if (0 != remote_parent_not_sampled) {
1330-
if (-1 == remote_parent_not_sampled) {
1330+
if (DEFAULT != remote_parent_not_sampled) {
1331+
if (ALWAYS_DROP == remote_parent_not_sampled) {
13311332
dt->sampled = false;
13321333
} else {
13331334
dt->sampled = true;

axiom/nr_distributed_trace.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ static const char NR_DISTRIBUTED_TRACE_W3C_TRACECONTEXT_ACCEPT_EXCEPTION[]
6060
typedef struct _nr_distributed_trace_t nr_distributed_trace_t;
6161
typedef struct _nr_distributed_trace_payload_t nr_distributed_trace_payload_t;
6262

63+
/*
64+
* Control options for how to respect other-vendor upstream sampling
65+
* decisions.
66+
*/
67+
typedef enum {
68+
DEFAULT,
69+
ALWAYS_KEEP,
70+
ALWAYS_DROP
71+
} nr_upstream_parent_sampling_control_t;
72+
6373
/*
6474
* Purpose : Creates/allocates a new distributed tracing metadata struct
6575
* instance. It's the responsibility of the caller to
@@ -416,16 +426,11 @@ bool nr_distributed_trace_accept_inbound_w3c_payload(
416426
* 2. W3C trace headers objet
417427
* 3. Setting for if the upstream trace is sampled
418428
* 4. Setting for if the upstream trace is not sampled
419-
*
420-
* Notes : The setting objects should follow this specification:
421-
* 1 = always keep
422-
* 0 = ignore upstream sampled flag
423-
* -1 = always toss
424429
*/
425430
void nr_distributed_trace_handle_inbound_w3c_sampled_flag(
426431
nr_distributed_trace_t* dt,
427432
const nrobj_t* trace_headers,
428-
int remote_parent_sampled,
429-
int remote_parent_not_sampled);
433+
nr_upstream_parent_sampling_control_t remote_parent_sampled,
434+
nr_upstream_parent_sampling_control_t remote_parent_not_sampled);
430435

431436
#endif /* NR_DISTRIBUTED_TRACE_HDR */

axiom/nr_txn.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,20 @@ typedef struct _nrtxnopt_t {
100100
headers in favor of only
101101
W3C trace context headers
102102
*/
103-
int dt_sampler_parent_sampled; /* how to sample spans when non-
104-
New Relic upstream did sample.
105-
1 - always keep
106-
0 - use default sampling
107-
-1 - always toss
108-
*/
109-
int dt_sampler_parent_not_sampled; /* how to sample spans when non-
110-
New Relic upstream didn't sample.
111-
1 - always keep
112-
0 - use default sampling
113-
-1 - always toss
114-
*/
103+
nr_upstream_parent_sampling_control_t
104+
dt_sampler_parent_sampled; /* how to sample spans when non-
105+
New Relic upstream did sample.
106+
1 - always keep
107+
0 - use default sampling
108+
-1 - always toss
109+
*/
110+
nr_upstream_parent_sampling_control_t
111+
dt_sampler_parent_not_sampled; /* how to sample spans when non-
112+
New Relic upstream didn't sample.
113+
1 - always keep
114+
0 - use default sampling
115+
-1 - always toss
116+
*/
115117
int span_events_enabled; /* Whether span events are enabled */
116118
size_t
117119
span_events_max_samples_stored; /* The maximum number of span events per

axiom/tests/test_txn.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6328,16 +6328,16 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
63286328
txn.distributed_trace->inbound.set = 0; \
63296329
nrm_table_destroy(&txn.unscoped_metrics); \
63306330
txn.unscoped_metrics = nrm_table_create(0); \
6331-
txn.options.dt_sampler_parent_not_sampled = 0; \
6332-
txn.options.dt_sampler_parent_sampled = 0;
6331+
txn.options.dt_sampler_parent_not_sampled = DEFAULT; \
6332+
txn.options.dt_sampler_parent_sampled = DEFAULT;
63336333

63346334
headers = nr_hashmap_create(NULL);
63356335

63366336
/*
63376337
* Test : DT traceparent sampled flag INI settings
63386338
*/
63396339
// 1: upstream not sampled, agent discard
6340-
txn.options.dt_sampler_parent_not_sampled = -1;
6340+
txn.options.dt_sampler_parent_not_sampled = ALWAYS_DROP;
63416341
nr_distributed_trace_destroy(&txn.distributed_trace);
63426342
txn.distributed_trace = nr_distributed_trace_create();
63436343
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_NOT_SAMPLED);
@@ -6354,7 +6354,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
63546354

63556355
// 2: upstream not sampled, agent keep
63566356
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6357-
txn.options.dt_sampler_parent_not_sampled = 1;
6357+
txn.options.dt_sampler_parent_not_sampled = ALWAYS_KEEP;
63586358
nr_distributed_trace_destroy(&txn.distributed_trace);
63596359
txn.distributed_trace = nr_distributed_trace_create();
63606360
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_NOT_SAMPLED);
@@ -6370,7 +6370,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
63706370

63716371
// 3: upstream not sampled, agent default (keep)
63726372
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6373-
txn.options.dt_sampler_parent_not_sampled = 0;
6373+
txn.options.dt_sampler_parent_not_sampled = DEFAULT;
63746374
nr_distributed_trace_destroy(&txn.distributed_trace);
63756375
txn.distributed_trace = nr_distributed_trace_create();
63766376
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_NOT_SAMPLED);
@@ -6387,7 +6387,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
63876387

63886388
// 4: upstream not sampled, agent default (toss)
63896389
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6390-
txn.options.dt_sampler_parent_not_sampled = 0;
6390+
txn.options.dt_sampler_parent_not_sampled = DEFAULT;
63916391
nr_distributed_trace_destroy(&txn.distributed_trace);
63926392
txn.distributed_trace = nr_distributed_trace_create();
63936393
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_NOT_SAMPLED);
@@ -6404,7 +6404,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
64046404

64056405
// 5: upstream sampled, agent discard
64066406
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6407-
txn.options.dt_sampler_parent_sampled = -1;
6407+
txn.options.dt_sampler_parent_sampled = ALWAYS_DROP;
64086408
nr_distributed_trace_destroy(&txn.distributed_trace);
64096409
txn.distributed_trace = nr_distributed_trace_create();
64106410
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_SAMPLED);
@@ -6421,7 +6421,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
64216421

64226422
// 6: upstream sampled, agent keep
64236423
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6424-
txn.options.dt_sampler_parent_sampled = 1;
6424+
txn.options.dt_sampler_parent_sampled = ALWAYS_KEEP;
64256425
nr_distributed_trace_destroy(&txn.distributed_trace);
64266426
txn.distributed_trace = nr_distributed_trace_create();
64276427
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_SAMPLED);
@@ -6437,7 +6437,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
64376437

64386438
// 7: upstream sampled, agent default (keep)
64396439
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6440-
txn.options.dt_sampler_parent_sampled = 0;
6440+
txn.options.dt_sampler_parent_sampled = DEFAULT;
64416441
nr_distributed_trace_destroy(&txn.distributed_trace);
64426442
txn.distributed_trace = nr_distributed_trace_create();
64436443
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_SAMPLED);
@@ -6454,7 +6454,7 @@ static void test_txn_accept_distributed_trace_payload_w3c_sample_flags(void) {
64546454

64556455
// 8: upstream sampled, agent default (toss)
64566456
TEST_TXN_ACCEPT_DT_PAYLOAD_RESET
6457-
txn.options.dt_sampler_parent_sampled = 0;
6457+
txn.options.dt_sampler_parent_sampled = DEFAULT;
64586458
nr_distributed_trace_destroy(&txn.distributed_trace);
64596459
txn.distributed_trace = nr_distributed_trace_create();
64606460
nr_hashmap_update(headers, NR_PSTR("traceparent"), TRACEPARENT_SAMPLED);

0 commit comments

Comments
 (0)