diff --git a/src/Client.php b/src/Client.php index badefd8..dd5d070 100644 --- a/src/Client.php +++ b/src/Client.php @@ -104,8 +104,12 @@ private function registerDefaultLogSendHandler() $this->registerLogSendHandler(function (array $logs) { $url = getenv('TAIL_LOGS_ENDPOINT') ?: self::LOGS_ENDPOINT; + $encodedLogs = array_map(function ($log) { + return json_encode($log); + }, $logs); + $this->guzzle->post($url, [ - 'json' => $logs, + 'body' => implode("\n", $encodedLogs), 'headers' => [ 'Authorization' => 'Bearer ' . $this->token, ], @@ -119,7 +123,7 @@ private function registerDefaultApmSendHandler() $url = getenv('TAIL_APM_ENDPOINT') ?: self::APM_ENDPOINT; $this->guzzle->post($url, [ - 'json' => $transaction, + 'body' => json_encode($transaction), 'headers' => [ 'Authorization' => 'Bearer ' . $this->token, ], diff --git a/tests/ClientTest.php b/tests/ClientTest.php index c55d701..d60e815 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -28,10 +28,12 @@ public function test_send_logs() ['message' => "message \n2"], ]; + $expectEncoded = "{\"message\":\"message 1\"}\n{\"message\":\"message \\n2\"}"; + $this->guzzle->shouldReceive('post')->with( Client::LOGS_ENDPOINT, [ - 'json' => $logs, + 'body' => $expectEncoded, 'headers' => [ 'Authorization' => 'Bearer secret_token', ], @@ -71,11 +73,12 @@ public function test_stop_log_sending_chain_with_handler_that_returns_false() public function test_send_apm() { $transaction = ['some' => 'data']; + $expectEncoded = "{\"some\":\"data\"}"; $this->guzzle->shouldReceive('post')->with( Client::APM_ENDPOINT, [ - 'json' => $transaction, + 'body' => $expectEncoded, 'headers' => [ 'Authorization' => 'Bearer secret_token', ],