Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Invalid instrumentation key ERROR #70

Open
xiaoxinyi666 opened this issue Oct 23, 2019 · 0 comments
Open

Invalid instrumentation key ERROR #70

xiaoxinyi666 opened this issue Oct 23, 2019 · 0 comments

Comments

@xiaoxinyi666
Copy link

xiaoxinyi666 commented Oct 23, 2019

hello,when i was Initializing the client and setting the instrumentation key ,i got the error like this,
my background is put magento2's log to Azure application insights,magento2 is a framework made by php,so I found this github project.Does anyone konw what i should to fix it out?
I'm new to php, i'm a python and java programmer,so if i made some Low-level mistakes, please tell me ,thank you so much!

[2019-10-23 03:03:42] main.ERROR: 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"}]}

and my php code is like this:

use ApplicationInsights\Telemetry_Client;

$telemetryClient = new \ApplicationInsights\Telemetry_Client();
$context = $telemetryClient->getContext();

// Necessary
$context->setInstrumentationKey('MYInstrumentationKey');

// Optionalmy
//$context->getSessionContext()->setId(session_id());
//$context->getUserContext()->setId('YOUR USER ID');
//$context->getApplicationContext()->setVer('YOUR VERSION');
//$context->getLocationContext()->setIp('YOUR IP');

// Start tracking
$telemetryClient->trackEvent('name of your event');
$telemetryClient->flush();

code Integrated into the magento2 is like this,

namespace Max\HelloWorld\Controller\Index;

use ApplicationInsights\Telemetry_Client;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Logger\Handler\Debug;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Webapi\Exception;
use Monolog\Logger;

class Test extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;

public function __construct(
    Context $context,
    PageFactory $pageFactory
)
{
    $this->_pageFactory = $pageFactory;
    return parent::__construct($context);
}

public function execute()
{
    echo "Hello World";
    exit;
}

public function postLogger()
{
    echo "Start";
    $telemetryClient = new  Telemetry_Client();
    $context = $telemetryClient->getContext();

    $context->setInstrumentationKey('myInstrumentationKey');

    $telemetryClient->trackEvent("Zhou-loggerInfo", Logger::DEBUG);
    //$telemetryClient->flush();
    echo "End";

}
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

1 participant