Set message severity level in trackMessage on TelemetryClient
This commit is contained in:
Родитель
a1fd851a47
Коммит
637e68bc2a
|
@ -30,6 +30,7 @@
|
|||
<Compile Include="ApplicationInsights\Channel\Contracts\Internal.php" />
|
||||
<Compile Include="ApplicationInsights\Channel\Contracts\Location.php" />
|
||||
<Compile Include="ApplicationInsights\Channel\Contracts\Message_Data.php" />
|
||||
<Compile Include="ApplicationInsights\Channel\Contracts\Message_SeverityLevel.php" />
|
||||
<Compile Include="ApplicationInsights\Channel\Contracts\Metric_Data.php" />
|
||||
<Compile Include="ApplicationInsights\Channel\Contracts\Operation.php" />
|
||||
<Compile Include="ApplicationInsights\Channel\Contracts\Page_View_Data.php" />
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
namespace ApplicationInsights\Channel\Contracts;
|
||||
/**
|
||||
* Enum Message_SeverityLevel.
|
||||
*/
|
||||
abstract class Message_SeverityLevel
|
||||
{
|
||||
const VERBOSE = 'Verbose';
|
||||
const INFORMATION = 'Information';
|
||||
const WARNING = 'Warning';
|
||||
const ERROR = 'Error';
|
||||
const CRITICAL = 'Critical';
|
||||
}
|
|
@ -130,12 +130,14 @@ class Telemetry_Client
|
|||
/**
|
||||
* Sends an Message_Data to the Application Insights service.
|
||||
* @param string $message The trace message.
|
||||
* @param \ApplicationInsights\Channel\Contracts\Message_SeverityLevel::Value $severityLevel The severity level of the message.
|
||||
* @param array $properties An array of name to value pairs. Use the name as the index and any string as the value.
|
||||
*/
|
||||
public function trackMessage($message, $properties = NULL)
|
||||
public function trackMessage($message, $severityLevel = NULL, $properties = NULL)
|
||||
{
|
||||
$data = new Channel\Contracts\Message_Data();
|
||||
$data->setMessage($message);
|
||||
$data->setSeverityLevel($severityLevel);
|
||||
|
||||
if ($properties != NULL)
|
||||
{
|
||||
|
|
|
@ -183,12 +183,12 @@ class Telemetry_Client_Test extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testCompleteMessage()
|
||||
{
|
||||
$this->_telemetryClient->trackMessage('myMessage', ['InlineProperty' => 'test_value']);
|
||||
$this->_telemetryClient->trackMessage('myMessage2', ['InlineProperty' => 'test_value']);
|
||||
$this->_telemetryClient->trackMessage('myMessage', \ApplicationInsights\Channel\Contracts\Message_SeverityLevel::ERROR, ['InlineProperty' => 'test_value']);
|
||||
$this->_telemetryClient->trackMessage('myMessage2', \ApplicationInsights\Channel\Contracts\Message_SeverityLevel::INFORMATION, ['InlineProperty' => 'test_value']);
|
||||
|
||||
$queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true);
|
||||
$queue = $this->adjustDataInQueue($queue);
|
||||
$expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100,"iKey":"'. Utils::getTestInstrumentationKey() . '","tags":{"ai.application.ver":"1.0.0.0","ai.device.id":"my_device_id","ai.device.ip":"127.0.0.1","ai.device.language":"EN","ai.device.locale":"EN","ai.device.model":"my_device_model","ai.device.network":5,"ai.device.oemName":"my_device_oem_name","ai.device.os":"Window","ai.device.osVersion":"8","ai.device.roleInstance":"device role instance","ai.device.roleName":"device role name","ai.device.screenResolution":"1920x1080","ai.device.type":"PC","ai.device.vmName":"device vm name","ai.location.ip":"127.0.0.0","ai.operation.id":"my_operation_id","ai.operation.name":"my_operation_name","ai.operation.parentId":"my_operation_parent_id","ai.operation.rootId":"my_operation_rood","ai.session.id":"my_session_id","ai.session.isFirst":"false","ai.session.isNew":"false","ai.user.id":"my_user_id","ai.user.accountAcquisitionDate":"1\/1\/2014","ai.user.accountId":"my_account_id","ai.user.userAgent":"my_user_agent","ai.internal.sdkVersion":"SDK_VERSION_STRING"},"data":{"baseData":{"ver":2,"message":"myMessage","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"MessageData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100,"iKey":"'. Utils::getTestInstrumentationKey() . '","tags":{"ai.application.ver":"1.0.0.0","ai.device.id":"my_device_id","ai.device.ip":"127.0.0.1","ai.device.language":"EN","ai.device.locale":"EN","ai.device.model":"my_device_model","ai.device.network":5,"ai.device.oemName":"my_device_oem_name","ai.device.os":"Window","ai.device.osVersion":"8","ai.device.roleInstance":"device role instance","ai.device.roleName":"device role name","ai.device.screenResolution":"1920x1080","ai.device.type":"PC","ai.device.vmName":"device vm name","ai.location.ip":"127.0.0.0","ai.operation.id":"my_operation_id","ai.operation.name":"my_operation_name","ai.operation.parentId":"my_operation_parent_id","ai.operation.rootId":"my_operation_rood","ai.session.id":"my_session_id","ai.session.isFirst":"false","ai.session.isNew":"false","ai.user.id":"my_user_id","ai.user.accountAcquisitionDate":"1\/1\/2014","ai.user.accountId":"my_account_id","ai.user.userAgent":"my_user_agent","ai.internal.sdkVersion":"SDK_VERSION_STRING"},"data":{"baseData":{"ver":2,"message":"myMessage2","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"MessageData"}}]', true);
|
||||
$expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100,"iKey":"'. Utils::getTestInstrumentationKey() . '","tags":{"ai.application.ver":"1.0.0.0","ai.device.id":"my_device_id","ai.device.ip":"127.0.0.1","ai.device.language":"EN","ai.device.locale":"EN","ai.device.model":"my_device_model","ai.device.network":5,"ai.device.oemName":"my_device_oem_name","ai.device.os":"Window","ai.device.osVersion":"8","ai.device.roleInstance":"device role instance","ai.device.roleName":"device role name","ai.device.screenResolution":"1920x1080","ai.device.type":"PC","ai.device.vmName":"device vm name","ai.location.ip":"127.0.0.0","ai.operation.id":"my_operation_id","ai.operation.name":"my_operation_name","ai.operation.parentId":"my_operation_parent_id","ai.operation.rootId":"my_operation_rood","ai.session.id":"my_session_id","ai.session.isFirst":"false","ai.session.isNew":"false","ai.user.id":"my_user_id","ai.user.accountAcquisitionDate":"1\/1\/2014","ai.user.accountId":"my_account_id","ai.user.userAgent":"my_user_agent","ai.internal.sdkVersion":"SDK_VERSION_STRING"},"data":{"baseData":{"ver":2,"message":"myMessage","severityLevel":"Error","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"MessageData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100,"iKey":"'. Utils::getTestInstrumentationKey() . '","tags":{"ai.application.ver":"1.0.0.0","ai.device.id":"my_device_id","ai.device.ip":"127.0.0.1","ai.device.language":"EN","ai.device.locale":"EN","ai.device.model":"my_device_model","ai.device.network":5,"ai.device.oemName":"my_device_oem_name","ai.device.os":"Window","ai.device.osVersion":"8","ai.device.roleInstance":"device role instance","ai.device.roleName":"device role name","ai.device.screenResolution":"1920x1080","ai.device.type":"PC","ai.device.vmName":"device vm name","ai.location.ip":"127.0.0.0","ai.operation.id":"my_operation_id","ai.operation.name":"my_operation_name","ai.operation.parentId":"my_operation_parent_id","ai.operation.rootId":"my_operation_rood","ai.session.id":"my_session_id","ai.session.isFirst":"false","ai.session.isNew":"false","ai.user.id":"my_user_id","ai.user.accountAcquisitionDate":"1\/1\/2014","ai.user.accountId":"my_account_id","ai.user.userAgent":"my_user_agent","ai.internal.sdkVersion":"SDK_VERSION_STRING"},"data":{"baseData":{"ver":2,"message":"myMessage2","severityLevel":"Information","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"MessageData"}}]', true);
|
||||
|
||||
$this->assertEquals($queue, $expectedValue);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче