Skip to content

Commit 9e3662d

Browse files
authored
Remove support for traceparent (#1833)
1 parent 259154f commit 9e3662d

9 files changed

Lines changed: 9 additions & 154 deletions

src/Tracing/GuzzleTracingMiddleware.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use function Sentry\getBaggage;
1717
use function Sentry\getTraceparent;
18-
use function Sentry\getW3CTraceparent;
1918

2019
/**
2120
* This handler traces each outgoing HTTP request by recording performance data.
@@ -66,7 +65,6 @@ public static function trace(?HubInterface $hub = null): \Closure
6665
if (self::shouldAttachTracingHeaders($client, $request)) {
6766
$request = $request
6867
->withHeader('sentry-trace', getTraceparent())
69-
->withHeader('traceparent', getW3CTraceparent())
7068
->withHeader('baggage', getBaggage());
7169
}
7270

src/Tracing/PropagationContext.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ final class PropagationContext
1111
{
1212
private const SENTRY_TRACEPARENT_HEADER_REGEX = '/^[ \\t]*(?<trace_id>[0-9a-f]{32})?-?(?<span_id>[0-9a-f]{16})?-?(?<sampled>[01])?[ \\t]*$/i';
1313

14-
private const W3C_TRACEPARENT_HEADER_REGEX = '/^[ \\t]*(?<version>[0]{2})?-?(?<trace_id>[0-9a-f]{32})?-?(?<span_id>[0-9a-f]{16})?-?(?<sampled>[01]{2})?[ \\t]*$/i';
15-
1614
/**
1715
* @var TraceId The trace id
1816
*/
@@ -81,10 +79,12 @@ public function toTraceparent(): string
8179

8280
/**
8381
* Returns a string that can be used for the W3C `traceparent` header & meta tag.
82+
*
83+
* @deprecated since version 4.12. To be removed in version 5.0.
8484
*/
8585
public function toW3CTraceparent(): string
8686
{
87-
return \sprintf('00-%s-%s-00', (string) $this->traceId, (string) $this->spanId);
87+
return '';
8888
}
8989

9090
/**
@@ -204,21 +204,6 @@ private static function parseTraceparentAndBaggage(string $traceparent, string $
204204
$context->parentSampled = $matches['sampled'] === '1';
205205
$hasSentryTrace = true;
206206
}
207-
} elseif (preg_match(self::W3C_TRACEPARENT_HEADER_REGEX, $traceparent, $matches)) {
208-
if (!empty($matches['trace_id'])) {
209-
$context->traceId = new TraceId($matches['trace_id']);
210-
$hasSentryTrace = true;
211-
}
212-
213-
if (!empty($matches['span_id'])) {
214-
$context->parentSpanId = new SpanId($matches['span_id']);
215-
$hasSentryTrace = true;
216-
}
217-
218-
if (isset($matches['sampled'])) {
219-
$context->parentSampled = $matches['sampled'] === '01';
220-
$hasSentryTrace = true;
221-
}
222207
}
223208

224209
$samplingContext = DynamicSamplingContext::fromHeader($baggage);

src/Tracing/Span.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -565,19 +565,12 @@ public function toTraceparent(): string
565565

566566
/**
567567
* Returns a string that can be used for the W3C `traceparent` header & meta tag.
568+
*
569+
* @deprecated since version 4.12. To be removed in version 5.0.
568570
*/
569571
public function toW3CTraceparent(): string
570572
{
571-
$sampled = '';
572-
573-
if ($this->sampled !== null) {
574-
$sampled = $this->sampled ? '01' : '00';
575-
} else {
576-
// If no sampling decision was made, set the flag to 00
577-
$sampled = '00';
578-
}
579-
580-
return \sprintf('00-%s-%s-%s', (string) $this->traceId, (string) $this->spanId, $sampled);
573+
return '';
581574
}
582575

583576
/**

src/Tracing/TransactionContext.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ final class TransactionContext extends SpanContext
88
{
99
private const SENTRY_TRACEPARENT_HEADER_REGEX = '/^[ \\t]*(?<trace_id>[0-9a-f]{32})?-?(?<span_id>[0-9a-f]{16})?-?(?<sampled>[01])?[ \\t]*$/i';
1010

11-
private const W3C_TRACEPARENT_HEADER_REGEX = '/^[ \\t]*(?<version>[0]{2})?-?(?<trace_id>[0-9a-f]{32})?-?(?<span_id>[0-9a-f]{16})?-?(?<sampled>[01]{2})?[ \\t]*$/i';
12-
1311
public const DEFAULT_NAME = '<unlabeled transaction>';
1412

1513
/**
@@ -166,21 +164,6 @@ private static function parseTraceAndBaggage(string $sentryTrace, string $baggag
166164
$context->parentSampled = $matches['sampled'] === '1';
167165
$hasSentryTrace = true;
168166
}
169-
} elseif (preg_match(self::W3C_TRACEPARENT_HEADER_REGEX, $sentryTrace, $matches)) {
170-
if (!empty($matches['trace_id'])) {
171-
$context->traceId = new TraceId($matches['trace_id']);
172-
$hasSentryTrace = true;
173-
}
174-
175-
if (!empty($matches['span_id'])) {
176-
$context->parentSpanId = new SpanId($matches['span_id']);
177-
$hasSentryTrace = true;
178-
}
179-
180-
if (isset($matches['sampled'])) {
181-
$context->parentSampled = $matches['sampled'] === '01';
182-
$hasSentryTrace = true;
183-
}
184167
}
185168

186169
$samplingContext = DynamicSamplingContext::fromHeader($baggage);

src/functions.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,29 +305,12 @@ function getTraceparent(): string
305305
* or HTML meta tag value.
306306
* This function is context aware, as in it either returns the traceparent based
307307
* on the current span, or the scope's propagation context.
308+
*
309+
* @deprecated since version 4.12. To be removed in version 5.0.
308310
*/
309311
function getW3CTraceparent(): string
310312
{
311-
$hub = SentrySdk::getCurrentHub();
312-
$client = $hub->getClient();
313-
314-
if ($client !== null) {
315-
$options = $client->getOptions();
316-
317-
if ($options !== null && $options->isTracingEnabled()) {
318-
$span = SentrySdk::getCurrentHub()->getSpan();
319-
if ($span !== null) {
320-
return $span->toW3CTraceparent();
321-
}
322-
}
323-
}
324-
325-
$traceParent = '';
326-
$hub->configureScope(function (Scope $scope) use (&$traceParent) {
327-
$traceParent = $scope->getPropagationContext()->toW3CTraceparent();
328-
});
329-
330-
return $traceParent;
313+
return '';
331314
}
332315

333316
/**

tests/FunctionsTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use function Sentry\continueTrace;
4040
use function Sentry\getBaggage;
4141
use function Sentry\getTraceparent;
42-
use function Sentry\getW3CTraceparent;
4342
use function Sentry\init;
4443
use function Sentry\startTransaction;
4544
use function Sentry\trace;
@@ -455,50 +454,6 @@ public function testTraceparentWithTracingEnabled(): void
455454
$this->assertSame('566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8', $traceParent);
456455
}
457456

458-
public function testW3CTraceparentWithTracingDisabled(): void
459-
{
460-
$propagationContext = PropagationContext::fromDefaults();
461-
$propagationContext->setTraceId(new TraceId('566e3688a61d4bc888951642d6f14a19'));
462-
$propagationContext->setSpanId(new SpanId('566e3688a61d4bc8'));
463-
464-
$scope = new Scope($propagationContext);
465-
466-
$hub = new Hub(null, $scope);
467-
468-
SentrySdk::setCurrentHub($hub);
469-
470-
$traceParent = getW3CTraceparent();
471-
472-
$this->assertSame('00-566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-00', $traceParent);
473-
}
474-
475-
public function testW3CTraceparentWithTracingEnabled(): void
476-
{
477-
$client = $this->createMock(ClientInterface::class);
478-
$client->expects($this->once())
479-
->method('getOptions')
480-
->willReturn(new Options([
481-
'traces_sample_rate' => 1.0,
482-
]));
483-
484-
$hub = new Hub($client);
485-
486-
SentrySdk::setCurrentHub($hub);
487-
488-
$spanContext = (new SpanContext())
489-
->setTraceId(new TraceId('566e3688a61d4bc888951642d6f14a19'))
490-
->setSpanId(new SpanId('566e3688a61d4bc8'))
491-
->setSampled(true);
492-
493-
$span = new Span($spanContext);
494-
495-
$hub->setSpan($span);
496-
497-
$traceParent = getW3CTraceparent();
498-
499-
$this->assertSame('00-566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-01', $traceParent);
500-
}
501-
502457
public function testBaggageWithTracingDisabled(): void
503458
{
504459
$propagationContext = PropagationContext::fromDefaults();

tests/Tracing/GuzzleTracingMiddlewareTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,9 @@ public function testTraceHeaders(Request $request, Options $options, bool $heade
130130
$function = $middleware(function (Request $request) use ($expectedPromiseResult, $headersShouldBePresent): PromiseInterface {
131131
if ($headersShouldBePresent) {
132132
$this->assertNotEmpty($request->getHeader('sentry-trace'));
133-
$this->assertNotEmpty($request->getHeader('traceparent'));
134133
$this->assertNotEmpty($request->getHeader('baggage'));
135134
} else {
136135
$this->assertEmpty($request->getHeader('sentry-trace'));
137-
$this->assertEmpty($request->getHeader('traceparent'));
138136
$this->assertEmpty($request->getHeader('baggage'));
139137
}
140138

@@ -167,11 +165,9 @@ public function testTraceHeadersWithTransaction(Request $request, Options $optio
167165
$function = $middleware(function (Request $request) use ($expectedPromiseResult, $headersShouldBePresent): PromiseInterface {
168166
if ($headersShouldBePresent) {
169167
$this->assertNotEmpty($request->getHeader('sentry-trace'));
170-
$this->assertNotEmpty($request->getHeader('traceparent'));
171168
$this->assertNotEmpty($request->getHeader('baggage'));
172169
} else {
173170
$this->assertEmpty($request->getHeader('sentry-trace'));
174-
$this->assertEmpty($request->getHeader('traceparent'));
175171
$this->assertEmpty($request->getHeader('baggage'));
176172
}
177173

@@ -344,7 +340,6 @@ public function testTrace(Request $request, $expectedPromiseResult, array $expec
344340
$middleware = GuzzleTracingMiddleware::trace($hub);
345341
$function = $middleware(function (Request $request) use ($expectedPromiseResult): PromiseInterface {
346342
$this->assertNotEmpty($request->getHeader('sentry-trace'));
347-
$this->assertNotEmpty($request->getHeader('traceparent'));
348343
$this->assertNotEmpty($request->getHeader('baggage'));
349344
if ($expectedPromiseResult instanceof \Throwable) {
350345
return new RejectedPromise($expectedPromiseResult);

tests/Tracing/PropagationContextTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ public static function tracingDataProvider(): iterable
7878
true,
7979
];
8080

81-
yield [
82-
'00-566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-01',
83-
'',
84-
new TraceId('566e3688a61d4bc888951642d6f14a19'),
85-
new SpanId('566e3688a61d4bc8'),
86-
true,
87-
];
88-
8981
yield [
9082
'566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-1',
9183
'sentry-public_key=public,sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-sample_rate=1',
@@ -112,15 +104,6 @@ public function testToTraceparent()
112104
$this->assertSame('566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8', $propagationContext->toTraceparent());
113105
}
114106

115-
public function testToW3CTraceparent()
116-
{
117-
$propagationContext = PropagationContext::fromDefaults();
118-
$propagationContext->setTraceId(new TraceId('566e3688a61d4bc888951642d6f14a19'));
119-
$propagationContext->setSpanId(new SpanId('566e3688a61d4bc8'));
120-
121-
$this->assertSame('00-566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-00', $propagationContext->toW3CTraceparent());
122-
}
123-
124107
public function testToBaggage()
125108
{
126109
$dynamicSamplingContext = DynamicSamplingContext::fromHeader('sentry-trace_id=566e3688a61d4bc888951642d6f14a19');

tests/Tracing/TransactionContextTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,6 @@ public static function tracingDataProvider(): iterable
117117
true,
118118
];
119119

120-
yield [
121-
'00-566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-00',
122-
'',
123-
new SpanId('566e3688a61d4bc8'),
124-
new TraceId('566e3688a61d4bc888951642d6f14a19'),
125-
false,
126-
DynamicSamplingContext::class,
127-
true,
128-
];
129-
130-
yield [
131-
'00-566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-01',
132-
'',
133-
new SpanId('566e3688a61d4bc8'),
134-
new TraceId('566e3688a61d4bc888951642d6f14a19'),
135-
true,
136-
DynamicSamplingContext::class,
137-
true,
138-
];
139-
140120
yield [
141121
'566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-1',
142122
'sentry-public_key=public,sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-sample_rate=1',

0 commit comments

Comments
 (0)