diff --git a/src/Elastic/Types/Service.php b/src/Elastic/Types/Service.php index 9f5a7b2..8c47a6e 100644 --- a/src/Elastic/Types/Service.php +++ b/src/Elastic/Types/Service.php @@ -125,6 +125,13 @@ final public function setVersion(string $version) */ public function jsonSerialize() { + if (array_key_exists('name', $this->data) && ($this->data['name'] != '')) { + return [ + 'service' => $this->data, + 'event' => ['dataset' => $this->data['name'] . '.log'] + ]; + } + return ['service' => $this->data]; } } diff --git a/tests/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatterTest.php b/tests/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatterTest.php index 0a05bb0..eac5673 100644 --- a/tests/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatterTest.php +++ b/tests/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatterTest.php @@ -163,6 +163,7 @@ public function testContextWithService() $this->assertEquals($service->toArray()['service']['id'], $decoded['service']['id']); $this->assertEquals($service->toArray()['service']['name'], $decoded['service']['name']); + $this->assertEquals($service->toArray()['event']['dataset'], $decoded['service']['name'] . '.log'); } /**