diff --git a/class_map/TextCodec.php b/class_map/TextCodec.php index 84fe86c..9c35b46 100644 --- a/class_map/TextCodec.php +++ b/class_map/TextCodec.php @@ -2,6 +2,7 @@ namespace Jaeger\Codec; +use Hyperf\Tracer\Support\GuzzleHeaderValidate; use Hyperf\Tracer\Support\TextCodecOtel; use Exception; use Jaeger\SpanContext; @@ -76,8 +77,12 @@ public function inject(SpanContext $spanContext, &$carrier) if ($this->urlEncoding) { $encodedValue = urlencode($value); } + $headerName = $this->baggagePrefix . $key; - $carrier[$this->baggagePrefix . $key] = $encodedValue; + if (!GuzzleHeaderValidate::isValidHeader($headerName, $encodedValue)) { + continue; + } + $carrier[$headerName] = $encodedValue; } } diff --git a/src/Support/GuzzleHeaderValidate.php b/src/Support/GuzzleHeaderValidate.php new file mode 100644 index 0000000..a392d73 --- /dev/null +++ b/src/Support/GuzzleHeaderValidate.php @@ -0,0 +1,37 @@ + $value) { - $baggageHeader[] = $key . '=' . $value; + $value = $key . '=' . $value; + if (!GuzzleHeaderValidate::isValidHeaderValue($value)) { + continue; + } + $baggageHeader[] = $value; } $carrier[$this->traceStateHeader] = implode(',', $baggageHeader); } diff --git a/tests/GuzzleHeaderValidateTest.php b/tests/GuzzleHeaderValidateTest.php new file mode 100644 index 0000000..5cc3cef --- /dev/null +++ b/tests/GuzzleHeaderValidateTest.php @@ -0,0 +1,35 @@ +