Skip to content

Commit 2531886

Browse files
committed
feat(tracer): deprecate App Analytics API to a no-op
The user-facing App Analytics API is now a deprecated no-op: it remains callable (Tag::ANALYTICS_KEY, TraceAnalyticsProcessor, DD_TRACE_ANALYTICS_ENABLED stay defined) but no longer applies any behavior nor emits the _dd1.sr.eausr metric in-process or on the wire. - serializer.c: drop the DD_TRACE_ANALYTICS_ENABLED/web-analytics emission, stop converting the analytics.event meta key to the metric (still consumed), and skip _dd1.sr.eausr in the metrics serialization loop. - TraceAnalyticsProcessor::normalizeAnalyticsValue is now an empty no-op; Tag::ANALYTICS_KEY, the processor, and the api stubs are marked @deprecated. - Tests rewritten to assert the API is callable and emits no _dd1.sr.eausr.
1 parent 55c6254 commit 2531886

10 files changed

Lines changed: 65 additions & 148 deletions

File tree

src/DDTrace/Processing/TraceAnalyticsProcessor.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,19 @@
22

33
namespace DDTrace\Processing;
44

5-
use DDTrace\Data\Span as DataSpan;
6-
use DDTrace\Tag;
7-
85
/**
9-
* A span processor in charge of adding the trace analytics client config metric when appropriate.
10-
*
11-
* NOTE: this may be transformer into a filter for consistency with other tracers, but for now we did not implement
12-
* any filtering functionality so giving it such name as of now might be misleading.
6+
* @deprecated App Analytics is deprecated and no longer has any effect.
137
*/
148
final class TraceAnalyticsProcessor
159
{
1610
/**
17-
* @param array $metrics
18-
* @param bool|float $value
19-
*/
11+
* @deprecated App Analytics is deprecated. This is now a no-op and does not
12+
* modify $metrics or emit the _dd1.sr.eausr metric.
13+
*
14+
* @param array $metrics
15+
* @param bool|float $value
16+
*/
2017
public static function normalizeAnalyticsValue(&$metrics, $value)
2118
{
22-
if (true === $value) {
23-
$metrics[Tag::ANALYTICS_KEY] = 1.0;
24-
} elseif (false === $value) {
25-
unset($metrics[Tag::ANALYTICS_KEY]);
26-
} elseif (is_numeric($value) && 0 <= $value && $value <= 1) {
27-
$metrics[Tag::ANALYTICS_KEY] = (float)$value;
28-
}
2919
}
3020
}

src/api/Tag.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Tag
3838
const TARGET_HOST = 'out.host';
3939
const TARGET_PORT = 'out.port';
4040
const BYTES_OUT = 'net.out.bytes';
41+
/** @deprecated App Analytics is deprecated; setting this metric no longer has any effect. */
4142
const ANALYTICS_KEY = '_dd1.sr.eausr';
4243
const HOSTNAME = '_dd.hostname';
4344
const ORIGIN = '_dd.origin';

