diff --git a/ApplicationInsights/Channel/Contracts/Application.php b/ApplicationInsights/Channel/Contracts/Application.php index b35a72e..d7cc8f7 100644 --- a/ApplicationInsights/Channel/Contracts/Application.php +++ b/ApplicationInsights/Channel/Contracts/Application.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Application. +* Data contract class for type Application. */ class Application { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Application. + * Creates a new Application. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the ver field. + * Gets the ver field. */ public function getVer() { @@ -29,18 +31,10 @@ public function getVer() } /** - * Sets the ver field. + * Sets the ver field. */ public function setVer($ver) { $this->_data['ai.application.ver'] = $ver; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Base_Data.php b/ApplicationInsights/Channel/Contracts/Base_Data.php new file mode 100644 index 0000000..a0f7e8f --- /dev/null +++ b/ApplicationInsights/Channel/Contracts/Base_Data.php @@ -0,0 +1,59 @@ +_envelopeTypeName; + } + + /** + * Gets the dataTypeName field. + */ + public function getDataTypeName() + { + return $this->_dataTypeName; + } + + /** + * Gets the properties field. + */ + public function getProperties() + { + if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } + return NULL; + } + + /** + * Sets the properties field. + */ + public function setProperties($properties) + { + $this->_data['properties'] = $properties; + } +} diff --git a/ApplicationInsights/Channel/Contracts/Data.php b/ApplicationInsights/Channel/Contracts/Data.php index 1df5d5f..19b5061 100644 --- a/ApplicationInsights/Channel/Contracts/Data.php +++ b/ApplicationInsights/Channel/Contracts/Data.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Data. +* Data contract class for type Data. */ class Data { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Data. + * Creates a new Data. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the baseType field. + * Gets the baseType field. */ public function getBaseType() { @@ -29,7 +31,7 @@ public function getBaseType() } /** - * Sets the baseType field. + * Sets the baseType field. */ public function setBaseType($baseType) { @@ -37,7 +39,7 @@ public function setBaseType($baseType) } /** - * Gets the baseData field. + * Gets the baseData field. */ public function getBaseData() { @@ -46,18 +48,10 @@ public function getBaseData() } /** - * Sets the baseData field. + * Sets the baseData field. */ public function setBaseData($baseData) { $this->_data['baseData'] = $baseData; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Data_Interface.php b/ApplicationInsights/Channel/Contracts/Data_Interface.php new file mode 100644 index 0000000..613b590 --- /dev/null +++ b/ApplicationInsights/Channel/Contracts/Data_Interface.php @@ -0,0 +1,43 @@ +_data['stdDev'] = $stdDev; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Dependency_Data.php b/ApplicationInsights/Channel/Contracts/Dependency_Data.php new file mode 100644 index 0000000..02d3786 --- /dev/null +++ b/ApplicationInsights/Channel/Contracts/Dependency_Data.php @@ -0,0 +1,179 @@ +_envelopeTypeName = 'Microsoft.ApplicationInsights.RemoteDependency'; + $this->_dataTypeName = 'RemoteDependencyData'; + $this->_data['ver'] = 2; + $this->_data['name'] = NULL; + $this->_data['kind'] = Data_Point_Type::Measurement; + $this->_data['dependencyKind'] = NULL; + $this->_data['commandName'] = NULL; + $this->_data['startTime'] = NULL; + $this->_data['duration'] = NULL; + $this->_data['success'] = true; + $this->_data['resultCode'] = NULL; + $this->_data['async'] = NULL; + } + + /** + * Gets the name field. + */ + public function getName() + { + if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } + return NULL; + } + + /** + * Sets the name field. + */ + public function setName($name) + { + $this->_data['name'] = $name; + } + + /** + * Gets the kind field. + */ + public function getKind() + { + if (array_key_exists('kind', $this->_data)) { return $this->_data['kind']; } + return NULL; + } + + /** + * Sets the kind field. + */ + public function setKind($kind) + { + $this->_data['kind'] = $kind; + } + + /** + * Gets the dependencyKind field. + */ + public function getDependencyKind() + { + if (array_key_exists('dependencyKind', $this->_data)) { return $this->_data['dependencyKind']; } + return NULL; + } + + /** + * Sets the dependencyKind field. + */ + public function setDependencyKind($dependencyKind) + { + $this->_data['dependencyKind'] = $dependencyKind; + } + + /** + * Gets the commandName field. + */ + public function getCommandName() + { + if (array_key_exists('commandName', $this->_data)) { return $this->_data['commandName']; } + return NULL; + } + + /** + * Sets the commandName field. + */ + public function setCommandName($name) + { + $this->_data['commandName'] = $name; + } + + /** + * Gets the startTime field. + */ + public function getStartTime() + { + if (array_key_exists('startTime', $this->_data)) { return $this->_data['startTime']; } + return NULL; + } + + /** + * Sets the startTime field. + */ + public function setStartTime($startTime) + { + $this->_data['startTime'] = $startTime; + } + /** + * Gets the duration field. + */ + public function getDuration() + { + if (array_key_exists('duration', $this->_data)) { return $this->_data['duration']; } + return NULL; + } + + /** + * Sets the duration field. + */ + public function setDuration($duration) + { + $this->_data['duration'] = $duration; + } + + /** + * Gets the success field. + */ + public function getSuccess() + { + if (array_key_exists('success', $this->_data)) { return $this->_data['success']; } + return NULL; + } + + /** + * Sets the success field. + */ + public function setSuccess($success) + { + $this->_data['success'] = $success; + } + + /** + * Gets the resultCode field. + */ + public function getResultCode() + { + if (array_key_exists('resultCode', $this->_data)) { return $this->_data['resultCode']; } + return NULL; + } + + /** + * Sets the resultCode field. + */ + public function setResultCode($resultCode) + { + $this->_data['resultCode'] = (string)var_export($resultCode, true); + } + + /** + * Gets the async field. + */ + public function getAsync() + { + if (array_key_exists('async', $this->_data)) { return $this->_data['async']; } + return NULL; + } + + /** + * Sets the success field. + */ + public function setAsync($async) + { + $this->_data['async'] = $async; + } +} diff --git a/ApplicationInsights/Channel/Contracts/Dependency_Type.php b/ApplicationInsights/Channel/Contracts/Dependency_Type.php new file mode 100644 index 0000000..b5f0f01 --- /dev/null +++ b/ApplicationInsights/Channel/Contracts/Dependency_Type.php @@ -0,0 +1,11 @@ +_data['ai.device.vmName'] = $vmName; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Envelope.php b/ApplicationInsights/Channel/Contracts/Envelope.php index 47e1a45..9376cae 100644 --- a/ApplicationInsights/Channel/Contracts/Envelope.php +++ b/ApplicationInsights/Channel/Contracts/Envelope.php @@ -2,17 +2,20 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Envelope. +* Data contract class for type Envelope. */ class Envelope { + use Json_Serializer; + use Version_Manager; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Envelope. + * Creates a new Envelope. */ function __construct() { @@ -23,24 +26,7 @@ function __construct() } /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the name field. + * Gets the name field. */ public function getName() { @@ -49,7 +35,7 @@ public function getName() } /** - * Sets the name field. + * Sets the name field. */ public function setName($name) { @@ -57,7 +43,7 @@ public function setName($name) } /** - * Gets the time field. + * Gets the time field. */ public function getTime() { @@ -66,7 +52,7 @@ public function getTime() } /** - * Sets the time field. + * Sets the time field. */ public function setTime($time) { @@ -74,7 +60,7 @@ public function setTime($time) } /** - * Gets the sampleRate field. + * Gets the sampleRate field. */ public function getSampleRate() { @@ -83,7 +69,7 @@ public function getSampleRate() } /** - * Sets the sampleRate field. + * Sets the sampleRate field. */ public function setSampleRate($sampleRate) { @@ -91,7 +77,7 @@ public function setSampleRate($sampleRate) } /** - * Gets the seq field. + * Gets the seq field. */ public function getSeq() { @@ -100,7 +86,7 @@ public function getSeq() } /** - * Sets the seq field. + * Sets the seq field. */ public function setSeq($seq) { @@ -108,7 +94,7 @@ public function setSeq($seq) } /** - * Gets the iKey field. + * Gets the iKey field. */ public function getInstrumentationKey() { @@ -117,7 +103,7 @@ public function getInstrumentationKey() } /** - * Sets the iKey field. + * Sets the iKey field. */ public function setInstrumentationKey($iKey) { @@ -125,7 +111,7 @@ public function setInstrumentationKey($iKey) } /** - * Gets the flags field. + * Gets the flags field. */ public function getFlags() { @@ -134,7 +120,7 @@ public function getFlags() } /** - * Sets the flags field. + * Sets the flags field. */ public function setFlags($flags) { @@ -142,7 +128,7 @@ public function setFlags($flags) } /** - * Gets the deviceId field. + * Gets the deviceId field. */ public function getDeviceId() { @@ -151,7 +137,7 @@ public function getDeviceId() } /** - * Sets the deviceId field. + * Sets the deviceId field. */ public function setDeviceId($deviceId) { @@ -159,7 +145,7 @@ public function setDeviceId($deviceId) } /** - * Gets the os field. + * Gets the os field. */ public function getOs() { @@ -168,7 +154,7 @@ public function getOs() } /** - * Sets the os field. + * Sets the os field. */ public function setOs($os) { @@ -176,7 +162,7 @@ public function setOs($os) } /** - * Gets the osVer field. + * Gets the osVer field. */ public function getOsVer() { @@ -185,7 +171,7 @@ public function getOsVer() } /** - * Sets the osVer field. + * Sets the osVer field. */ public function setOsVer($osVer) { @@ -193,7 +179,7 @@ public function setOsVer($osVer) } /** - * Gets the appId field. + * Gets the appId field. */ public function getAppId() { @@ -202,7 +188,7 @@ public function getAppId() } /** - * Sets the appId field. + * Sets the appId field. */ public function setAppId($appId) { @@ -210,7 +196,7 @@ public function setAppId($appId) } /** - * Gets the appVer field. + * Gets the appVer field. */ public function getAppVer() { @@ -219,7 +205,7 @@ public function getAppVer() } /** - * Sets the appVer field. + * Sets the appVer field. */ public function setAppVer($appVer) { @@ -227,7 +213,7 @@ public function setAppVer($appVer) } /** - * Gets the userId field. + * Gets the userId field. */ public function getUserId() { @@ -236,7 +222,7 @@ public function getUserId() } /** - * Sets the userId field. + * Sets the userId field. */ public function setUserId($userId) { @@ -244,7 +230,7 @@ public function setUserId($userId) } /** - * Gets the tags field. + * Gets the tags field. */ public function getTags() { @@ -253,7 +239,7 @@ public function getTags() } /** - * Sets the tags field. + * Sets the tags field. */ public function setTags($tags) { @@ -261,7 +247,7 @@ public function setTags($tags) } /** - * Gets the data field. + * Gets the data field. */ public function getData() { @@ -270,18 +256,10 @@ public function getData() } /** - * Sets the data field. + * Sets the data field. */ public function setData($data) { $this->_data['data'] = $data; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Event_Data.php b/ApplicationInsights/Channel/Contracts/Event_Data.php index 625e449..6b4993a 100644 --- a/ApplicationInsights/Channel/Contracts/Event_Data.php +++ b/ApplicationInsights/Channel/Contracts/Event_Data.php @@ -2,27 +2,12 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Event_Data. +* Data contract class for type Event_Data. */ -class Event_Data +class Event_Data extends Base_Data implements Data_Interface { /** - * Data array that will store all the values. - */ - private $_data; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_envelopeTypeName; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_dataTypeName; - - /** - * Creates a new EventData. + * Creates a new EventData. */ function __construct() { @@ -33,40 +18,7 @@ function __construct() } /** - * Gets the envelopeTypeName field. - */ - public function getEnvelopeTypeName() - { - return $this->_envelopeTypeName; - } - - /** - * Gets the dataTypeName field. - */ - public function getDataTypeName() - { - return $this->_dataTypeName; - } - - /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the name field. + * Gets the name field. */ public function getName() { @@ -75,7 +27,7 @@ public function getName() } /** - * Sets the name field. + * Sets the name field. */ public function setName($name) { @@ -83,24 +35,7 @@ public function setName($name) } /** - * Gets the properties field. - */ - public function getProperties() - { - if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } - return NULL; - } - - /** - * Sets the properties field. - */ - public function setProperties($properties) - { - $this->_data['properties'] = $properties; - } - - /** - * Gets the measurements field. + * Gets the measurements field. */ public function getMeasurements() { @@ -109,18 +44,10 @@ public function getMeasurements() } /** - * Sets the measurements field. + * Sets the measurements field. */ public function setMeasurements($measurements) { $this->_data['measurements'] = $measurements; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Exception_Data.php b/ApplicationInsights/Channel/Contracts/Exception_Data.php index 6e3d497..11cf254 100644 --- a/ApplicationInsights/Channel/Contracts/Exception_Data.php +++ b/ApplicationInsights/Channel/Contracts/Exception_Data.php @@ -2,27 +2,12 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Exception_Data. +* Data contract class for type Exception_Data. */ -class Exception_Data +class Exception_Data extends Base_Data implements Data_Interface { /** - * Data array that will store all the values. - */ - private $_data; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_envelopeTypeName; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_dataTypeName; - - /** - * Creates a new ExceptionData. + * Creates a new ExceptionData. */ function __construct() { @@ -34,40 +19,7 @@ function __construct() } /** - * Gets the envelopeTypeName field. - */ - public function getEnvelopeTypeName() - { - return $this->_envelopeTypeName; - } - - /** - * Gets the dataTypeName field. - */ - public function getDataTypeName() - { - return $this->_dataTypeName; - } - - /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the handledAt field. + * Gets the handledAt field. */ public function getHandledAt() { @@ -76,7 +28,7 @@ public function getHandledAt() } /** - * Sets the handledAt field. + * Sets the handledAt field. */ public function setHandledAt($handledAt) { @@ -84,7 +36,7 @@ public function setHandledAt($handledAt) } /** - * Gets the exceptions field. + * Gets the exceptions field. */ public function getExceptions() { @@ -93,7 +45,7 @@ public function getExceptions() } /** - * Sets the exceptions field. + * Sets the exceptions field. */ public function setExceptions($exceptions) { @@ -101,7 +53,7 @@ public function setExceptions($exceptions) } /** - * Gets the severityLevel field. + * Gets the severityLevel field. */ public function getSeverityLevel() { @@ -110,7 +62,7 @@ public function getSeverityLevel() } /** - * Sets the severityLevel field. + * Sets the severityLevel field. */ public function setSeverityLevel($severityLevel) { @@ -118,24 +70,7 @@ public function setSeverityLevel($severityLevel) } /** - * Gets the properties field. - */ - public function getProperties() - { - if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } - return NULL; - } - - /** - * Sets the properties field. - */ - public function setProperties($properties) - { - $this->_data['properties'] = $properties; - } - - /** - * Gets the measurements field. + * Gets the measurements field. */ public function getMeasurements() { @@ -144,18 +79,10 @@ public function getMeasurements() } /** - * Sets the measurements field. + * Sets the measurements field. */ public function setMeasurements($measurements) { $this->_data['measurements'] = $measurements; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Exception_Details.php b/ApplicationInsights/Channel/Contracts/Exception_Details.php index a0c6d0b..d4f1bd3 100644 --- a/ApplicationInsights/Channel/Contracts/Exception_Details.php +++ b/ApplicationInsights/Channel/Contracts/Exception_Details.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Exception_Details. +* Data contract class for type Exception_Details. */ class Exception_Details { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new ExceptionDetails. + * Creates a new ExceptionDetails. */ function __construct() { @@ -22,7 +24,7 @@ function __construct() } /** - * Gets the id field. + * Gets the id field. */ public function getId() { @@ -31,7 +33,7 @@ public function getId() } /** - * Sets the id field. + * Sets the id field. */ public function setId($id) { @@ -39,7 +41,7 @@ public function setId($id) } /** - * Gets the outerId field. + * Gets the outerId field. */ public function getOuterId() { @@ -48,7 +50,7 @@ public function getOuterId() } /** - * Sets the outerId field. + * Sets the outerId field. */ public function setOuterId($outerId) { @@ -56,7 +58,7 @@ public function setOuterId($outerId) } /** - * Gets the typeName field. + * Gets the typeName field. */ public function getTypeName() { @@ -65,7 +67,7 @@ public function getTypeName() } /** - * Sets the typeName field. + * Sets the typeName field. */ public function setTypeName($typeName) { @@ -73,7 +75,7 @@ public function setTypeName($typeName) } /** - * Gets the message field. + * Gets the message field. */ public function getMessage() { @@ -82,7 +84,7 @@ public function getMessage() } /** - * Sets the message field. + * Sets the message field. */ public function setMessage($message) { @@ -90,7 +92,7 @@ public function setMessage($message) } /** - * Gets the hasFullStack field. + * Gets the hasFullStack field. */ public function getHasFullStack() { @@ -99,7 +101,7 @@ public function getHasFullStack() } /** - * Sets the hasFullStack field. + * Sets the hasFullStack field. */ public function setHasFullStack($hasFullStack) { @@ -107,7 +109,7 @@ public function setHasFullStack($hasFullStack) } /** - * Gets the stack field. + * Gets the stack field. */ public function getStack() { @@ -116,7 +118,7 @@ public function getStack() } /** - * Sets the stack field. + * Sets the stack field. */ public function setStack($stack) { @@ -124,7 +126,7 @@ public function setStack($stack) } /** - * Gets the parsedStack field. + * Gets the parsedStack field. */ public function getParsedStack() { @@ -133,18 +135,10 @@ public function getParsedStack() } /** - * Sets the parsedStack field. + * Sets the parsedStack field. */ public function setParsedStack($parsedStack) { $this->_data['parsedStack'] = $parsedStack; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Internal.php b/ApplicationInsights/Channel/Contracts/Internal.php index 398fbd9..c1c2ee6 100644 --- a/ApplicationInsights/Channel/Contracts/Internal.php +++ b/ApplicationInsights/Channel/Contracts/Internal.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Internal. +* Data contract class for type Internal. */ class Internal { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Internal. + * Creates a new Internal. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the sdkVersion field. + * Gets the sdkVersion field. */ public function getSdkVersion() { @@ -29,7 +31,7 @@ public function getSdkVersion() } /** - * Sets the sdkVersion field. + * Sets the sdkVersion field. */ public function setSdkVersion($sdkVersion) { @@ -37,7 +39,7 @@ public function setSdkVersion($sdkVersion) } /** - * Gets the agentVersion field. + * Gets the agentVersion field. */ public function getAgentVersion() { @@ -46,18 +48,10 @@ public function getAgentVersion() } /** - * Sets the agentVersion field. + * Sets the agentVersion field. */ public function setAgentVersion($agentVersion) { $this->_data['ai.internal.agentVersion'] = $agentVersion; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Json_Serializer.php b/ApplicationInsights/Channel/Contracts/Json_Serializer.php new file mode 100644 index 0000000..3839bb1 --- /dev/null +++ b/ApplicationInsights/Channel/Contracts/Json_Serializer.php @@ -0,0 +1,16 @@ +_data); + } +} diff --git a/ApplicationInsights/Channel/Contracts/Location.php b/ApplicationInsights/Channel/Contracts/Location.php index c04a3fe..c7904c0 100644 --- a/ApplicationInsights/Channel/Contracts/Location.php +++ b/ApplicationInsights/Channel/Contracts/Location.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Location. +* Data contract class for type Location. */ class Location { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Location. + * Creates a new Location. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the ip field. + * Gets the ip field. */ public function getIp() { @@ -29,18 +31,10 @@ public function getIp() } /** - * Sets the ip field. + * Sets the ip field. */ public function setIp($ip) { $this->_data['ai.location.ip'] = $ip; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Message_Data.php b/ApplicationInsights/Channel/Contracts/Message_Data.php index d1a03e7..043418f 100644 --- a/ApplicationInsights/Channel/Contracts/Message_Data.php +++ b/ApplicationInsights/Channel/Contracts/Message_Data.php @@ -2,27 +2,12 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Message_Data. +* Data contract class for type Message_Data. */ -class Message_Data +class Message_Data extends Base_Data implements Data_Interface { /** - * Data array that will store all the values. - */ - private $_data; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_envelopeTypeName; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_dataTypeName; - - /** - * Creates a new MessageData. + * Creates a new MessageData. */ function __construct() { @@ -33,40 +18,7 @@ function __construct() } /** - * Gets the envelopeTypeName field. - */ - public function getEnvelopeTypeName() - { - return $this->_envelopeTypeName; - } - - /** - * Gets the dataTypeName field. - */ - public function getDataTypeName() - { - return $this->_dataTypeName; - } - - /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the message field. + * Gets the message field. */ public function getMessage() { @@ -75,7 +27,7 @@ public function getMessage() } /** - * Sets the message field. + * Sets the message field. */ public function setMessage($message) { @@ -83,7 +35,7 @@ public function setMessage($message) } /** - * Gets the severityLevel field. + * Gets the severityLevel field. */ public function getSeverityLevel() { @@ -92,35 +44,10 @@ public function getSeverityLevel() } /** - * Sets the severityLevel field. + * Sets the severityLevel field. */ public function setSeverityLevel($severityLevel) { $this->_data['severityLevel'] = $severityLevel; } - - /** - * Gets the properties field. - */ - public function getProperties() - { - if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } - return NULL; - } - - /** - * Sets the properties field. - */ - public function setProperties($properties) - { - $this->_data['properties'] = $properties; - } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Metric_Data.php b/ApplicationInsights/Channel/Contracts/Metric_Data.php index d01cc87..37a46c4 100644 --- a/ApplicationInsights/Channel/Contracts/Metric_Data.php +++ b/ApplicationInsights/Channel/Contracts/Metric_Data.php @@ -2,27 +2,12 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Metric_Data. +* Data contract class for type Metric_Data. */ -class Metric_Data +class Metric_Data extends Base_Data implements Data_Interface { /** - * Data array that will store all the values. - */ - private $_data; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_envelopeTypeName; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_dataTypeName; - - /** - * Creates a new MetricData. + * Creates a new MetricData. */ function __construct() { @@ -33,40 +18,7 @@ function __construct() } /** - * Gets the envelopeTypeName field. - */ - public function getEnvelopeTypeName() - { - return $this->_envelopeTypeName; - } - - /** - * Gets the dataTypeName field. - */ - public function getDataTypeName() - { - return $this->_dataTypeName; - } - - /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the metrics field. + * Gets the metrics field. */ public function getMetrics() { @@ -75,35 +27,10 @@ public function getMetrics() } /** - * Sets the metrics field. + * Sets the metrics field. */ public function setMetrics($metrics) { $this->_data['metrics'] = $metrics; } - - /** - * Gets the properties field. - */ - public function getProperties() - { - if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } - return NULL; - } - - /** - * Sets the properties field. - */ - public function setProperties($properties) - { - $this->_data['properties'] = $properties; - } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Operation.php b/ApplicationInsights/Channel/Contracts/Operation.php index 5f65237..5c41c1d 100644 --- a/ApplicationInsights/Channel/Contracts/Operation.php +++ b/ApplicationInsights/Channel/Contracts/Operation.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Operation. +* Data contract class for type Operation. */ class Operation { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Operation. + * Creates a new Operation. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the id field. + * Gets the id field. */ public function getId() { @@ -29,7 +31,7 @@ public function getId() } /** - * Sets the id field. + * Sets the id field. */ public function setId($id) { @@ -37,7 +39,7 @@ public function setId($id) } /** - * Gets the name field. + * Gets the name field. */ public function getName() { @@ -46,7 +48,7 @@ public function getName() } /** - * Sets the name field. + * Sets the name field. */ public function setName($name) { @@ -54,7 +56,7 @@ public function setName($name) } /** - * Gets the parentId field. + * Gets the parentId field. */ public function getParentId() { @@ -63,7 +65,7 @@ public function getParentId() } /** - * Sets the parentId field. + * Sets the parentId field. */ public function setParentId($parentId) { @@ -71,7 +73,7 @@ public function setParentId($parentId) } /** - * Gets the rootId field. + * Gets the rootId field. */ public function getRootId() { @@ -80,18 +82,10 @@ public function getRootId() } /** - * Sets the rootId field. + * Sets the rootId field. */ public function setRootId($rootId) { $this->_data['ai.operation.rootId'] = $rootId; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Page_View_Data.php b/ApplicationInsights/Channel/Contracts/Page_View_Data.php index 2223959..bfda3f9 100644 --- a/ApplicationInsights/Channel/Contracts/Page_View_Data.php +++ b/ApplicationInsights/Channel/Contracts/Page_View_Data.php @@ -2,27 +2,12 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Page_View_Data. +* Data contract class for type Page_View_Data. */ -class Page_View_Data +class Page_View_Data extends Base_Data implements Data_Interface { /** - * Data array that will store all the values. - */ - private $_data; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_envelopeTypeName; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_dataTypeName; - - /** - * Creates a new PageViewData. + * Creates a new PageViewData. */ function __construct() { @@ -33,40 +18,7 @@ function __construct() } /** - * Gets the envelopeTypeName field. - */ - public function getEnvelopeTypeName() - { - return $this->_envelopeTypeName; - } - - /** - * Gets the dataTypeName field. - */ - public function getDataTypeName() - { - return $this->_dataTypeName; - } - - /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the url field. + * Gets the url field. */ public function getUrl() { @@ -75,7 +27,7 @@ public function getUrl() } /** - * Sets the url field. + * Sets the url field. */ public function setUrl($url) { @@ -83,7 +35,7 @@ public function setUrl($url) } /** - * Gets the name field. + * Gets the name field. */ public function getName() { @@ -92,7 +44,7 @@ public function getName() } /** - * Sets the name field. + * Sets the name field. */ public function setName($name) { @@ -100,7 +52,7 @@ public function setName($name) } /** - * Gets the duration field. + * Gets the duration field. */ public function getDuration() { @@ -109,7 +61,7 @@ public function getDuration() } /** - * Sets the duration field. + * Sets the duration field. */ public function setDuration($duration) { @@ -117,24 +69,7 @@ public function setDuration($duration) } /** - * Gets the properties field. - */ - public function getProperties() - { - if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } - return NULL; - } - - /** - * Sets the properties field. - */ - public function setProperties($properties) - { - $this->_data['properties'] = $properties; - } - - /** - * Gets the measurements field. + * Gets the measurements field. */ public function getMeasurements() { @@ -143,18 +78,10 @@ public function getMeasurements() } /** - * Sets the measurements field. + * Sets the measurements field. */ public function setMeasurements($measurements) { $this->_data['measurements'] = $measurements; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Request_Data.php b/ApplicationInsights/Channel/Contracts/Request_Data.php index 7b32921..11b69a1 100644 --- a/ApplicationInsights/Channel/Contracts/Request_Data.php +++ b/ApplicationInsights/Channel/Contracts/Request_Data.php @@ -2,27 +2,12 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Request_Data. +* Data contract class for type Request_Data. */ -class Request_Data +class Request_Data extends Base_Data implements Data_Interface { /** - * Data array that will store all the values. - */ - private $_data; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_envelopeTypeName; - - /** - * Needed to properly construct the JSON envelope. - */ - private $_dataTypeName; - - /** - * Creates a new RequestData. + * Creates a new RequestData. */ function __construct() { @@ -37,40 +22,7 @@ function __construct() } /** - * Gets the envelopeTypeName field. - */ - public function getEnvelopeTypeName() - { - return $this->_envelopeTypeName; - } - - /** - * Gets the dataTypeName field. - */ - public function getDataTypeName() - { - return $this->_dataTypeName; - } - - /** - * Gets the ver field. - */ - public function getVer() - { - if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } - return NULL; - } - - /** - * Sets the ver field. - */ - public function setVer($ver) - { - $this->_data['ver'] = $ver; - } - - /** - * Gets the id field. + * Gets the id field. */ public function getId() { @@ -79,7 +31,7 @@ public function getId() } /** - * Sets the id field. + * Sets the id field. */ public function setId($id) { @@ -87,7 +39,7 @@ public function setId($id) } /** - * Gets the name field. + * Gets the name field. */ public function getName() { @@ -96,7 +48,7 @@ public function getName() } /** - * Sets the name field. + * Sets the name field. */ public function setName($name) { @@ -104,7 +56,7 @@ public function setName($name) } /** - * Gets the startTime field. + * Gets the startTime field. */ public function getStartTime() { @@ -113,7 +65,7 @@ public function getStartTime() } /** - * Sets the startTime field. + * Sets the startTime field. */ public function setStartTime($startTime) { @@ -121,7 +73,7 @@ public function setStartTime($startTime) } /** - * Gets the duration field. + * Gets the duration field. */ public function getDuration() { @@ -130,7 +82,7 @@ public function getDuration() } /** - * Sets the duration field. + * Sets the duration field. */ public function setDuration($duration) { @@ -138,7 +90,7 @@ public function setDuration($duration) } /** - * Gets the responseCode field. + * Gets the responseCode field. */ public function getResponseCode() { @@ -147,7 +99,7 @@ public function getResponseCode() } /** - * Sets the responseCode field. + * Sets the responseCode field. */ public function setResponseCode($responseCode) { @@ -155,7 +107,7 @@ public function setResponseCode($responseCode) } /** - * Gets the success field. + * Gets the success field. */ public function getSuccess() { @@ -164,7 +116,7 @@ public function getSuccess() } /** - * Sets the success field. + * Sets the success field. */ public function setSuccess($success) { @@ -172,7 +124,7 @@ public function setSuccess($success) } /** - * Gets the httpMethod field. + * Gets the httpMethod field. */ public function getHttpMethod() { @@ -181,7 +133,7 @@ public function getHttpMethod() } /** - * Sets the httpMethod field. + * Sets the httpMethod field. */ public function setHttpMethod($httpMethod) { @@ -189,7 +141,7 @@ public function setHttpMethod($httpMethod) } /** - * Gets the url field. + * Gets the url field. */ public function getUrl() { @@ -198,7 +150,7 @@ public function getUrl() } /** - * Sets the url field. + * Sets the url field. */ public function setUrl($url) { @@ -206,24 +158,7 @@ public function setUrl($url) } /** - * Gets the properties field. - */ - public function getProperties() - { - if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } - return NULL; - } - - /** - * Sets the properties field. - */ - public function setProperties($properties) - { - $this->_data['properties'] = $properties; - } - - /** - * Gets the measurements field. + * Gets the measurements field. */ public function getMeasurements() { @@ -232,18 +167,10 @@ public function getMeasurements() } /** - * Sets the measurements field. + * Sets the measurements field. */ public function setMeasurements($measurements) { $this->_data['measurements'] = $measurements; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Session.php b/ApplicationInsights/Channel/Contracts/Session.php index b88c51f..047a854 100644 --- a/ApplicationInsights/Channel/Contracts/Session.php +++ b/ApplicationInsights/Channel/Contracts/Session.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Session. +* Data contract class for type Session. */ class Session { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new Session. + * Creates a new Session. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the id field. + * Gets the id field. */ public function getId() { @@ -29,7 +31,7 @@ public function getId() } /** - * Sets the id field. + * Sets the id field. */ public function setId($id) { @@ -37,7 +39,7 @@ public function setId($id) } /** - * Gets the isFirst field. + * Gets the isFirst field. */ public function getIsFirst() { @@ -46,7 +48,7 @@ public function getIsFirst() } /** - * Sets the isFirst field. + * Sets the isFirst field. */ public function setIsFirst($isFirst) { @@ -54,7 +56,7 @@ public function setIsFirst($isFirst) } /** - * Gets the isNew field. + * Gets the isNew field. */ public function getIsNew() { @@ -63,18 +65,10 @@ public function getIsNew() } /** - * Sets the isNew field. + * Sets the isNew field. */ public function setIsNew($isNew) { $this->_data['ai.session.isNew'] = var_export($isNew, true);; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Stack_Frame.php b/ApplicationInsights/Channel/Contracts/Stack_Frame.php index 4eb9fee..189a122 100644 --- a/ApplicationInsights/Channel/Contracts/Stack_Frame.php +++ b/ApplicationInsights/Channel/Contracts/Stack_Frame.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type Stack_Frame. +* Data contract class for type Stack_Frame. */ class Stack_Frame { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new StackFrame. + * Creates a new StackFrame. */ function __construct() { @@ -21,7 +23,7 @@ function __construct() } /** - * Gets the level field. + * Gets the level field. */ public function getLevel() { @@ -30,7 +32,7 @@ public function getLevel() } /** - * Sets the level field. + * Sets the level field. */ public function setLevel($level) { @@ -38,7 +40,7 @@ public function setLevel($level) } /** - * Gets the method field. + * Gets the method field. */ public function getMethod() { @@ -47,7 +49,7 @@ public function getMethod() } /** - * Sets the method field. + * Sets the method field. */ public function setMethod($method) { @@ -55,7 +57,7 @@ public function setMethod($method) } /** - * Gets the assembly field. + * Gets the assembly field. */ public function getAssembly() { @@ -64,7 +66,7 @@ public function getAssembly() } /** - * Sets the assembly field. + * Sets the assembly field. */ public function setAssembly($assembly) { @@ -72,7 +74,7 @@ public function setAssembly($assembly) } /** - * Gets the fileName field. + * Gets the fileName field. */ public function getFileName() { @@ -81,7 +83,7 @@ public function getFileName() } /** - * Sets the fileName field. + * Sets the fileName field. */ public function setFileName($fileName) { @@ -89,7 +91,7 @@ public function setFileName($fileName) } /** - * Gets the line field. + * Gets the line field. */ public function getLine() { @@ -98,18 +100,10 @@ public function getLine() } /** - * Sets the line field. + * Sets the line field. */ public function setLine($line) { $this->_data['line'] = $line; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/User.php b/ApplicationInsights/Channel/Contracts/User.php index 01e1758..bfe8ba1 100644 --- a/ApplicationInsights/Channel/Contracts/User.php +++ b/ApplicationInsights/Channel/Contracts/User.php @@ -2,17 +2,19 @@ namespace ApplicationInsights\Channel\Contracts; /** -* Data contract class for type User. +* Data contract class for type User. */ class User { + use Json_Serializer; + /** - * Data array that will store all the values. + * Data array that will store all the values. */ private $_data; /** - * Creates a new User. + * Creates a new User. */ function __construct() { @@ -20,7 +22,7 @@ function __construct() } /** - * Gets the accountAcquisitionDate field. + * Gets the accountAcquisitionDate field. */ public function getAccountAcquisitionDate() { @@ -29,7 +31,7 @@ public function getAccountAcquisitionDate() } /** - * Sets the accountAcquisitionDate field. + * Sets the accountAcquisitionDate field. */ public function setAccountAcquisitionDate($accountAcquisitionDate) { @@ -37,7 +39,7 @@ public function setAccountAcquisitionDate($accountAcquisitionDate) } /** - * Gets the accountId field. + * Gets the accountId field. */ public function getAccountId() { @@ -46,7 +48,7 @@ public function getAccountId() } /** - * Sets the accountId field. + * Sets the accountId field. */ public function setAccountId($accountId) { @@ -54,7 +56,7 @@ public function setAccountId($accountId) } /** - * Gets the userAgent field. + * Gets the userAgent field. */ public function getUserAgent() { @@ -63,7 +65,7 @@ public function getUserAgent() } /** - * Sets the userAgent field. + * Sets the userAgent field. */ public function setUserAgent($userAgent) { @@ -71,7 +73,7 @@ public function setUserAgent($userAgent) } /** - * Gets the id field. + * Gets the id field. */ public function getId() { @@ -80,18 +82,10 @@ public function getId() } /** - * Sets the id field. + * Sets the id field. */ public function setId($id) { $this->_data['ai.user.id'] = $id; } - - /** - * Overrides JSON serialization for this class. - */ - public function jsonSerialize() - { - return Utils::removeEmptyValues($this->_data); - } } diff --git a/ApplicationInsights/Channel/Contracts/Version_Manager.php b/ApplicationInsights/Channel/Contracts/Version_Manager.php new file mode 100644 index 0000000..83c7628 --- /dev/null +++ b/ApplicationInsights/Channel/Contracts/Version_Manager.php @@ -0,0 +1,25 @@ +_data)) { return $this->_data['ver']; } + return NULL; + } + + /** + * Sets the ver field. + */ + public function setVer($ver) + { + $this->_data['ver'] = $ver; + } +} diff --git a/ApplicationInsights/Channel/Telemetry_Channel.php b/ApplicationInsights/Channel/Telemetry_Channel.php index 75fc6bf..d207f81 100644 --- a/ApplicationInsights/Channel/Telemetry_Channel.php +++ b/ApplicationInsights/Channel/Telemetry_Channel.php @@ -11,13 +11,13 @@ class Telemetry_Channel * @var string */ private $_endpointUrl; - + /** * The queue of already serialized JSON objects to send. * @var array */ private $_queue; - + /** * Initializes a new Telemetry_Channel. * @param string $endpointUrl Optional. Allows caller to override which endpoint to send data to. @@ -27,7 +27,7 @@ function __construct($endpointUrl = 'https://dc.services.visualstudio.com/v2/tra $this->_endpointUrl = $endpointUrl; $this->_queue = array(); } - + /** * Returns the current URL this TelemetrySender will send to. * @return string @@ -36,7 +36,7 @@ public function getEndpointUrl() { return $this->_endpointUrl; } - + /** * Sets the current URL this TelemetrySender will send to. * @param string $endpointUrl @@ -45,25 +45,25 @@ public function setEndpointUrl($endpointUrl) { $this->_endpointUrl = $endpointUrl; } - + /** - * Returns the current queue. + * Returns the current queue. * @return array */ public function getQueue() { return $this->_queue; } - + /** - * Sets the current queue. + * Sets the current queue. * @param array $queue */ public function setQueue($queue) { $this->_queue = $queue; } - + /** * Summary of getSerializedQueue * @return string JSON representation of queue. @@ -75,36 +75,36 @@ public function getSerializedQueue() { array_push($queueToEncode, Contracts\Utils::getUnderlyingData($dataItem->jsonSerialize())); } - + return json_encode($queueToEncode); } - + /** * Writes the item into the sending queue for subsequent processing. - * @param mixed $data The telemetry item to send. - * @param \ApplicationInsights\Telemetry_Context $telemetryContext The context to use. + * @param \ApplicationInsights\Channel\Contracts\Data_Interface $data The telemetry item to send. + * @param \ApplicationInsights\Telemetry_Context $telemetryContext The context to use. */ - public function addToQueue($data, \ApplicationInsights\Telemetry_Context $telemetryContext) + public function addToQueue(\ApplicationInsights\Channel\Contracts\Data_Interface $data, \ApplicationInsights\Telemetry_Context $telemetryContext) { // If no data or context provided, we just return to not cause upstream issues as a result of telemetry if ($data == NULL || $telemetryContext == NULL) { return; } - + $envelope = new Contracts\Envelope(); - + // Main envelope properties $envelope->setName($data->getEnvelopeTypeName()); $envelope->setTime(Contracts\Utils::returnISOStringForTime()); - + // Set the SDK version $internalContext = new Contracts\Internal(); $internalContext->setSdkVersion('php:0.3.2'); - + // The instrumentation key to use $envelope->setInstrumentationKey($telemetryContext->getInstrumentationKey()); - + // Copy all context into the Tags array $envelope->setTags(array_merge($telemetryContext->getApplicationContext()->jsonSerialize(), $telemetryContext->getDeviceContext()->jsonSerialize(), @@ -113,7 +113,7 @@ public function addToQueue($data, \ApplicationInsights\Telemetry_Context $teleme $telemetryContext->getSessionContext()->jsonSerialize(), $telemetryContext->getUserContext()->jsonSerialize(), $internalContext->jsonSerialize())); - + // Merge properties from global context to local context $contextProperties = $telemetryContext->getProperties(); if (method_exists($data, 'getProperties') == true && $contextProperties != NULL && count($contextProperties) > 0) @@ -132,18 +132,18 @@ public function addToQueue($data, \ApplicationInsights\Telemetry_Context $teleme } $data->setProperties($dataProperties); } - + // Embed the main data object $envelope->setData(new Contracts\Data()); $envelope->getData()->setBaseType($data->getDataTypeName()); $envelope->getData()->setBaseData($data); - + array_push($this->_queue, $envelope); } - + /** * Summary of send - * @param mixed $telemetryItem + * @param mixed $telemetryItem */ public function send() { @@ -151,25 +151,25 @@ public function send() { return; } - + $serializedTelemetryItem = $this->getSerializedQueue(); - - $headersArray = array('Accept' => 'application/json', + + $headersArray = array('Accept' => 'application/json', 'Content-Type' => 'application/json; charset=utf-8'); - + if (array_key_exists('HTTP_USER_AGENT', $_SERVER) == true) { $headersArray['User-Agent'] = $_SERVER['HTTP_USER_AGENT']; } - + $body = utf8_encode($serializedTelemetryItem); - + if (class_exists('\GuzzleHttp\Client') == true) { // Standard case if properly pulled in composer dependencies - + $client = new \GuzzleHttp\Client(); - + $client->post($this->_endpointUrl, array( 'headers' => $headersArray, 'body' => $body, @@ -179,7 +179,7 @@ public function send() } else if (function_exists('wp_remote_post')) { - // Used in WordPress + // Used in WordPress wp_remote_post($this->_endpointUrl, array( 'method' => 'POST', 'blocking' => true, diff --git a/ApplicationInsights/Telemetry_Client.php b/ApplicationInsights/Telemetry_Client.php index c25a0fc..f590001 100644 --- a/ApplicationInsights/Telemetry_Client.php +++ b/ApplicationInsights/Telemetry_Client.php @@ -86,17 +86,17 @@ public function trackPageView($name, $url, $duration = 0, $properties = NULL, $m */ public function trackMetric($name, $value, $type = NULL, $count = NULL, $min = NULL, $max = NULL, $stdDev = NULL, $properties = NULL) { - $dataPoiint = new Channel\Contracts\Data_Point(); - $dataPoiint->setName($name); - $dataPoiint->setValue($value); - $dataPoiint->setKind($type == NULL ? Channel\Contracts\Data_Point_Type::Aggregation : $type); - $dataPoiint->setCount($count); - $dataPoiint->setMin($min); - $dataPoiint->setMax($max); - $dataPoiint->setStdDev($stdDev); + $dataPoint = new Channel\Contracts\Data_Point(); + $dataPoint->setName($name); + $dataPoint->setValue($value); + $dataPoint->setKind($type == NULL ? Channel\Contracts\Data_Point_Type::Aggregation : $type); + $dataPoint->setCount($count); + $dataPoint->setMin($min); + $dataPoint->setMax($max); + $dataPoint->setStdDev($stdDev); $data = new Channel\Contracts\Metric_Data(); - $data->setMetrics(array($dataPoiint)); + $data->setMetrics(array($dataPoint)); if ($properties != NULL) { $data->setProperties($properties); @@ -274,6 +274,47 @@ public function trackException(\Exception $ex, $properties = NULL, $measurements $this->_channel->addToQueue($data, $this->_context); } + /** + * Sends an Dependency_Data to the Application Insights service. + * @param string $name Name of the dependency. + * @param \ApplicationInsights\Channel\Dependency_Type::Value $type The Dependency type of value being sent. + * @param string $commandName Command/Method of the dependency. + * @param int $startTime The timestamp at which the request started. + * @param int $durationInMilliseconds The duration, in milliseconds, of the request. + * @param bool $isSuccessful Whether or not the request was successful. + * @param int $resultCode The result code of the request. + * @param bool $isAsync Whether or not the request was asyncronous. + * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. + */ + public function trackDependency( + $name, + $type = Channel\Contracts\Dependency_Type::OTHER, + $commandName = NULL, + $startTime = NULL, + $durationInMilliseconds = 0, + $isSuccessful = true, + $resultCode = NULL, + $isAsync = NULL, + $properties = NULL) + { + $data = new Channel\Contracts\Dependency_Data(); + $data->setName($name); + $data->setDependencyKind($type); + $data->setCommandName($commandName); + $data->setStartTime(Channel\Contracts\Utils::returnISOStringForTime($startTime)); + $data->setDuration(Channel\Contracts\Utils::convertMillisecondsToTimeSpan($durationInMilliseconds)); + $data->setSuccess($isSuccessful); + $data->setResultCode($resultCode); + $data->setAsync($isAsync); + + if ($properties != NULL) + { + $data->setProperties($properties); + } + + $this->_channel->addToQueue($data, $this->_context); + } + /** * Flushes the underlying Telemetry_Channel queue. */ diff --git a/ApplicationInsights/Tests/Telemetry_Client_Test.php b/ApplicationInsights/Tests/Telemetry_Client_Test.php index 6852508..c5ed90b 100644 --- a/ApplicationInsights/Tests/Telemetry_Client_Test.php +++ b/ApplicationInsights/Tests/Telemetry_Client_Test.php @@ -7,13 +7,13 @@ class Telemetry_Client_Test extends \PHPUnit_Framework_TestCase { private $_telemetryClient; - + protected function setUp() { $this->_telemetryClient = new \ApplicationInsights\Telemetry_Client(); - + $context = $this->_telemetryClient->getContext(); - + $context->setInstrumentationKey(Utils::getTestInstrumentationKey()); $context->setApplicationContext(Utils::getSampleApplicationContext()); $context->setDeviceContext(Utils::getSampleDeviceContext()); @@ -21,13 +21,13 @@ protected function setUp() $context->setOperationContext(Utils::getSampleOperationContext()); $context->setSessionContext(Utils::getSampleSessionContext()); $context->setUserContext(Utils::getSampleUserContext()); - + $context->setProperties(Utils::getSampleCustomProperties()); } - + /** * Tests a completely filled exception. - * + * * Ensure this method doesn't move in the source, if it does, the test will fail and needs to have a line number adjusted. */ public function testCompleteException() @@ -35,29 +35,29 @@ public function testCompleteException() try { Utils::throwNestedException(3); - } + } catch (\Exception $ex) { $this->_telemetryClient->trackException($ex, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); } - + $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); $queue = $this->adjustDataInQueue($queue); $searchStrings = array("\\"); $replaceStrings = array("\\\\"); - - $expectedString = str_replace($searchStrings, $replaceStrings, '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","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,"handledAt":"UserCode","exceptions":[{"typeName":"Exception","message":"testException in G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php on line 130","hasFullStack":true,"id":1,"parsedStack":[{"level":"14","method":"main","assembly":"PHPUnit_TextUI_Command","fileName":"C:\\Users\\jakubo\\AppData\\Local\\Microsoft\\VisualStudio\\12.0\\Extensions\\DEVSENSE\\PHP Tools for Visual Studio 2013 1.14.5747\\phpunit-3.7.phar","line":612},{"level":"13","method":"run","assembly":"PHPUnit_TextUI_Command","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":129},{"level":"12","method":"doRun","assembly":"PHPUnit_TextUI_TestRunner","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":176},{"level":"11","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\TextUI\\TestRunner.php","line":423},{"level":"10","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":751},{"level":"9","method":"run","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":751},{"level":"8","method":"run","assembly":"PHPUnit_Framework_TestResult","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":612},{"level":"7","method":"runBare","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestResult.php","line":643},{"level":"6","method":"runTest","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":766},{"level":"5","method":"invokeArgs","assembly":"ReflectionMethod","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":881},{"level":"4","method":"testCompleteException","assembly":"ApplicationInsights\\Tests\\Telemetry_Client_Test"},{"level":"3","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Telemetry_Client_Test.php","line":37},{"level":"2","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"1","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"0","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133}]}],"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"ExceptionData"}}]'); + + $expectedString = str_replace($searchStrings, $replaceStrings, '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","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,"handledAt":"UserCode","exceptions":[{"typeName":"Exception","message":"testException in G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php on line 130","hasFullStack":true,"id":1,"parsedStack":[{"level":"14","method":"main","assembly":"PHPUnit_TextUI_Command","fileName":"C:\\Users\\jakubo\\AppData\\Local\\Microsoft\\VisualStudio\\12.0\\Extensions\\DEVSENSE\\PHP Tools for Visual Studio 2013 1.14.5747\\phpunit-3.7.phar","line":52},{"level":"13","method":"run","assembly":"PHPUnit_TextUI_Command","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":100},{"level":"12","method":"doRun","assembly":"PHPUnit_TextUI_TestRunner","fileName":"phar://C:/Users/jakubo/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/DEVSENSE/PHP Tools for Visual Studio 2013 1.14.5747/phpunit-3.7.phar/phpunit/TextUI/Command.php","line":149},{"level":"11","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\TextUI\\TestRunner.php","line":440},{"level":"10","method":"run","assembly":"PHPUnit_Framework_TestSuite","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":722},{"level":"9","method":"run","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php","line":722},{"level":"8","method":"run","assembly":"PHPUnit_Framework_TestResult","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":724},{"level":"7","method":"runBare","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestResult.php","line":612},{"level":"6","method":"runTest","assembly":"PHPUnit_Framework_TestCase","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":768},{"level":"5","method":"invokeArgs","assembly":"ReflectionMethod","fileName":"G:\\GitHub\\AppInsights-PHP\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php","line":908},{"level":"4","method":"testCompleteException","assembly":"ApplicationInsights\\Tests\\Telemetry_Client_Test"},{"level":"3","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Telemetry_Client_Test.php","line":37},{"level":"2","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"1","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133},{"level":"0","method":"throwNestedException","assembly":"ApplicationInsights\\Tests\\Utils","fileName":"G:\\GitHub\\AppInsights-PHP\\ApplicationInsights\\Tests\\Utils.php","line":133}]}],"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"ExceptionData"}}]'); $expectedValue = json_decode($expectedString, true); - + $this->assertEquals($this->removeMachineSpecificExceptionData($queue), $this->removeMachineSpecificExceptionData($expectedValue)); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } } - + /** * Verifies the object is constructed properly. */ @@ -67,7 +67,7 @@ public function testConstructor() $this->assertEquals($telemetryClient->getContext(), new \ApplicationInsights\Telemetry_Context()); $this->assertEquals($telemetryClient->getChannel(), new \ApplicationInsights\Channel\Telemetry_Channel()); } - + /** * Tests a completely filled event. */ @@ -79,15 +79,15 @@ public function testCompleteEvent() $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); $queue = $this->adjustDataInQueue($queue); $expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.Event","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,"name":"myEvent","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration":42}},"baseType":"EventData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.Event","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,"name":"myEvent2","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration":42}},"baseType":"EventData"}}]', true); - + $this->assertEquals($queue, $expectedValue); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } } - + /** * Tests a completely filled page view. */ @@ -99,15 +99,15 @@ public function testCompletePageView() $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); $queue = $this->adjustDataInQueue($queue); $expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.PageView","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,"name":"myPageView","url":"http:\/\/www.foo.com","duration":256,"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration":42}},"baseType":"PageViewData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.PageView","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,"name":"myPageView2","url":"http:\/\/www.foo.com","duration":256,"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration":42}},"baseType":"PageViewData"}}]', true); - + $this->assertEquals($queue, $expectedValue); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } } - + /** * Tests a completely filled metric. */ @@ -119,15 +119,15 @@ public function testCompleteMetric() $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); $queue = $this->adjustDataInQueue($queue); $expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.Metric","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,"metrics":[{"name":"myMetric","kind":1,"value":42,"count":5,"max":1,"stdDev":0.2}],"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"MetricData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.Metric","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,"metrics":[{"name":"myMetric2","kind":1,"value":42,"count":5,"max":1,"stdDev":0.2}],"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"MetricData"}}]', true); - + $this->assertEquals($queue, $expectedValue); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } } - + /** * Tests a completely filled request. */ @@ -135,19 +135,19 @@ public function testCompleteRequest() { $this->_telemetryClient->trackRequest('myRequest', 'http://foo.bar', time(), 3754, 200, true, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); $this->_telemetryClient->trackRequest('myRequest2', 'http://foo.bar', time(), 3754, 200, false, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); - + $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); $queue = $this->adjustDataInQueue($queue); $expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.Request","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,"id":"ID_PLACEHOLDER","startTime":"TIME_PLACEHOLDER","duration":"00:00:03.754","responseCode":200,"success":true,"name":"myRequest","url":"http:\/\/foo.bar","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"RequestData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.Request","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,"id":"ID_PLACEHOLDER","startTime":"TIME_PLACEHOLDER","duration":"00:00:03.754","responseCode":200,"success":false,"name":"myRequest2","url":"http:\/\/foo.bar","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"RequestData"}}]', true); - + $this->assertEquals($queue, $expectedValue); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } } - + /** * Tests a completely filled request created by begin/end pair. */ @@ -161,22 +161,22 @@ public function testCompleteBeginEndRequest() // now queue that request, and another begin/end pair $this->_telemetryClient->endRequest($request, 3754, 200, true, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); - + $request = $this->_telemetryClient->beginRequest('myRequest2', 'http://foo.bar', time()); $this->_telemetryClient->endRequest($request, 3754, 200, false, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); - + $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); $queue = $this->adjustDataInQueue($queue); // expected to look exactly the same as testCompleteRequest $expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.Request","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,"id":"ID_PLACEHOLDER","startTime":"TIME_PLACEHOLDER","duration":"00:00:03.754","responseCode":200,"success":true,"name":"myRequest","url":"http:\/\/foo.bar","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"RequestData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.Request","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,"id":"ID_PLACEHOLDER","startTime":"TIME_PLACEHOLDER","duration":"00:00:03.754","responseCode":200,"success":false,"name":"myRequest2","url":"http:\/\/foo.bar","properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"},"measurements":{"duration_inner":42}},"baseType":"RequestData"}}]', true); - + $this->assertEquals($queue, $expectedValue); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } - } + } /** * Tests a completely filled message. @@ -189,15 +189,36 @@ public function testCompleteMessage() $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); - + $this->assertEquals($queue, $expectedValue); - + if (Utils::sendDataToServer()) { $this->_telemetryClient->flush(); } } - + + /** + * Tests a completely filled dependency. + */ + public function testCompleteDependency() + { + $this->_telemetryClient->trackDependency('Sql', \ApplicationInsights\Channel\Contracts\Dependency_Type::SQL, 'SELECT * FROM hola;', time(), 100, true, 200, true, ['InlineProperty' => 'test_value']); + $this->_telemetryClient->trackDependency('http://example.com/api/method', \ApplicationInsights\Channel\Contracts\Dependency_Type::HTTP, null, time(), 100, false, 503, false, ['InlineProperty' => 'test_value']); + $this->_telemetryClient->trackDependency('Other', \ApplicationInsights\Channel\Contracts\Dependency_Type::OTHER, 'Other text', time(), 100, true, 200, true, ['InlineProperty' => 'test_value']); + + $queue = json_decode($this->_telemetryClient->getChannel()->getSerializedQueue(), true); + $queue = $this->adjustDataInQueue($queue); + $expectedValue = json_decode('[{"ver":1,"name":"Microsoft.ApplicationInsights.RemoteDependency","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,"name":"Sql","commandName":"SELECT * FROM hola;","startTime":"TIME_PLACEHOLDER","duration":"00:00:00.100","success":true,"resultCode":"200","async":true,"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"RemoteDependencyData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.RemoteDependency","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,"name":"http:\/\/example.com\/api\/method","dependencyKind":1,"startTime":"TIME_PLACEHOLDER","duration":"00:00:00.100","success":false,"resultCode":"503","async":false,"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"RemoteDependencyData"}},{"ver":1,"name":"Microsoft.ApplicationInsights.RemoteDependency","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,"name":"Other","dependencyKind":2,"commandName":"Other text","startTime":"TIME_PLACEHOLDER","duration":"00:00:00.100","success":true,"resultCode":"200","async":true,"properties":{"InlineProperty":"test_value","MyCustomProperty":42,"MyCustomProperty2":"test"}},"baseType":"RemoteDependencyData"}}]', true); + + $this->assertEquals($queue, $expectedValue); + + if (Utils::sendDataToServer()) + { + $this->_telemetryClient->flush(); + } + } + /** * Removes machine specific data from exceptions. * @param array $queue The queue of items @@ -211,20 +232,20 @@ private function removeMachineSpecificExceptionData($queue) { if (preg_match('([A-Za-z]+\.php)', $exception['message'], $matches) == 1) { - $exception['message'] = $matches[0]; + $exception['message'] = $matches[0]; } else { $exception['message'] = NULL; } - + foreach ($exception['parsedStack'] as &$stackFrame) { if (array_key_exists('fileName', $stackFrame)) { if (preg_match('([A-Za-z]+\.php)', $stackFrame['fileName'], $matches) == 1) { - $stackFrame['fileName'] = $matches[0]; + $stackFrame['fileName'] = $matches[0]; } else { @@ -236,7 +257,7 @@ private function removeMachineSpecificExceptionData($queue) } return $queue; } - + /** * Remotes transient data from validation queues * @param array $queue The queue of items diff --git a/README.md b/README.md index 9bbbc97..2abb7fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Application Insights for PHP # -This project extends the Application Insights API surface to support PHP. [Application Insights](http://azure.microsoft.com/en-us/services/application-insights/) is a service that allows developers to keep their application available, performing and succeeding. This PHP module will allow you to send telemetry of various kinds (event, trace, exception, etc.) to the Application Insights service where they can be visualized in the Azure Portal. +This project extends the Application Insights API surface to support PHP. [Application Insights](http://azure.microsoft.com/en-us/services/application-insights/) is a service that allows developers to keep their application available, performing and succeeding. This PHP module will allow you to send telemetry of various kinds (event, trace, exception, etc.) to the Application Insights service where they can be visualized in the Azure Portal. ## Requirements ## @@ -10,7 +10,7 @@ For opening the project in Microsoft Visual Studio you will need [PHP Tools for ## Installation ## -We've published a package you can find on [Packagist](https://packagist.org/packages/microsoft/application-insights). In order to use it, first, you'll need to get [Composer](https://getcomposer.org/). +We've published a package you can find on [Packagist](https://packagist.org/packages/microsoft/application-insights). In order to use it, first, you'll need to get [Composer](https://getcomposer.org/). Once you've setup your project to use Composer, just add a reference to our package with whichever version you'd like to use to your composer.json file. @@ -105,29 +105,29 @@ $telemetryClient->flush(); try { // Do something to throw an exception -} +} catch (\Exception $ex) { $telemetryClient->trackException($ex, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); $telemetryClient->flush(); } -``` +``` **Registering an exception handler** ```php class Handle_Exceptions { private $_telemetryClient; - + public function __construct() { $this->_telemetryClient = new \ApplicationInsights\Telemetry_Client(); $this->_telemetryClient->getContext()->setInstrumentationKey('YOUR INSTRUMENTATION KEY'); - + set_exception_handler(array($this, 'exceptionHandler')); } - + function exceptionHandler(\Exception $exception) { if ($exception != NULL) @@ -138,3 +138,21 @@ class Handle_Exceptions } } ``` + +**Sending a successful SQL dependency telemetry item** +```php +$telemetryClient->trackDependency('MySQL', \ApplicationInsights\Channel\Contracts\Dependency_Type::OTHER, 'SELECT * FROM table;', time(), 122, true); +$telemetryClient->flush(); +``` + +**Sending a failed HTTP dependency telemetry item** +```php +$telemetryClient->trackDependency('http://example.com/api/method', \ApplicationInsights\Channel\Contracts\Dependency_Type::HTTP, null, time(), 324, false, 503); +$telemetryClient->flush(); +``` + +**Sending any other kind dependency telemetry item** +```php +$telemetryClient->trackDependency('Whatever Service', \ApplicationInsights\Channel\Contracts\Dependency_Type::OTHER, 'Service Command', time(), 23, true); +$telemetryClient->flush(); +``` diff --git a/phpunit.xml b/phpunit.xml index 5175240..b42f5d5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,4 +1,4 @@ - + bootstrap="/ApplicationInsights/Tests/Bootstrap.php" cacheTokens="false" colors="false"