Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenTracing test flakiness #2867

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions tests/Frameworks/Custom/OpenTelemetry/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

require __DIR__ . '/vendor/autoload.php';

try {
$tracerProvider = new TracerProvider();
$tracer = $tracerProvider->getTracer('foo');
$span = $tracer->spanBuilder('barbar')
->startSpan()
;
$span->end();
} finally {
\dd_trace_internal_fn("finalize_telemetry");
}
$tracerProvider = new TracerProvider();
$tracer = $tracerProvider->getTracer('foo');
$span = $tracer->spanBuilder('barbar')
->startSpan()
;
$span->end();
20 changes: 8 additions & 12 deletions tests/Frameworks/Custom/OpenTracing/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

require __DIR__ . '/vendor/autoload.php';

try {
$otTracer = new \DDTrace\OpenTracer1\Tracer(\DDTrace\GlobalTracer::get());
$scope = $otTracer->startActiveSpan('web.request');
$span = $scope->getSpan();
$span->setTag('service.name', 'service_name');
$span->setTag('resource.name', 'resource_name');
$span->setTag('span.type', 'web');
$span->setTag('http.method', $_SERVER['REQUEST_METHOD']);
$span->finish();
} finally {
\dd_trace_internal_fn("finalize_telemetry");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling finalize_telemetry manually causes the metrics (like spans_created) to be sent twice.
Once with service_name as service name, the other with index.php

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think back in the old times finalize_telemetry was final :-) (But I think that matters no longer.)

}
$otTracer = new \DDTrace\OpenTracer1\Tracer(\DDTrace\GlobalTracer::get());
$scope = $otTracer->startActiveSpan('web.request');
$span = $scope->getSpan();
$span->setTag('service.name', 'service_name');
$span->setTag('resource.name', 'resource_name');
$span->setTag('span.type', 'web');
$span->setTag('http.method', $_SERVER['REQUEST_METHOD']);
$span->finish();
21 changes: 14 additions & 7 deletions tests/OpenTracing/InternalTelemetryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ public function testInternalMetricWithOpenTracing()

$this->executeCommand();

$requests = $this->retrieveDumpedData($this->untilTelemetryRequest("spans_created"));
$requests = $this->retrieveDumpedData($this->untilTelemetryRequest("spans_created"), true);

$payloads = $this->readTelemetryPayloads($requests);
$isMetric = function (array $payload) {
return 'generate-metrics' === $payload['request_type'];
};
$metrics = array_values(array_filter($payloads, $isMetric));
$metricRequests = array_values(array_filter($payloads, $isMetric));

$this->assertCount(1, $metrics);
$this->assertEquals("generate-metrics", $metrics[0]["request_type"]);
$this->assertEquals("tracers", $metrics[0]["payload"]["series"][0]["namespace"]);
$this->assertEquals("spans_created", $metrics[0]["payload"]["series"][0]["metric"]);
$this->assertEquals(["integration_name:opentracing"], $metrics[0]["payload"]["series"][0]["tags"]);
$this->assertCount(1, $metricRequests);
$this->assertEquals("generate-metrics", $metricRequests[0]["request_type"]);

$metrics = [];
foreach ($metricRequests[0]['payload']['series'] as $serie) {
$metrics[$serie['metric']][] = $serie;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also receive other metrics (like logs_created), that's why we group them

}

$this->assertCount(1, $metrics['spans_created']);
$this->assertEquals("tracers", $metrics['spans_created'][0]["namespace"]);
$this->assertEquals("spans_created", $metrics['spans_created'][0]["metric"]);
$this->assertEquals(["integration_name:opentracing"], $metrics['spans_created'][0]["tags"]);
}
}
Loading