Ver código fonte

Add prefixes to the context and extra record keys. Needed as some processors have the same keys as the the context. Specifically, the IntrospectionProcessor has "line" and "file" that can overwrite an error context "line" and "file".

Mark Garrett 11 anos atrás
pai
commit
e7647fd37d

+ 2 - 2
src/Monolog/Handler/NewRelicHandler.php

@@ -60,11 +60,11 @@ class NewRelicHandler extends AbstractProcessingHandler
         }
 
         foreach ($record['context'] as $key => $parameter) {
-            newrelic_add_custom_parameter($key, $parameter);
+            newrelic_add_custom_parameter('context_' . $key, $parameter);
         }
 
         foreach ($record['extra'] as $key => $parameter) {
-            newrelic_add_custom_parameter($key, $parameter);
+            newrelic_add_custom_parameter('extra_' . $key, $parameter);
         }
     }
 

+ 4 - 4
tests/Monolog/Handler/NewRelicHandlerTest.php

@@ -45,7 +45,7 @@ class NewRelicHandlerTest extends TestCase
     {
         $handler = new StubNewRelicHandler();
         $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('a' => 'b')));
-        $this->assertEquals(array('a' => 'b'), self::$customParameters);
+        $this->assertEquals(array('context_a' => 'b'), self::$customParameters);
     }
 
     public function testThehandlerCanAddExtraParamsToTheNewRelicTrace()
@@ -56,7 +56,7 @@ class NewRelicHandlerTest extends TestCase
         $handler = new StubNewRelicHandler();
         $handler->handle($record);
 
-        $this->assertEquals(array('c' => 'd'), self::$customParameters);
+        $this->assertEquals(array('extra_c' => 'd'), self::$customParameters);
     }
 
     public function testThehandlerCanAddExtraContextAndParamsToTheNewRelicTrace()
@@ -68,8 +68,8 @@ class NewRelicHandlerTest extends TestCase
         $handler->handle($record);
 
         $expected = array(
-            'a' => 'b',
-            'c' => 'd',
+            'context_a' => 'b',
+            'extra_c' => 'd',
         );
 
         $this->assertEquals($expected, self::$customParameters);