From 02a35065552eea9ea9835f6b4e12158643129c79 Mon Sep 17 00:00:00 2001 From: Musoftware Date: Wed, 31 Jan 2024 19:44:19 +0200 Subject: [PATCH 1/7] accept any website --- src/Dsn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dsn.php b/src/Dsn.php index 071a6292f..5ab366e3e 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -75,7 +75,7 @@ public static function createFromString(string $value): self throw new \InvalidArgumentException(sprintf('The "%s" DSN is invalid.', $value)); } - foreach (['scheme', 'host', 'path', 'user'] as $component) { + foreach (['scheme', 'host', 'path'] as $component) { if (!isset($parsedDsn[$component]) || (isset($parsedDsn[$component]) && empty($parsedDsn[$component]))) { throw new \InvalidArgumentException(sprintf('The "%s" DSN must contain a scheme, a host, a user and a path component.', $value)); } From 8fbd78db9880d2324b7cea25f929a9a452d860ce Mon Sep 17 00:00:00 2001 From: Musoftware Date: Wed, 31 Jan 2024 21:12:32 +0200 Subject: [PATCH 2/7] updates --- src/Dsn.php | 23 ++++++----------------- src/Tracing/DynamicSamplingContext.php | 8 -------- src/Util/Http.php | 1 - tests/DsnTest.php | 1 - 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/Dsn.php b/src/Dsn.php index 5ab366e3e..deb39d2b8 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -27,10 +27,6 @@ final class Dsn implements \Stringable */ private $port; - /** - * @var string The public key to authenticate the SDK - */ - private $publicKey; /** * @var string The ID of the resource to access @@ -50,14 +46,12 @@ final class Dsn implements \Stringable * @param int $port The port on which the resource is exposed * @param string $projectId The ID of the resource to access * @param string $path The specific resource that the web client wants to access - * @param string $publicKey The public key to authenticate the SDK */ - private function __construct(string $scheme, string $host, int $port, string $projectId, string $path, string $publicKey) + private function __construct(string $scheme, string $host, int $port, string $projectId, string $path) { $this->scheme = $scheme; $this->host = $host; $this->port = $port; - $this->publicKey = $publicKey; $this->path = $path; $this->projectId = $projectId; } @@ -70,7 +64,6 @@ private function __construct(string $scheme, string $host, int $port, string $pr public static function createFromString(string $value): self { $parsedDsn = parse_url($value); - if ($parsedDsn === false) { throw new \InvalidArgumentException(sprintf('The "%s" DSN is invalid.', $value)); } @@ -99,8 +92,7 @@ public static function createFromString(string $value): self $parsedDsn['host'], $parsedDsn['port'] ?? ($parsedDsn['scheme'] === 'http' ? 80 : 443), $projectId, - $path, - $parsedDsn['user'] + $path ); } @@ -147,10 +139,7 @@ public function getProjectId(): string /** * Gets the public key to authenticate the SDK. */ - public function getPublicKey(): string - { - return $this->publicKey; - } + /** * Returns the URL of the API for the envelope endpoint. @@ -165,7 +154,7 @@ public function getEnvelopeApiEndpointUrl(): string */ public function getCspReportEndpointUrl(): string { - return $this->getBaseEndpointUrl() . '/security/?sentry_key=' . $this->publicKey; + return $this->getBaseEndpointUrl() . '/security/'; } /** @@ -173,9 +162,9 @@ public function getCspReportEndpointUrl(): string */ public function __toString(): string { - $url = $this->scheme . '://' . $this->publicKey; + $url = $this->scheme . '://'; - $url .= '@' . $this->host; + $url .= $this->host; if (($this->scheme === 'http' && $this->port !== 80) || ($this->scheme === 'https' && $this->port !== 443)) { $url .= ':' . $this->port; diff --git a/src/Tracing/DynamicSamplingContext.php b/src/Tracing/DynamicSamplingContext.php index cf159ed59..20a5c8dbe 100644 --- a/src/Tracing/DynamicSamplingContext.php +++ b/src/Tracing/DynamicSamplingContext.php @@ -169,10 +169,6 @@ public static function fromTransaction(Transaction $transaction, HubInterface $h if ($client !== null) { $options = $client->getOptions(); - if ($options->getDsn() !== null && $options->getDsn()->getPublicKey() !== null) { - $samplingContext->set('public_key', $options->getDsn()->getPublicKey()); - } - if ($options->getRelease() !== null) { $samplingContext->set('release', $options->getRelease()); } @@ -200,10 +196,6 @@ public static function fromOptions(Options $options, Scope $scope): self $samplingContext->set('sample_rate', (string) $options->getTracesSampleRate()); } - if ($options->getDsn() !== null && $options->getDsn()->getPublicKey() !== null) { - $samplingContext->set('public_key', $options->getDsn()->getPublicKey()); - } - if ($options->getRelease() !== null) { $samplingContext->set('release', $options->getRelease()); } diff --git a/src/Util/Http.php b/src/Util/Http.php index efe903ad7..c6a75d5bd 100644 --- a/src/Util/Http.php +++ b/src/Util/Http.php @@ -20,7 +20,6 @@ public static function getRequestHeaders(Dsn $dsn, string $sdkIdentifier, string $authHeader = [ 'sentry_version=' . Client::PROTOCOL_VERSION, 'sentry_client=' . $sdkIdentifier . '/' . $sdkVersion, - 'sentry_key=' . $dsn->getPublicKey(), ]; return [ diff --git a/tests/DsnTest.php b/tests/DsnTest.php index 724d00538..2c970bb1f 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -29,7 +29,6 @@ public function testCreateFromString( $this->assertSame($expectedScheme, $dsn->getScheme()); $this->assertSame($expectedHost, $dsn->getHost()); $this->assertSame($expectedPort, $dsn->getPort()); - $this->assertSame($expectedPublicKey, $dsn->getPublicKey()); $this->assertSame($expectedProjectId, $dsn->getProjectId(true)); $this->assertSame($expectedPath, $dsn->getPath()); } From cac51c635a629e205f14d9addddeb8542a9ac74d Mon Sep 17 00:00:00 2001 From: Musoftware Date: Wed, 31 Jan 2024 21:13:54 +0200 Subject: [PATCH 3/7] Update composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 798b05541..1bc5ab381 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sentry/sentry", + "name": "musoftware/logger-php", "type": "library", "description": "PHP SDK for Sentry (http://sentry.io)", "keywords": [ @@ -13,7 +13,6 @@ "profiling", "tracing" ], - "homepage": "http://sentry.io", "license": "MIT", "authors": [ { From 401556fb38f50080fe4be30b3c910a49ebbb4709 Mon Sep 17 00:00:00 2001 From: Musoftware Date: Sat, 3 Feb 2024 11:04:27 +0200 Subject: [PATCH 4/7] Update Dsn.php --- src/Dsn.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Dsn.php b/src/Dsn.php index deb39d2b8..0f55696ec 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -190,11 +190,12 @@ private function getBaseEndpointUrl(): string $url .= ':' . $this->port; } + $url .= '/api'; if ($this->path !== null) { $url .= $this->path; } - $url .= '/api/' . $this->projectId; + $url .= '/' . $this->projectId; return $url; } From be950edeadfef008ef2ecf5fc92140c9cefcc2ff Mon Sep 17 00:00:00 2001 From: Musoftware Date: Sat, 3 Feb 2024 13:03:24 +0200 Subject: [PATCH 5/7] remove ontent-Type --- src/Spotlight/SpotlightClient.php | 3 --- src/Util/Http.php | 1 - tests/Util/HttpTest.php | 1 - 3 files changed, 5 deletions(-) diff --git a/src/Spotlight/SpotlightClient.php b/src/Spotlight/SpotlightClient.php index f32af4cda..d154a141a 100644 --- a/src/Spotlight/SpotlightClient.php +++ b/src/Spotlight/SpotlightClient.php @@ -26,9 +26,6 @@ public static function sendRequest(Request $request, string $url): Response $curlHandle = curl_init(); curl_setopt($curlHandle, \CURLOPT_URL, $url); - curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, [ - 'Content-Type: application/x-sentry-envelope', - ]); curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2.0); curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1.0); curl_setopt($curlHandle, \CURLOPT_ENCODING, ''); diff --git a/src/Util/Http.php b/src/Util/Http.php index c6a75d5bd..692845141 100644 --- a/src/Util/Http.php +++ b/src/Util/Http.php @@ -23,7 +23,6 @@ public static function getRequestHeaders(Dsn $dsn, string $sdkIdentifier, string ]; return [ - 'Content-Type: application/x-sentry-envelope', 'X-Sentry-Auth: Sentry ' . implode(', ', $authHeader), ]; } diff --git a/tests/Util/HttpTest.php b/tests/Util/HttpTest.php index 342ad1b75..c14b4c90d 100644 --- a/tests/Util/HttpTest.php +++ b/tests/Util/HttpTest.php @@ -25,7 +25,6 @@ public static function getRequestHeadersDataProvider(): \Generator 'sentry.sdk.identifier', '1.2.3', [ - 'Content-Type: application/x-sentry-envelope', 'X-Sentry-Auth: Sentry sentry_version=7, sentry_client=sentry.sdk.identifier/1.2.3, sentry_key=public', ], ]; From a06e11db4243fd33c3a488e54b57d6adf1640abc Mon Sep 17 00:00:00 2001 From: Musoftware Date: Sat, 3 Feb 2024 13:27:13 +0200 Subject: [PATCH 6/7] fix bugs --- src/Dsn.php | 4 ++-- src/HttpClient/HttpClient.php | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Dsn.php b/src/Dsn.php index 0f55696ec..ea4e6642c 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -146,7 +146,7 @@ public function getProjectId(): string */ public function getEnvelopeApiEndpointUrl(): string { - return $this->getBaseEndpointUrl() . '/envelope/'; + return $this->getBaseEndpointUrl() . '/envelope'; } /** @@ -154,7 +154,7 @@ public function getEnvelopeApiEndpointUrl(): string */ public function getCspReportEndpointUrl(): string { - return $this->getBaseEndpointUrl() . '/security/'; + return $this->getBaseEndpointUrl() . '/security'; } /** diff --git a/src/HttpClient/HttpClient.php b/src/HttpClient/HttpClient.php index 779088d25..45b30278c 100644 --- a/src/HttpClient/HttpClient.php +++ b/src/HttpClient/HttpClient.php @@ -48,14 +48,6 @@ public function sendRequest(Request $request, Options $options): Response $requestHeaders = Http::getRequestHeaders($dsn, $this->sdkIdentifier, $this->sdkVersion); - if ( - \extension_loaded('zlib') - && $options->isHttpCompressionEnabled() - ) { - $requestData = gzcompress($requestData, -1, \ZLIB_ENCODING_GZIP); - $requestHeaders[] = 'Content-Encoding: gzip'; - } - $responseHeaders = []; $responseHeaderCallback = function ($curlHandle, $headerLine) use (&$responseHeaders): int { return Http::parseResponseHeaders($headerLine, $responseHeaders); @@ -73,10 +65,7 @@ public function sendRequest(Request $request, Options $options): Response curl_setopt($curlHandle, \CURLOPT_HEADERFUNCTION, $responseHeaderCallback); curl_setopt($curlHandle, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1); - $httpSslVerifyPeer = $options->getHttpSslVerifyPeer(); - if (!$httpSslVerifyPeer) { - curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, false); - } + curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, false); $httpProxy = $options->getHttpProxy(); if ($httpProxy !== null) { @@ -105,6 +94,7 @@ public function sendRequest(Request $request, Options $options): Response curl_close($curlHandle); + return new Response($statusCode, $responseHeaders, ''); } } From 45ed4b3943fa397e163e5b99fd9ac7f860357eda Mon Sep 17 00:00:00 2001 From: Musoftware Date: Sun, 4 Feb 2024 12:16:44 +0200 Subject: [PATCH 7/7] Update Http.php --- src/Util/Http.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Util/Http.php b/src/Util/Http.php index 692845141..8c95da5f5 100644 --- a/src/Util/Http.php +++ b/src/Util/Http.php @@ -23,6 +23,7 @@ public static function getRequestHeaders(Dsn $dsn, string $sdkIdentifier, string ]; return [ + 'Content-Type: application/x-ndjson', 'X-Sentry-Auth: Sentry ' . implode(', ', $authHeader), ]; }