Skip to content

Commit e90ca56

Browse files
committed
single line json encoding
1 parent 2a8e3d5 commit e90ca56

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/Client.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ private function registerDefaultLogSendHandler()
104104
$this->registerLogSendHandler(function (array $logs) {
105105
$url = getenv('TAIL_LOGS_ENDPOINT') ?: self::LOGS_ENDPOINT;
106106

107+
$encodedLogs = array_map(function ($log) {
108+
return json_encode($log);
109+
}, $logs);
110+
107111
$this->guzzle->post($url, [
108-
'json' => $logs,
112+
'body' => implode("\n", $encodedLogs),
109113
'headers' => [
110114
'Authorization' => 'Bearer ' . $this->token,
111115
],
@@ -119,7 +123,7 @@ private function registerDefaultApmSendHandler()
119123
$url = getenv('TAIL_APM_ENDPOINT') ?: self::APM_ENDPOINT;
120124

121125
$this->guzzle->post($url, [
122-
'json' => $transaction,
126+
'body' => json_encode($transaction),
123127
'headers' => [
124128
'Authorization' => 'Bearer ' . $this->token,
125129
],

tests/ClientTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ public function test_send_logs()
2828
['message' => "message \n2"],
2929
];
3030

31+
$expectEncoded = "{\"message\":\"message 1\"}\n{\"message\":\"message \\n2\"}";
32+
3133
$this->guzzle->shouldReceive('post')->with(
3234
Client::LOGS_ENDPOINT,
3335
[
34-
'json' => $logs,
36+
'body' => $expectEncoded,
3537
'headers' => [
3638
'Authorization' => 'Bearer secret_token',
3739
],
@@ -71,11 +73,12 @@ public function test_stop_log_sending_chain_with_handler_that_returns_false()
7173
public function test_send_apm()
7274
{
7375
$transaction = ['some' => 'data'];
76+
$expectEncoded = "{\"some\":\"data\"}";
7477

7578
$this->guzzle->shouldReceive('post')->with(
7679
Client::APM_ENDPOINT,
7780
[
78-
'json' => $transaction,
81+
'body' => $expectEncoded,
7982
'headers' => [
8083
'Authorization' => 'Bearer secret_token',
8184
],

0 commit comments

Comments
 (0)