newrelic / newrelic-monolog-logenricher-php

Monolog components to enable New Relic Logs
Apache License 2.0
24 stars 32 forks source link

Bug or mistake in AbstractHandler::sendBatch #36

Closed uuf6429 closed 3 years ago

uuf6429 commented 3 years ago

Description

In troubleshooting why my setup didn't seem to be working, I ended up seeing the following code: https://github.com/newrelic/newrelic-monolog-logenricher-php/blob/master/src/AbstractHandler.php#L133...L135

        $postData = '[{"logs":' . $data . '}]';

        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        Curl\Util::execute($ch, 5, false);
    }

$postData is not used, and I'm wondering if this is correct or could be causing problems (I'll keep investigating my problem separately).

Your Environment

PHP: 7.4 OS: osx 11.3.1 Monolog: 2.2.0 (via laravel)

joshuabenuck commented 3 years ago

@uuf6429

I think that is just an unused variable. Those lines (including the unused variable) were moved from Handler.php just recently, but they were first added two years ago.

I did a quick experiment with PHP 7.4 and Monolog 2.2 on a Linux host and was able to get it to send up log entries. PHP 8.0 on a macOS host also worked. This points to something in your setup. Can you provide more information about how you have things configured, what APIs you are calling, and what you are expecting to see, but are not? If you are able to provide a small script to reproduce the problem, that would be even better.

Here's the script that I used, if you want to try it to rule out something like an incorrect license key or networking problem. (Do a composer require newrelic/monolog-enricher in the script's directory to populate the vendor directory).

<?php
require __DIR__ . '/vendor/autoload.php';
use Monolog\Logger;
use NewRelic\Monolog\Enricher\{Handler, Processor};

$log = new Logger('monolog-experiment');
$handler = new Handler;
$handler->setLicenseKey('<your license key here>');
$log->pushHandler($handler);

$log->info('Monolog Enricher test!');
uuf6429 commented 3 years ago

Thanks for the quick reply!

I figured out the problem on my side late yesterday (and forgot to update this ticket) - it was a rather embarrassing server-side misconfiguration that was causing a different logging provider to be used.