Skip to content

Commit b172a75

Browse files
authored
Add starfish v1 attributes to span data/breadcrumbs (#756)
1 parent 542b6a2 commit b172a75

File tree

8 files changed

+70
-69
lines changed

8 files changed

+70
-69
lines changed

src/EventListener/TracingRequestListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function handleKernelRequestEvent(RequestEvent $event): void
5353
}
5454

5555
$context->setStartTimestamp($requestStartTime);
56-
$context->setTags($this->getTags($request));
56+
$context->setData($this->getData($request));
5757

5858
$this->hub->setSpan($this->hub->startTransaction($context));
5959
}
@@ -76,19 +76,19 @@ public function handleKernelTerminateEvent(TerminateEvent $event): void
7676
}
7777

7878
/**
79-
* Gets the tags to attach to the transaction.
79+
* Gets the data to attach to the transaction.
8080
*
8181
* @param Request $request The HTTP request
8282
*
8383
* @return array<string, string>
8484
*/
85-
private function getTags(Request $request): array
85+
private function getData(Request $request): array
8686
{
8787
$client = $this->hub->getClient();
8888
$httpFlavor = $this->getHttpFlavor($request);
8989
$tags = [
9090
'net.host.port' => (string) $request->getPort(),
91-
'http.method' => $request->getMethod(),
91+
'http.request.method' => $request->getMethod(),
9292
'http.url' => $request->getUri(),
9393
'route' => $this->getRouteName($request),
9494
];

src/EventListener/TracingSubRequestListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function handleKernelRequestEvent(RequestEvent $event): void
3737
$spanContext = new SpanContext();
3838
$spanContext->setOp('http.server');
3939
$spanContext->setDescription(sprintf('%s %s%s%s', $request->getMethod(), $request->getSchemeAndHttpHost(), $request->getBaseUrl(), $request->getPathInfo()));
40-
$spanContext->setTags([
41-
'http.method' => $request->getMethod(),
40+
$spanContext->setData([
41+
'http.request.method' => $request->getMethod(),
4242
'http.url' => $request->getUri(),
4343
'route' => $this->getRouteName($request),
4444
]);

src/Tracing/Doctrine/DBAL/TracingDriverConnection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct(
9090
) {
9191
$this->hub = $hub;
9292
$this->decoratedConnection = $decoratedConnection;
93-
$this->spanData = $this->getSpanTags($databasePlatform, $params);
93+
$this->spanData = $this->getSpanData($databasePlatform, $params);
9494
}
9595

9696
/**
@@ -258,7 +258,7 @@ private function traceFunction(string $spanOperation, string $spanDescription, \
258258
*
259259
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
260260
*/
261-
private function getSpanTags(string $databasePlatform, array $params): array
261+
private function getSpanData(string $databasePlatform, array $params): array
262262
{
263263
$data = ['db.system' => $databasePlatform];
264264

@@ -272,20 +272,20 @@ private function getSpanTags(string $databasePlatform, array $params): array
272272

273273
if (isset($params['host']) && !empty($params['host']) && !isset($params['memory'])) {
274274
if (false === filter_var($params['host'], \FILTER_VALIDATE_IP)) {
275-
$data['net.peer.name'] = $params['host'];
275+
$data['server.address'] = $params['host'];
276276
} else {
277-
$data['net.peer.ip'] = $params['host'];
277+
$data['server.address'] = $params['host'];
278278
}
279279
}
280280

281281
if (isset($params['port'])) {
282-
$data['net.peer.port'] = (string) $params['port'];
282+
$data['server.port'] = (string) $params['port'];
283283
}
284284

285285
if (isset($params['unix_socket'])) {
286-
$data['net.transport'] = 'Unix';
286+
$data['server.socket.address'] = 'Unix';
287287
} elseif (isset($params['memory'])) {
288-
$data['net.transport'] = 'inproc';
288+
$data['server.socket.address'] = 'inproc';
289289
}
290290

291291
return $data;

src/Tracing/HttpClient/AbstractTraceableHttpClient.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,18 @@ public function request(string $method, string $url, array $options = []): Respo
7575
$context = new SpanContext();
7676
$context->setOp('http.client');
7777
$context->setDescription($method . ' ' . (string) $partialUri);
78-
$context->setTags([
79-
'http.method' => $method,
78+
79+
$contextData = [
8080
'http.url' => (string) $partialUri,
81-
]);
82-
$context->setData([
83-
'http.query' => $uri->getQuery(),
84-
'http.fragment' => $uri->getFragment(),
85-
]);
81+
'http.request.method' => $method,
82+
];
83+
if ('' !== $uri->getQuery()) {
84+
$contextData['http.query'] = $uri->getQuery();
85+
}
86+
if ('' !== $uri->getFragment()) {
87+
$contextData['http.fragment'] = $uri->getFragment();
88+
}
89+
$context->setData($contextData);
8690

8791
$childSpan = $span->startChild($context);
8892

tests/EventListener/TracingRequestListenerTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
9898
$transactionContext->setSource(TransactionSource::url());
9999
$transactionContext->setOp('http.server');
100100
$transactionContext->setStartTimestamp(1613493597.010275);
101-
$transactionContext->setTags([
101+
$transactionContext->setData([
102102
'net.host.port' => '80',
103-
'http.method' => 'GET',
103+
'http.request.method' => 'GET',
104104
'http.url' => 'http://www.example.com/',
105105
'http.flavor' => '1.1',
106106
'route' => '<unknown>',
@@ -135,9 +135,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
135135
$transactionContext->setSource(TransactionSource::url());
136136
$transactionContext->setOp('http.server');
137137
$transactionContext->setStartTimestamp(1613493597.010275);
138-
$transactionContext->setTags([
138+
$transactionContext->setData([
139139
'net.host.port' => '80',
140-
'http.method' => 'GET',
140+
'http.request.method' => 'GET',
141141
'http.url' => 'http://www.example.com/',
142142
'http.flavor' => '1.1',
143143
'route' => '<unknown>',
@@ -167,9 +167,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
167167
$transactionContext->setSource(TransactionSource::url());
168168
$transactionContext->setOp('http.server');
169169
$transactionContext->setStartTimestamp(1613493597.010275);
170-
$transactionContext->setTags([
170+
$transactionContext->setData([
171171
'net.host.port' => '80',
172-
'http.method' => 'GET',
172+
'http.request.method' => 'GET',
173173
'http.url' => 'http://www.example.com/',
174174
'http.flavor' => '1.1',
175175
'route' => '<unknown>',
@@ -190,9 +190,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
190190
$transactionContext->setSource(TransactionSource::url());
191191
$transactionContext->setOp('http.server');
192192
$transactionContext->setStartTimestamp(1613493597.010275);
193-
$transactionContext->setTags([
193+
$transactionContext->setData([
194194
'net.host.port' => '80',
195-
'http.method' => 'GET',
195+
'http.request.method' => 'GET',
196196
'http.url' => 'http://127.0.0.1/',
197197
'http.flavor' => '1.1',
198198
'route' => '<unknown>',
@@ -221,9 +221,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
221221
$transactionContext->setSource(TransactionSource::route());
222222
$transactionContext->setOp('http.server');
223223
$transactionContext->setStartTimestamp(1613493597.010275);
224-
$transactionContext->setTags([
224+
$transactionContext->setData([
225225
'net.host.port' => '80',
226-
'http.method' => 'GET',
226+
'http.request.method' => 'GET',
227227
'http.url' => 'http://www.example.com/path',
228228
'http.flavor' => '1.1',
229229
'route' => 'app_homepage',
@@ -245,9 +245,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
245245
$transactionContext->setSource(TransactionSource::url());
246246
$transactionContext->setOp('http.server');
247247
$transactionContext->setStartTimestamp(1613493597.010275);
248-
$transactionContext->setTags([
248+
$transactionContext->setData([
249249
'net.host.port' => '80',
250-
'http.method' => 'GET',
250+
'http.request.method' => 'GET',
251251
'http.url' => 'http://www.example.com/path',
252252
'http.flavor' => '1.1',
253253
'route' => '/path',
@@ -269,9 +269,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
269269
$transactionContext->setSource(TransactionSource::url());
270270
$transactionContext->setOp('http.server');
271271
$transactionContext->setStartTimestamp(1613493597.010275);
272-
$transactionContext->setTags([
272+
$transactionContext->setData([
273273
'net.host.port' => '80',
274-
'http.method' => 'GET',
274+
'http.request.method' => 'GET',
275275
'http.url' => 'http://www.example.com/',
276276
'http.flavor' => '1.1',
277277
'route' => 'App\\Controller::indexAction',
@@ -293,9 +293,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
293293
$transactionContext->setSource(TransactionSource::url());
294294
$transactionContext->setOp('http.server');
295295
$transactionContext->setStartTimestamp(1613493597.010275);
296-
$transactionContext->setTags([
296+
$transactionContext->setData([
297297
'net.host.port' => '80',
298-
'http.method' => 'GET',
298+
'http.request.method' => 'GET',
299299
'http.url' => 'http://www.example.com/',
300300
'http.flavor' => '1.1',
301301
'route' => 'App\\Controller::indexAction',
@@ -317,9 +317,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
317317
$transactionContext->setSource(TransactionSource::url());
318318
$transactionContext->setOp('http.server');
319319
$transactionContext->setStartTimestamp(1613493597.010275);
320-
$transactionContext->setTags([
320+
$transactionContext->setData([
321321
'net.host.port' => '80',
322-
'http.method' => 'GET',
322+
'http.request.method' => 'GET',
323323
'http.url' => 'http://www.example.com/',
324324
'http.flavor' => '1.1',
325325
'route' => 'class@anonymous::indexAction',
@@ -341,9 +341,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
341341
$transactionContext->setSource(TransactionSource::url());
342342
$transactionContext->setOp('http.server');
343343
$transactionContext->setStartTimestamp(1613493597.010275);
344-
$transactionContext->setTags([
344+
$transactionContext->setData([
345345
'net.host.port' => '80',
346-
'http.method' => 'GET',
346+
'http.request.method' => 'GET',
347347
'http.url' => 'http://www.example.com/',
348348
'http.flavor' => '1.1',
349349
'route' => '<unknown>',
@@ -365,9 +365,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
365365
$transactionContext->setSource(TransactionSource::url());
366366
$transactionContext->setOp('http.server');
367367
$transactionContext->setStartTimestamp(1613493597.010275);
368-
$transactionContext->setTags([
368+
$transactionContext->setData([
369369
'net.host.port' => '80',
370-
'http.method' => 'GET',
370+
'http.request.method' => 'GET',
371371
'http.url' => 'http://www.example.com/',
372372
'http.flavor' => '1.1',
373373
'route' => '<unknown>',
@@ -389,9 +389,9 @@ public function handleKernelRequestEventDataProvider(): \Generator
389389
$transactionContext->setSource(TransactionSource::url());
390390
$transactionContext->setOp('http.server');
391391
$transactionContext->setStartTimestamp(1613493597.010275);
392-
$transactionContext->setTags([
392+
$transactionContext->setData([
393393
'net.host.port' => '',
394-
'http.method' => 'GET',
394+
'http.request.method' => 'GET',
395395
'http.url' => 'http://:/',
396396
'route' => '<unknown>',
397397
'net.host.name' => '',

tests/EventListener/TracingSubRequestListenerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public function handleKernelRequestEventDataProvider(): \Generator
7575
$span = new Span();
7676
$span->setOp('http.server');
7777
$span->setDescription('GET http://www.example.com/path');
78-
$span->setTags([
79-
'http.method' => 'GET',
78+
$span->setData([
79+
'http.request.method' => 'GET',
8080
'http.url' => 'http://www.example.com/path',
8181
'route' => 'App\\Controller::indexAction',
8282
]);
@@ -92,8 +92,8 @@ public function handleKernelRequestEventDataProvider(): \Generator
9292
$span = new Span();
9393
$span->setOp('http.server');
9494
$span->setDescription('GET http://www.example.com/');
95-
$span->setTags([
96-
'http.method' => 'GET',
95+
$span->setData([
96+
'http.request.method' => 'GET',
9797
'http.url' => 'http://www.example.com/',
9898
'route' => 'App\\Controller::indexAction',
9999
]);
@@ -109,8 +109,8 @@ public function handleKernelRequestEventDataProvider(): \Generator
109109
$span = new Span();
110110
$span->setOp('http.server');
111111
$span->setDescription('GET http://www.example.com/');
112-
$span->setTags([
113-
'http.method' => 'GET',
112+
$span->setData([
113+
'http.request.method' => 'GET',
114114
'http.url' => 'http://www.example.com/',
115115
'route' => 'class@anonymous::indexAction',
116116
]);
@@ -126,8 +126,8 @@ public function handleKernelRequestEventDataProvider(): \Generator
126126
$span = new Span();
127127
$span->setOp('http.server');
128128
$span->setDescription('GET http://www.example.com/');
129-
$span->setTags([
130-
'http.method' => 'GET',
129+
$span->setData([
130+
'http.request.method' => 'GET',
131131
'http.url' => 'http://www.example.com/',
132132
'route' => '<unknown>',
133133
]);

tests/Tracing/Doctrine/DBAL/TracingDriverConnectionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ public function spanDataDataProvider(): \Generator
466466
'db.system' => 'foo_platform',
467467
'db.user' => 'root',
468468
'db.name' => 'INFORMATION_SCHEMA',
469-
'net.peer.port' => '3306',
470-
'net.transport' => 'Unix',
469+
'server.port' => '3306',
470+
'server.socket.address' => 'Unix',
471471
],
472472
];
473473

@@ -482,8 +482,8 @@ public function spanDataDataProvider(): \Generator
482482
'db.system' => 'foo_platform',
483483
'db.user' => 'root',
484484
'db.name' => 'INFORMATION_SCHEMA',
485-
'net.peer.port' => '3306',
486-
'net.transport' => 'inproc',
485+
'server.port' => '3306',
486+
'server.socket.address' => 'inproc',
487487
],
488488
];
489489

@@ -493,7 +493,7 @@ public function spanDataDataProvider(): \Generator
493493
],
494494
[
495495
'db.system' => 'foo_platform',
496-
'net.peer.name' => 'localhost',
496+
'server.address' => 'localhost',
497497
],
498498
];
499499

@@ -503,7 +503,7 @@ public function spanDataDataProvider(): \Generator
503503
],
504504
[
505505
'db.system' => 'foo_platform',
506-
'net.peer.ip' => '127.0.0.1',
506+
'server.address' => '127.0.0.1',
507507
],
508508
];
509509
}

0 commit comments

Comments
 (0)