Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

How to use it #74

Open
mareksloser opened this issue Nov 2, 2022 · 2 comments
Open

How to use it #74

mareksloser opened this issue Nov 2, 2022 · 2 comments

Comments

@mareksloser
Copy link

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
Copy link
Contributor

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

@mareksloser
Copy link
Author

@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"}]}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants