Microsoft Azure - php

2

How do I get Microsoft Azure to capture my errors?

I'mcurrentlyhandlingerrorswiththisfunction:

<?php/**PluginName:TESTEDescription:testandolognovoVersion:1.0Author:VtesteAuthorURI:teste-------LICENSE:Thisfileissubjecttothetermsandconditionsdefinedinfile'license.txt',whichispartofAdvancedAccessManagersourcepackage.**///errorhandlerfunctionfunctionmyErrorHandler($errno,$errstr,$errfile,$errline){switch($errno){caseE_USER_ERROR:$erro="<b>My ERROR</b> [$errno] $errstr<br />\n";
        $erro += "  Fatal error on line $errline in file $errfile";
        $erro += ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
        $erro += "Aborting...<br />\n";
        echo $erro;
        exit(1);
        break;

    case E_USER_WARNING:
        $erro = "<b>My WARNING</b> [$errno] $errstr\n";
        break;

    case E_USER_NOTICE:
        $erro = "<b>My NOTICE</b> [$errno] $errstr\n";
        break;

    default:
        $erro = "Unknown error type: [$errno] $errstr, linha:$errline, no arquivo $errfile";
            error_log($erro);
        break;
    }

    /* Don't execute PHP internal error handler */
    return true;
}

// function to test the error handling
function scale_by_log($vect, $scale)
{
    if (!is_numeric($scale) || $scale <= 0) {
        trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR);
    }

    if (!is_array($vect)) {
        trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
        return null;
    }

    $temp = array();
    foreach($vect as $pos => $value) {
        if (!is_numeric($value)) {
            trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);
            $value = 0;
        }
        $temp[$pos] = log($scale) * $value;
    }

    return $temp;
}

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");


?>

And I use the Application Insights | Microsoft Azure , however it is not collecting any kind of error, so I would like to manually submit how could I do?

    
asked by anonymous 09.06.2017 / 20:34

1 answer

2

I'm not sure, but I think it's due to:

return true;

Inside your handler does not have set_error_handler , this does instead of using the internal handler it uses only your "handler", so PHP's internal LOG can never catch the error, because you are preventing it.

To try to resolve remove return true; , a detail at Microsoft provides an API for using Application Insights , if you are using return true; you can install like this:

require: "microsoft/application-insights": "*"

Note that you need to be using PHP 5.4.2 +

After you install create a key and add this code with your key:

$telemetryClient = new \ApplicationInsights\Telemetry_Client();
$telemetryClient->getContext()->setInstrumentationKey('DIGITE SUA CHAVE AQUI');
$telemetryClient->trackEvent('name of your event');
$telemetryClient->flush();
    
09.06.2017 / 21:14