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

Invalid instrumentation key ERROR  #70

Open
@xiaoxinyi666

Description

@xiaoxinyi666

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";

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions