app-insights-php / monolog-handler

Microsoft App Insights monolog handler for trace tracking
MIT License
3 stars 7 forks source link

How to use it #74

Open mareksloser opened 1 year ago

mareksloser commented 1 year ago

Hello,

thank you for this code.

Could you help me? How i can use this handler?

RotatingFileHandler - handler working well, i have new line every time in main-DATE.log But how to use AppInsights_Handler? I dont know if i miss someting. I have no data in Azure appInsight, no errors nothing happend.

protected static function configureInstance(): void {
    $dir = dirname(__DIR__) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . 'log';

    if( ! file_exists( $dir ) && ! mkdir( $dir, 0777, true ) && ! is_dir( $dir ) ) {
        throw new \RuntimeException( sprintf( 'Directory "%s" was not created', $dir ) );
    }

    $logger = new Logger('Wordpress');

    $client = new ClientFactory(
        self::$instrumentation_key,
        AppInsightsPHP\Client\Configuration::createDefault(),
        new Psr16Cache(new ArrayAdapter()),
        $logger
    );

    $logger->pushHandler(new AppInsightsDependencyHandler($client->create()));
    $logger->pushHandler(new RotatingFileHandler($dir . DIRECTORY_SEPARATOR . 'main.log', 5));

    self::$instance = $logger;
}

Thank you

norberttech commented 1 year ago

hey, in order to collect logs you might want to use AppInsightsTraceHandler instead of DependencyHandler

mareksloser commented 1 year ago

@norberttech

Could you give me a info, how change url? I have to use this information from connection string: IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/

Exception occurred while flushing App Insights Telemetry Client: Client error: POST https://dc.services.visualstudio.com/v2/track resulted in a 400 Invalid instrumentation key response: {"itemsReceived":1,"itemsAccepted":0,"errors":[{"index":0,"statusCode":400,"message":"Invalid instrumentation key"}]}