src/ddtrace_php_api.stubs.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,14 @@ public static function createFromLocalSpan(\DDTrace\SpanData $span, bool $sample
301301
}
302302
namespace DDTrace\Processing {
303303
/**
304-
* A span processor in charge of adding the trace analytics client config metric when appropriate.
305-
*
306-
* NOTE: this may be transformer into a filter for consistency with other tracers, but for now we did not implement
307-
* any filtering functionality so giving it such name as of now might be misleading.
304+
* @deprecated App Analytics is deprecated and no longer has any effect.
308305
*/
309306
final class TraceAnalyticsProcessor
310307
{
311308
/**
309+
* @deprecated App Analytics is deprecated. This is now a no-op and does not
310+
* modify $metrics or emit the _dd1.sr.eausr metric.
311+
*
312312
* @param array $metrics
313313
* @param bool|float $value
314314
*/
@@ -2241,6 +2241,7 @@ class Tag
22412241
const TARGET_HOST = 'out.host';
22422242
const TARGET_PORT = 'out.port';
22432243
const BYTES_OUT = 'net.out.bytes';
2244+
/** @deprecated App Analytics is deprecated; setting this metric no longer has any effect. */
22442245
const ANALYTICS_KEY = '_dd1.sr.eausr';
22452246
const HOSTNAME = '_dd.hostname';
22462247
const ORIGIN = '_dd.origin';

tests/OpenTelemetry/Integration/API/TracerTest.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -339,30 +339,33 @@ public function providerSpanKind()
339339
public function providerAnalyticsEvent()
340340
{
341341
return [
342-
["true", 1],
343-
["TRUE", 1],
344-
["True", 1],
345-
["false", 0],
346-
["False", 0],
347-
["FALSE", 0],
348-
["something-else", null],
349-
[True, 1],
350-
[False, 0],
351-
['t', 1],
352-
['T', 1],
353-
['f', 0],
354-
['F', 0],
355-
['1', 1],
356-
['0', 0],
357-
['fAlse', null],
358-
['trUe', null]
342+
["true"],
343+
["TRUE"],
344+
["True"],
345+
["false"],
346+
["False"],
347+
["FALSE"],
348+
["something-else"],
349+
[True],
350+
[False],
351+
['t'],
352+
['T'],
353+
['f'],
354+
['F'],
355+
['1'],
356+
['0'],
357+
['fAlse'],
358+
['trUe']
359359
];
360360
}
361361

362362
/**
363+
* App Analytics is deprecated and a no-op: analytics.event no longer emits the
364+
* _dd1.sr.eausr metric, but setting it must remain callable without error.
365+
*
363366
* @dataProvider providerAnalyticsEvent
364367
*/
365-
public function testReservedAttributesOverridesAnalyticsEvent($analyticsEventValue, $expectedMetricValue)
368+
public function testAnalyticsEventIsDeprecatedNoOp($analyticsEventValue)
366369
{
367370
$traces = $this->isolateTracer(function () use ($analyticsEventValue) {
368371
$tracer = self::getTracer();
@@ -374,12 +377,7 @@ public function testReservedAttributesOverridesAnalyticsEvent($analyticsEventVal
374377
});
375378

376379
$span = $traces[0][0];
377-
if ($expectedMetricValue !== null) {
378-
$actualMetricValue = $span['metrics']['_dd1.sr.eausr'];
379-
$this->assertEquals($expectedMetricValue, $actualMetricValue);
380-
} else {
381-
$this->assertArrayNotHasKey('_dd1.sr.eausr', $span['metrics']);
382-
}
380+
$this->assertArrayNotHasKey('_dd1.sr.eausr', $span['metrics']);
383381
}
384382

385383
public function testSpanErrorStatus()

tests/OpenTelemetry/Integration/InteroperabilityTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,8 @@ public function testSpecialAttributes()
838838
$this->assertSame('new.name', $span['resource']);
839839
$this->assertSame('new.service.name', $span['service']);
840840
$this->assertSame('new.span.type', $span['type']);
841-
$this->assertEquals(1.0, $span['metrics']['_dd1.sr.eausr']);
841+
// App Analytics is deprecated and a no-op: analytics.event no longer emits _dd1.sr.eausr.
842+
$this->assertArrayNotHasKey('_dd1.sr.eausr', $span['metrics']);
842843
}
843844

844845
public function testHasEnded()

tests/Unit/Processing/TraceAnalyticsProcessorTest.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,35 @@
88

99
final class TraceAnalyticsProcessorTest extends BaseTestCase
1010
{
11-
public function testTrueIs1()
11+
public function testTrueIsNoOp()
1212
{
13-
$metrics = [
14-
];
13+
$metrics = [];
1514
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, true);
16-
$this->assertSame(1.0, $metrics[Tag::ANALYTICS_KEY]);
15+
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $metrics);
1716
}
1817

19-
public function testFalseIsUnset()
18+
public function testFalseIsNoOp()
2019
{
2120
$metrics = [
2221
Tag::ANALYTICS_KEY => 0.2,
2322
];
2423
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, false);
25-
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $metrics);
24+
$this->assertSame(0.2, $metrics[Tag::ANALYTICS_KEY]);
2625
}
2726

28-
public function testNumericValueBetweenZeroAndOne()
29-
{
30-
$metrics = [
31-
];
32-
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, 0.4);
33-
$this->assertSame(0.4, $metrics[Tag::ANALYTICS_KEY]);
34-
}
35-
36-
public function testValueLessThan0()
27+
public function testNumericValueIsNoOp()
3728
{
3829
$metrics = [];
39-
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, -0.1);
30+
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, 0.4);
4031
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $metrics);
4132
}
4233

43-
public function testValueGreaterThan1()
34+
public function testDoesNotMutateExistingMetrics()
4435
{
45-
$metrics = [];
36+
$metrics = ['foo' => 1.0];
37+
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, true);
38+
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, -0.1);
4639
TraceAnalyticsProcessor::normalizeAnalyticsValue($metrics, 1.1);
47-
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $metrics);
40+
$this->assertSame(['foo' => 1.0], $metrics);
4841
}
4942
}

