Skip to content

Commit 44440df

Browse files
Merge remote-tracking branch 'upstream/main' into spi/laravel
2 parents c9a83fe + 2d2c37b commit 44440df

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

src/Aws/src/AwsSdkInstrumentation.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,17 @@ public function activate(): bool
109109

110110
/** @psalm-suppress PossiblyInvalidArgument */
111111
$end_middleware = Middleware::mapResult(function (ResultInterface $result) {
112-
$this->span->setAttributes([
113-
'http.status_code' => $result['@metadata']['statusCode'], //@phan-suppress-current-line PhanTypeMismatchDimFetch
114-
]);
112+
/**
113+
* Some AWS SDK Funtions, such as S3Client->getObjectUrl() do not actually perform on the wire comms
114+
* with AWS Servers, and therefore do not return with a populated AWS\Result object with valid @metadata
115+
* Check for the presence of @metadata before extracting status code as these calls are still
116+
* instrumented.
117+
*/
118+
if (isset($result['@metadata'])) {
119+
$this->span->setAttributes([
120+
'http.status_code' => $result['@metadata']['statusCode'], //@phan-suppress-current-line PhanTypeMismatchDimFetch
121+
]);
122+
}
115123

116124
$this->span->end();
117125
$this->scope->detach();

src/Instrumentation/Guzzle/src/GuzzleInstrumentation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace OpenTelemetry\Contrib\Instrumentation\Guzzle;
66

77
use function get_cfg_var;
8-
use GuzzleHttp\ClientInterface;
8+
use GuzzleHttp\Client;
99
use GuzzleHttp\Promise\PromiseInterface;
1010
use OpenTelemetry\API\Globals;
1111
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
@@ -35,9 +35,9 @@ public static function register(): void
3535
);
3636

3737
hook(
38-
ClientInterface::class,
38+
Client::class,
3939
'transfer',
40-
pre: static function (ClientInterface $client, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation): array {
40+
pre: static function (Client $client, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation): array {
4141
$request = $params[0];
4242
assert($request instanceof RequestInterface);
4343

@@ -84,7 +84,7 @@ public static function register(): void
8484

8585
return [$request];
8686
},
87-
post: static function (ClientInterface $client, array $params, PromiseInterface $promise, ?Throwable $exception): void {
87+
post: static function (Client $client, array $params, PromiseInterface $promise, ?Throwable $exception): void {
8888
$scope = Context::storage()->scope();
8989
$scope?->detach();
9090

src/Instrumentation/Symfony/src/HttpClientInstrumentation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static function register(): void
5252
->tracer()
5353
->spanBuilder(\sprintf('%s', $params[0]))
5454
->setSpanKind(SpanKind::KIND_CLIENT)
55+
->setAttribute(TraceAttributes::PEER_SERVICE, parse_url((string) $params[1])['host'] ?? null)
5556
->setAttribute(TraceAttributes::URL_FULL, (string) $params[1])
5657
->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $params[0])
5758
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)

src/Instrumentation/Symfony/src/MessengerInstrumentation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function register(): void
5858
$builder = $instrumentation
5959
->tracer()
6060
->spanBuilder(\sprintf('DISPATCH %s', $messageClass))
61-
->setSpanKind(SpanKind::KIND_INTERNAL)
61+
->setSpanKind(SpanKind::KIND_PRODUCER)
6262
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
6363
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
6464
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
@@ -125,7 +125,7 @@ public static function register(): void
125125
$builder = $instrumentation
126126
->tracer()
127127
->spanBuilder(\sprintf('SEND %s', $messageClass))
128-
->setSpanKind(SpanKind::KIND_INTERNAL)
128+
->setSpanKind(SpanKind::KIND_PRODUCER)
129129
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
130130
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
131131
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)

src/Instrumentation/Symfony/src/SymfonyInstrumentation.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public static function register(): void
104104
$span->recordException($exception, [
105105
TraceAttributes::EXCEPTION_ESCAPED => true,
106106
]);
107-
$span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage());
107+
if (null !== $response && $response->getStatusCode() >= Response::HTTP_INTERNAL_SERVER_ERROR) {
108+
$span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage());
109+
}
108110
}
109111

110112
if (null === $response) {
@@ -159,8 +161,7 @@ public static function register(): void
159161
Span::getCurrent()
160162
->recordException($throwable, [
161163
TraceAttributes::EXCEPTION_ESCAPED => true,
162-
])
163-
->setStatus(StatusCode::STATUS_ERROR, $throwable->getMessage());
164+
]);
164165

165166
return $params;
166167
},

src/Instrumentation/Symfony/tests/Integration/HttpClientInstrumentationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function test_send_request(string $method, string $uri, int $statusCode,
4848
$this->assertNotNull($requestHeaders['HTTP_TRACEPARENT']);
4949
}
5050

51+
$this->assertTrue($span->getAttributes()->has(TraceAttributes::PEER_SERVICE));
52+
$this->assertSame(parse_url($uri)['host'] ?? null, $span->getAttributes()->get(TraceAttributes::PEER_SERVICE));
5153
$this->assertTrue($span->getAttributes()->has(TraceAttributes::URL_FULL));
5254
$this->assertSame($uri, $span->getAttributes()->get(TraceAttributes::URL_FULL));
5355
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_REQUEST_METHOD));

src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function sendDataProvider(): array
157157
[
158158
new SendEmailMessage('Hello Again'),
159159
'SEND OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage',
160-
SpanKind::KIND_INTERNAL,
160+
SpanKind::KIND_PRODUCER,
161161
[
162162
MessengerInstrumentation::ATTRIBUTE_MESSENGER_TRANSPORT => class_exists('Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport') ? 'Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport' : 'Symfony\Component\Messenger\Transport\InMemoryTransport',
163163
MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE => 'OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage',
@@ -172,7 +172,7 @@ public function dispatchDataProvider(): array
172172
[
173173
new SendEmailMessage('Hello Again'),
174174
'DISPATCH OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage',
175-
SpanKind::KIND_INTERNAL,
175+
SpanKind::KIND_PRODUCER,
176176
[
177177
MessengerInstrumentation::ATTRIBUTE_MESSENGER_BUS => 'Symfony\Component\Messenger\MessageBus',
178178
MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE => 'OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage',

0 commit comments

Comments
 (0)