Skip to content

Commit

Permalink
Add starfish v1 attributes to span data/breadcrumbs (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Aug 10, 2023
1 parent 51fb4c7 commit 95d3d3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/Tracing/GuzzleTracingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function trace(?HubInterface $hub = null): Closure
$spanContext->setOp('http.client');
$spanContext->setDescription($request->getMethod() . ' ' . (string) $partialUri);
$spanContext->setData([
'http.request.method' => $request->getMethod(),
'http.query' => $request->getUri()->getQuery(),
'http.fragment' => $request->getUri()->getFragment(),
]);
Expand Down Expand Up @@ -78,8 +79,8 @@ public static function trace(?HubInterface $hub = null): Closure

$breadcrumbData = [
'url' => (string) $partialUri,
'method' => $request->getMethod(),
'request_body_size' => $request->getBody()->getSize(),
'http.request.method' => $request->getMethod(),
'http.request.body.size' => $request->getBody()->getSize(),
];
if ('' !== $request->getUri()->getQuery()) {
$breadcrumbData['http.query'] = $request->getUri()->getQuery();
Expand All @@ -91,8 +92,8 @@ public static function trace(?HubInterface $hub = null): Closure
if (null !== $response) {
$childSpan->setStatus(SpanStatus::createFromHttpStatusCode($response->getStatusCode()));

$breadcrumbData['status_code'] = $response->getStatusCode();
$breadcrumbData['response_body_size'] = $response->getBody()->getSize();
$breadcrumbData['http.response.status_code'] = $response->getStatusCode();
$breadcrumbData['http.response.body.size'] = $response->getBody()->getSize();
} else {
$childSpan->setStatus(SpanStatus::internalError());
}
Expand Down
28 changes: 14 additions & 14 deletions tests/Tracing/GuzzleTracingMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ public static function traceDataProvider(): iterable
new Response(),
[
'url' => 'https://www.example.com',
'method' => 'GET',
'request_body_size' => 0,
'status_code' => 200,
'response_body_size' => 0,
'http.request.method' => 'GET',
'http.request.body.size' => 0,
'http.response.status_code' => 200,
'http.response.body.size' => 0,
],
];

Expand All @@ -282,12 +282,12 @@ public static function traceDataProvider(): iterable
new Response(),
[
'url' => 'https://www.example.com',
'method' => 'GET',
'request_body_size' => 0,
'http.request.method' => 'GET',
'http.request.body.size' => 0,
'http.query' => 'query=string',
'http.fragment' => 'fragment=1',
'status_code' => 200,
'response_body_size' => 0,
'http.response.status_code' => 200,
'http.response.body.size' => 0,
],
];

Expand All @@ -296,10 +296,10 @@ public static function traceDataProvider(): iterable
new Response(403, [], 'sentry'),
[
'url' => 'https://www.example.com',
'method' => 'POST',
'request_body_size' => 10,
'status_code' => 403,
'response_body_size' => 6,
'http.request.method' => 'POST',
'http.request.body.size' => 10,
'http.response.status_code' => 403,
'http.response.body.size' => 6,
],
];

Expand All @@ -308,8 +308,8 @@ public static function traceDataProvider(): iterable
new \Exception(),
[
'url' => 'https://www.example.com',
'method' => 'GET',
'request_body_size' => 0,
'http.request.method' => 'GET',
'http.request.body.size' => 0,
],
];
}
Expand Down

0 comments on commit 95d3d3a

Please sign in to comment.