tests/Unit/SpanTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,45 +273,45 @@ public function testMetricsSetGet()
273273
$this->assertSame(1.0, $span->getMetrics()['exists']);
274274
}
275275

276-
public function testTraceAnalyticsConfigEnabledByTag()
276+
public function testTraceAnalyticsByTagIsDeprecatedNoOp()
277277
{
278278
$span = $this->createSpan();
279279
$span->setTag(Tag::ANALYTICS_KEY, 0.5);
280280

281-
$this->assertSame(0.5, $span->getMetrics()[Tag::ANALYTICS_KEY]);
281+
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $span->getMetrics());
282282
}
283283

284-
public function testTraceAnalyticsConfigEnabledByMetric()
284+
public function testTraceAnalyticsByMetricIsDeprecatedNoOp()
285285
{
286286
$span = $this->createSpan();
287287
$span->setMetric(Tag::ANALYTICS_KEY, 0.5);
288288

289-
$this->assertSame(0.5, $span->getMetrics()[Tag::ANALYTICS_KEY]);
289+
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $span->getMetrics());
290290
}
291291

292-
public function testTraceAnalyticsConfigEnabledTrueResultTo1()
292+
public function testTraceAnalyticsTrueIsDeprecatedNoOp()
293293
{
294294
$span = $this->createSpan();
295295
$span->setMetric(Tag::ANALYTICS_KEY, true);
296296

297-
$this->assertSame(1.0, $span->getMetrics()[Tag::ANALYTICS_KEY]);
297+
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $span->getMetrics());
298298
}
299299

300-
public function testTraceAnalyticsConfigDisabled()
300+
public function testTraceAnalyticsFalseIsDeprecatedNoOp()
301301
{
302302
$span = $this->createSpan();
303303
$span->setMetric(Tag::ANALYTICS_KEY, true);
304-
$this->assertSame(1.0, $span->getMetrics()[Tag::ANALYTICS_KEY]);
305-
306304
$span->setMetric(Tag::ANALYTICS_KEY, false);
305+
307306
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $span->getMetrics());
308307
}
309308

310-
public function testTraceAnalyticsConfigSpecificRate()
309+
public function testTraceAnalyticsSpecificRateIsDeprecatedNoOp()
311310
{
312311
$span = $this->createSpan();
313312
$span->setMetric(Tag::ANALYTICS_KEY, 0.3);
314-
$this->assertSame(0.3, $span->getMetrics()[Tag::ANALYTICS_KEY]);
313+
314+
$this->assertArrayNotHasKey(Tag::ANALYTICS_KEY, $span->getMetrics());
315315
}
316316

317317
public function testSpanCreationDoesNotInterfereWithDeterministicRandomness()

tests/ext/test_special_attributes.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var_dump(dd_clean_spans());
3333
--EXPECTF--
3434
array(1) {
3535
[0]=>
36-
array(11) {
36+
array(10) {
3737
["trace_id"]=>
3838
string(%d) "%d"
3939
["span_id"]=>
@@ -59,10 +59,5 @@ array(1) {
5959
["_dd.svc_src"]=>
6060
string(1) "m"
6161
}
62-
["metrics"]=>
63-
array(1) {
64-
["_dd1.sr.eausr"]=>
65-
float(1)
66-
}
6762
}
6863
}

tests/ext/test_special_attributes_bis.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var_dump(dd_clean_spans());
3434
--EXPECTF--
3535
array(1) {
3636
[0]=>
37-
array(11) {
37+
array(10) {
3838
["trace_id"]=>
3939
string(%d) "%d"
4040
["span_id"]=>
@@ -60,10 +60,5 @@ array(1) {
6060
["_dd.svc_src"]=>
6161
string(1) "m"
6262
}
63-
["metrics"]=>
64-
array(1) {
65-
["_dd1.sr.eausr"]=>
66-
float(1)
67-
}
6863
}
6964
}

tracer/serializer.c

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,6 @@ void ddtrace_set_root_span_properties(ddtrace_root_span_data *span) {
908908
DATADOG_G(asm_event_emitted) = false; // we attach this to the first root span after the asm event was detected (if there was none while emitted)
909909
}
910910

911-
ddtrace_integration *web_integration = &ddtrace_integrations[DDTRACE_INTEGRATION_WEB];
912-
if (get_DD_TRACE_ANALYTICS_ENABLED() || web_integration->is_analytics_enabled()) {
913-
zval sample_rate;
914-
ZVAL_DOUBLE(&sample_rate, web_integration->get_sample_rate());
915-
zend_hash_str_add_new(metrics, ZEND_STRL("_dd1.sr.eausr"), &sample_rate);
916-
}
917-
918911
if (get_DD_TRACE_GIT_METADATA_ENABLED()) {
919912
ddtrace_inject_git_metadata(&span->property_git_metadata);
920913
}
@@ -1431,46 +1424,6 @@ void ddtrace_shutdown_span_sampling_limiter(void) {
14311424
zend_hash_destroy(&dd_span_sampling_limiters);
14321425
}
14331426

1434-
// ParseBool returns the boolean value represented by the string.
1435-
// It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
1436-
// Any other value returns -1.
1437-
static zend_always_inline double strconv_parse_bool(zend_string *str) {
1438-
// See Go's strconv.ParseBool
1439-
// https://cs.opensource.google/go/go/+/refs/tags/go1.21.5:src/strconv/atob.go;drc=1f137052e4a20dbd302f947b1cf34cdf4b427d65;l=10
1440-
size_t len = ZSTR_LEN(str);
1441-
if (len == 0) {
1442-
return -1;
1443-
}
1444-
1445-
char *s = ZSTR_VAL(str);
1446-
switch (len) {
1447-
case 1:
1448-
switch (s[0]) {
1449-
case '1':
1450-
case 't':
1451-
case 'T':
1452-
return 1;
1453-
case '0':
1454-
case 'f':
1455-
case 'F':
1456-
return 0;
1457-
}
1458-
break;
1459-
case 4:
1460-
if (strcmp(s, "TRUE") == 0 || strcmp(s, "True") == 0 || strcmp(s, "true") == 0) {
1461-
return 1;
1462-
}
1463-
break;
1464-
case 5:
1465-
if (strcmp(s, "FALSE") == 0 || strcmp(s, "False") == 0 || strcmp(s, "false") == 0) {
1466-
return 0;
1467-
}
1468-
break;
1469-
}
1470-
1471-
return -1;
1472-
}
1473-
14741427
void transfer_meta_data(ddog_SpanBytes *source, ddog_SpanBytes *destination, const char *key, bool delete_source) {
14751428
ddog_CharSlice value = ddog_get_span_meta_str(source, key);
14761429
if (value.len > 0) {
@@ -1811,18 +1764,7 @@ ddog_SpanBytes *ddtrace_serialize_span_to_rust_span(ddtrace_span_data *span, ddo
18111764
zend_hash_str_del(meta, ZEND_STRL("span.type"));
18121765
}
18131766

1814-
zval *analytics_event = zend_hash_str_find(meta, ZEND_STRL("analytics.event"));
1815-
if (analytics_event) {
1816-
if (Z_TYPE_P(analytics_event) == IS_STRING) {
1817-
double parsed_analytics_event = strconv_parse_bool(Z_STR_P(analytics_event));
1818-
if (parsed_analytics_event >= 0) {
1819-
ddog_add_span_metrics_str(rust_span, "_dd1.sr.eausr", parsed_analytics_event);
1820-
}
1821-
} else {
1822-
ddog_add_span_metrics_str(rust_span, "_dd1.sr.eausr", zval_get_double(analytics_event));
1823-
}
1824-
zend_hash_str_del(meta, ZEND_STRL("analytics.event"));
1825-
}
1767+
zend_hash_str_del(meta, ZEND_STRL("analytics.event"));
18261768

18271769
if (span_sampling_applied) {
18281770
ddog_add_span_metrics_str(rust_span, "_dd.span_sampling.mechanism", 8.0);
@@ -1984,7 +1926,8 @@ ddog_SpanBytes *ddtrace_serialize_span_to_rust_span(ddtrace_span_data *span, ddo
19841926
zend_string *str_key;
19851927
zval *val;
19861928
ZEND_HASH_FOREACH_STR_KEY_VAL_IND(metrics, str_key, val) {
1987-
if (str_key && !ddog_has_span_metrics_zstr(rust_span, str_key)) {
1929+
if (str_key && !zend_string_equals_literal(str_key, "_dd1.sr.eausr") &&
1930+
!ddog_has_span_metrics_zstr(rust_span, str_key)) {
19881931
dd_serialize_array_metrics_recursively(rust_span, str_key, val);
19891932
}
19901933
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)