├── .gitattributes ├── .gitignore ├── .travis.yml ├── Application.Insights.phpproj ├── Application.Insights.sln ├── ApplicationInsights ├── Channel │ ├── Contracts │ │ ├── Application.php │ │ ├── Availability_Data.php │ │ ├── Base_Data.php │ │ ├── Cloud.php │ │ ├── Data.php │ │ ├── Data_Interface.php │ │ ├── Data_Point.php │ │ ├── Data_Point_Type.php │ │ ├── Dependency_Data.php │ │ ├── Device.php │ │ ├── Envelope.php │ │ ├── Event_Data.php │ │ ├── Exception_Data.php │ │ ├── Exception_Details.php │ │ ├── Internal.php │ │ ├── Json_Serializer.php │ │ ├── Location.php │ │ ├── Message_Data.php │ │ ├── Message_Severity_Level.php │ │ ├── Metric_Data.php │ │ ├── Operation.php │ │ ├── Page_View_Data.php │ │ ├── Page_View_Perf_Data.php │ │ ├── Request_Data.php │ │ ├── Session.php │ │ ├── Severity_Level.php │ │ ├── Stack_Frame.php │ │ ├── User.php │ │ ├── Utils.php │ │ └── Version_Manager.php │ └── Telemetry_Channel.php ├── Current_Session.php ├── Current_User.php ├── Telemetry_Client.php └── Telemetry_Context.php ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── Schema ├── PublicSchema │ ├── AvailabilityData.bond │ ├── Base.bond │ ├── ContextTagKeys.bond │ ├── Data.bond │ ├── DataPoint.bond │ ├── DataPointType.bond │ ├── Domain.bond │ ├── Envelope.bond │ ├── EventData.bond │ ├── ExceptionData.bond │ ├── ExceptionDetails.bond │ ├── MessageData.bond │ ├── MetricData.bond │ ├── PageViewData.bond │ ├── PageViewPerfData.bond │ ├── RemoteDependencyData.bond │ ├── RequestData.bond │ ├── SeverityLevel.bond │ └── StackFrame.bond └── generateSchema.ps1 ├── Tests ├── Bootstrap.php ├── Channel │ ├── Contracts │ │ └── Utils_Test.php │ └── Telemetry_Channel_Test.php ├── Current_Session_Test.php ├── Current_User_Test.php ├── Telemetry_Client_Test.php ├── Telemetry_Context_Test.php └── Utils.php ├── composer.json ├── phpdoc.xml └── phpunit.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Composer 2 | vendor 3 | *.lock 4 | *.phar 5 | 6 | ## Ignore Visual Studio temporary files, build results, and 7 | ## files generated by popular Visual Studio add-ons. 8 | 9 | # User-specific files 10 | *.suo 11 | *.user 12 | *.sln.docstates 13 | 14 | # Build results 15 | 16 | [Dd]ebug/ 17 | [Rr]elease/ 18 | x64/ 19 | build/ 20 | [Bb]in/ 21 | [Oo]bj/ 22 | 23 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 24 | !packages/*/build/ 25 | 26 | # MSTest test Results 27 | [Tt]est[Rr]esult*/ 28 | [Bb]uild[Ll]og.* 29 | 30 | *_i.c 31 | *_p.c 32 | *.ilk 33 | *.meta 34 | *.obj 35 | *.pch 36 | *.pdb 37 | *.pgc 38 | *.pgd 39 | *.rsp 40 | *.sbr 41 | *.tlb 42 | *.tli 43 | *.tlh 44 | *.tmp 45 | *.tmp_proj 46 | *.log 47 | *.vspscc 48 | *.vssscc 49 | .builds 50 | *.pidb 51 | *.log 52 | *.scc 53 | 54 | # Visual C++ cache files 55 | ipch/ 56 | *.aps 57 | *.ncb 58 | *.opensdf 59 | *.sdf 60 | *.cachefile 61 | 62 | # Visual Studio profiler 63 | *.psess 64 | *.vsp 65 | *.vspx 66 | 67 | # Guidance Automation Toolkit 68 | *.gpState 69 | 70 | # ReSharper is a .NET coding add-in 71 | _ReSharper*/ 72 | *.[Rr]e[Ss]harper 73 | 74 | # TeamCity is a build add-in 75 | _TeamCity* 76 | 77 | # DotCover is a Code Coverage Tool 78 | *.dotCover 79 | 80 | # NCrunch 81 | *.ncrunch* 82 | .*crunch*.local.xml 83 | 84 | # Installshield output folder 85 | [Ee]xpress/ 86 | 87 | # DocProject is a documentation generator add-in 88 | DocProject/buildhelp/ 89 | DocProject/Help/*.HxT 90 | DocProject/Help/*.HxC 91 | DocProject/Help/*.hhc 92 | DocProject/Help/*.hhk 93 | DocProject/Help/*.hhp 94 | DocProject/Help/Html2 95 | DocProject/Help/html 96 | 97 | # Click-Once directory 98 | publish/ 99 | 100 | # Publish Web Output 101 | *.Publish.xml 102 | 103 | # NuGet Packages Directory 104 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 105 | #packages/ 106 | 107 | # Windows Azure Build Output 108 | csx 109 | *.build.csdef 110 | 111 | # Windows Store app package directory 112 | AppPackages/ 113 | 114 | # Others 115 | sql/ 116 | *.Cache 117 | ClientBin/ 118 | [Ss]tyle[Cc]op.* 119 | ~$* 120 | *~ 121 | *.dbmdl 122 | *.[Pp]ublish.xml 123 | *.pfx 124 | *.publishsettings 125 | 126 | # RIA/Silverlight projects 127 | Generated_Code/ 128 | 129 | # Backup & report files from converting an old project file to a newer 130 | # Visual Studio version. Backup files are not needed, because we have git ;-) 131 | _UpgradeReport_Files/ 132 | Backup*/ 133 | UpgradeLog*.XML 134 | UpgradeLog*.htm 135 | 136 | # SQL Server files 137 | App_Data/*.mdf 138 | App_Data/*.ldf 139 | 140 | 141 | #LightSwitch generated files 142 | GeneratedArtifacts/ 143 | _Pvt_Extensions/ 144 | ModelManifest.xml 145 | 146 | # ========================= 147 | # Windows detritus 148 | # ========================= 149 | 150 | # Windows image file caches 151 | Thumbs.db 152 | ehthumbs.db 153 | 154 | # Folder config file 155 | Desktop.ini 156 | 157 | # Recycle Bin used on file shares 158 | $RECYCLE.BIN/ 159 | 160 | # Mac desktop service store files 161 | .DS_Store 162 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | install: composer install 3 | php: 4 | - "5.4" 5 | - "5.5" 6 | - "5.6" 7 | - "7.0" 8 | - nightly 9 | script: 10 | - phpunit -c phpunit.xml Tests/ -------------------------------------------------------------------------------- /Application.Insights.phpproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | Application.Insights 6 | 6c54eac1-21b0-4dbe-a7c8-59e4a4f81316 7 | Console 8 | Application.Insights 9 | {A0786B88-2ADB-4C21-ABE8-AA2D79766269} 10 | 11 | 12 | Application.Insights 13 | 14 | 15 | true 16 | 17 | 18 | false 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /Application.Insights.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{A0786B88-2ADB-4C21-ABE8-AA2D79766269}") = "Application.Insights", "Application.Insights.phpproj", "{6C54EAC1-21B0-4DBE-A7C8-59E4A4F81316}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6C54EAC1-21B0-4DBE-A7C8-59E4A4F81316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {6C54EAC1-21B0-4DBE-A7C8-59E4A4F81316}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {6C54EAC1-21B0-4DBE-A7C8-59E4A4F81316}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {6C54EAC1-21B0-4DBE-A7C8-59E4A4F81316}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Application.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Application. 14 | */ 15 | class Application 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Application. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the ver field. Application version. Information in the application context fields is always about the application that is sending the telemetry. 34 | */ 35 | public function getVer() 36 | { 37 | if (array_key_exists('ai.application.ver', $this->_data)) { return $this->_data['ai.application.ver']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the ver field. Application version. Information in the application context fields is always about the application that is sending the telemetry. 43 | */ 44 | public function setVer($ver) 45 | { 46 | $this->_data['ai.application.ver'] = $ver; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Availability_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Availability_Data. Instances of AvailabilityData represent the result of executing an availability test. 14 | */ 15 | class Availability_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new AvailabilityData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.Availability'; 24 | $this->_dataTypeName = 'AvailabilityData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['id'] = NULL; 27 | $this->_data['name'] = NULL; 28 | $this->_data['duration'] = NULL; 29 | $this->_data['success'] = NULL; 30 | } 31 | 32 | /** 33 | * Gets the ver field. Schema version 34 | */ 35 | public function getVer() 36 | { 37 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the ver field. Schema version 43 | */ 44 | public function setVer($ver) 45 | { 46 | $this->_data['ver'] = $ver; 47 | } 48 | 49 | /** 50 | * Gets the id field. Identifier of a test run. Use it to correlate steps of test run and telemetry generated by the service. 51 | */ 52 | public function getId() 53 | { 54 | if (array_key_exists('id', $this->_data)) { return $this->_data['id']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the id field. Identifier of a test run. Use it to correlate steps of test run and telemetry generated by the service. 60 | */ 61 | public function setId($id) 62 | { 63 | $this->_data['id'] = $id; 64 | } 65 | 66 | /** 67 | * Gets the name field. Name of the test that these availability results represent. 68 | */ 69 | public function getName() 70 | { 71 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 72 | return NULL; 73 | } 74 | 75 | /** 76 | * Sets the name field. Name of the test that these availability results represent. 77 | */ 78 | public function setName($name) 79 | { 80 | $this->_data['name'] = $name; 81 | } 82 | 83 | /** 84 | * Gets the duration field. Duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days. 85 | */ 86 | public function getDuration() 87 | { 88 | if (array_key_exists('duration', $this->_data)) { return $this->_data['duration']; } 89 | return NULL; 90 | } 91 | 92 | /** 93 | * Sets the duration field. Duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days. 94 | */ 95 | public function setDuration($duration) 96 | { 97 | $this->_data['duration'] = $duration; 98 | } 99 | 100 | /** 101 | * Gets the success field. Success flag. 102 | */ 103 | public function getSuccess() 104 | { 105 | if (array_key_exists('success', $this->_data)) { return $this->_data['success']; } 106 | return NULL; 107 | } 108 | 109 | /** 110 | * Sets the success field. Success flag. 111 | */ 112 | public function setSuccess($success) 113 | { 114 | $this->_data['success'] = $success; 115 | } 116 | 117 | /** 118 | * Gets the runLocation field. Name of the location where the test was run from. 119 | */ 120 | public function getRunLocation() 121 | { 122 | if (array_key_exists('runLocation', $this->_data)) { return $this->_data['runLocation']; } 123 | return NULL; 124 | } 125 | 126 | /** 127 | * Sets the runLocation field. Name of the location where the test was run from. 128 | */ 129 | public function setRunLocation($runLocation) 130 | { 131 | $this->_data['runLocation'] = $runLocation; 132 | } 133 | 134 | /** 135 | * Gets the message field. Diagnostic message for the result. 136 | */ 137 | public function getMessage() 138 | { 139 | if (array_key_exists('message', $this->_data)) { return $this->_data['message']; } 140 | return NULL; 141 | } 142 | 143 | /** 144 | * Sets the message field. Diagnostic message for the result. 145 | */ 146 | public function setMessage($message) 147 | { 148 | $this->_data['message'] = $message; 149 | } 150 | 151 | /** 152 | * Gets the properties field. Collection of custom properties. 153 | */ 154 | public function getProperties() 155 | { 156 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 157 | return NULL; 158 | } 159 | 160 | /** 161 | * Sets the properties field. Collection of custom properties. 162 | */ 163 | public function setProperties($properties) 164 | { 165 | $this->_data['properties'] = $properties; 166 | } 167 | 168 | /** 169 | * Gets the measurements field. Collection of custom measurements. 170 | */ 171 | public function getMeasurements() 172 | { 173 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 174 | return NULL; 175 | } 176 | 177 | /** 178 | * Sets the measurements field. Collection of custom measurements. 179 | */ 180 | public function setMeasurements($measurements) 181 | { 182 | $this->_data['measurements'] = $measurements; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Base_Data.php: -------------------------------------------------------------------------------- 1 | _envelopeTypeName; 38 | } 39 | 40 | /** 41 | * Gets the dataTypeName field. 42 | */ 43 | public function getDataTypeName() 44 | { 45 | return $this->_dataTypeName; 46 | } 47 | 48 | /** 49 | * Gets the time of the event. 50 | */ 51 | public function getTime() 52 | { 53 | return $this->_time; 54 | } 55 | 56 | /** 57 | * Sets the time of the event. 58 | */ 59 | public function setTime($time) 60 | { 61 | $this->_time = $time; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Cloud.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Cloud. 14 | */ 15 | class Cloud 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Cloud. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the role field. Name of the role the application is a part of. Maps directly to the role name in azure. 34 | */ 35 | public function getRole() 36 | { 37 | if (array_key_exists('ai.cloud.role', $this->_data)) { return $this->_data['ai.cloud.role']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the role field. Name of the role the application is a part of. Maps directly to the role name in azure. 43 | */ 44 | public function setRole($role) 45 | { 46 | $this->_data['ai.cloud.role'] = $role; 47 | } 48 | 49 | /** 50 | * Gets the roleInstance field. Name of the instance where the application is running. Computer name for on-premisis, instance name for Azure. 51 | */ 52 | public function getRoleInstance() 53 | { 54 | if (array_key_exists('ai.cloud.roleInstance', $this->_data)) { return $this->_data['ai.cloud.roleInstance']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the roleInstance field. Name of the instance where the application is running. Computer name for on-premisis, instance name for Azure. 60 | */ 61 | public function setRoleInstance($roleInstance) 62 | { 63 | $this->_data['ai.cloud.roleInstance'] = $roleInstance; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Data. Data struct to contain both B and C sections. 14 | */ 15 | class Data 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Data. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data['baseData'] = NULL; 30 | } 31 | 32 | /** 33 | * Gets the baseType field. Name of item (B section) if any. If telemetry data is derived straight from this, this should be null. 34 | */ 35 | public function getBaseType() 36 | { 37 | if (array_key_exists('baseType', $this->_data)) { return $this->_data['baseType']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the baseType field. Name of item (B section) if any. If telemetry data is derived straight from this, this should be null. 43 | */ 44 | public function setBaseType($baseType) 45 | { 46 | $this->_data['baseType'] = $baseType; 47 | } 48 | 49 | /** 50 | * Gets the baseData field. Container for data item (B section). 51 | */ 52 | public function getBaseData() 53 | { 54 | if (array_key_exists('baseData', $this->_data)) { return $this->_data['baseData']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the baseData field. Container for data item (B section). 60 | */ 61 | public function setBaseData($baseData) 62 | { 63 | $this->_data['baseData'] = $baseData; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Data_Interface.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Data_Point. Metric data single measurement. 14 | */ 15 | class Data_Point 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new DataPoint. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data['name'] = NULL; 30 | $this->_data['kind'] = Data_Point_Type::Measurement; 31 | $this->_data['value'] = NULL; 32 | } 33 | 34 | /** 35 | * Gets the ns field. Namespace of the metric. 36 | */ 37 | public function getNs() 38 | { 39 | if (array_key_exists('ns', $this->_data)) { return $this->_data['ns']; } 40 | return NULL; 41 | } 42 | 43 | /** 44 | * Sets the ns field. Namespace of the metric. 45 | */ 46 | public function setNs($ns) 47 | { 48 | $this->_data['ns'] = $ns; 49 | } 50 | 51 | /** 52 | * Gets the name field. Name of the metric. 53 | */ 54 | public function getName() 55 | { 56 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 57 | return NULL; 58 | } 59 | 60 | /** 61 | * Sets the name field. Name of the metric. 62 | */ 63 | public function setName($name) 64 | { 65 | $this->_data['name'] = $name; 66 | } 67 | 68 | /** 69 | * Gets the kind field. Metric type. Single measurement or the aggregated value. 70 | */ 71 | public function getKind() 72 | { 73 | if (array_key_exists('kind', $this->_data)) { return $this->_data['kind']; } 74 | return NULL; 75 | } 76 | 77 | /** 78 | * Sets the kind field. Metric type. Single measurement or the aggregated value. 79 | */ 80 | public function setKind($kind) 81 | { 82 | $this->_data['kind'] = $kind; 83 | } 84 | 85 | /** 86 | * Gets the value field. Single value for measurement. Sum of individual measurements for the aggregation. 87 | */ 88 | public function getValue() 89 | { 90 | if (array_key_exists('value', $this->_data)) { return $this->_data['value']; } 91 | return NULL; 92 | } 93 | 94 | /** 95 | * Sets the value field. Single value for measurement. Sum of individual measurements for the aggregation. 96 | */ 97 | public function setValue($value) 98 | { 99 | $this->_data['value'] = $value; 100 | } 101 | 102 | /** 103 | * Gets the count field. Metric weight of the aggregated metric. Should not be set for a measurement. 104 | */ 105 | public function getCount() 106 | { 107 | if (array_key_exists('count', $this->_data)) { return $this->_data['count']; } 108 | return NULL; 109 | } 110 | 111 | /** 112 | * Sets the count field. Metric weight of the aggregated metric. Should not be set for a measurement. 113 | */ 114 | public function setCount($count) 115 | { 116 | $this->_data['count'] = $count; 117 | } 118 | 119 | /** 120 | * Gets the min field. Minimum value of the aggregated metric. Should not be set for a measurement. 121 | */ 122 | public function getMin() 123 | { 124 | if (array_key_exists('min', $this->_data)) { return $this->_data['min']; } 125 | return NULL; 126 | } 127 | 128 | /** 129 | * Sets the min field. Minimum value of the aggregated metric. Should not be set for a measurement. 130 | */ 131 | public function setMin($min) 132 | { 133 | $this->_data['min'] = $min; 134 | } 135 | 136 | /** 137 | * Gets the max field. Maximum value of the aggregated metric. Should not be set for a measurement. 138 | */ 139 | public function getMax() 140 | { 141 | if (array_key_exists('max', $this->_data)) { return $this->_data['max']; } 142 | return NULL; 143 | } 144 | 145 | /** 146 | * Sets the max field. Maximum value of the aggregated metric. Should not be set for a measurement. 147 | */ 148 | public function setMax($max) 149 | { 150 | $this->_data['max'] = $max; 151 | } 152 | 153 | /** 154 | * Gets the stdDev field. Standard deviation of the aggregated metric. Should not be set for a measurement. 155 | */ 156 | public function getStdDev() 157 | { 158 | if (array_key_exists('stdDev', $this->_data)) { return $this->_data['stdDev']; } 159 | return NULL; 160 | } 161 | 162 | /** 163 | * Sets the stdDev field. Standard deviation of the aggregated metric. Should not be set for a measurement. 164 | */ 165 | public function setStdDev($stdDev) 166 | { 167 | $this->_data['stdDev'] = $stdDev; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Data_Point_Type.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | /** 12 | * Enum Data_Point_Type. 13 | */ 14 | abstract class Data_Point_Type 15 | { 16 | const Measurement = 0; 17 | const Aggregation = 1; 18 | } 19 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Dependency_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Dependency_Data. An instance of Remote Dependency represents an interaction of the monitored component with a remote component/service like SQL or an HTTP endpoint. 14 | */ 15 | class Dependency_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new RemoteDependencyData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.RemoteDependency'; 24 | $this->_dataTypeName = 'RemoteDependencyData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['name'] = NULL; 27 | $this->_data['duration'] = NULL; 28 | $this->_data['success'] = true; 29 | } 30 | 31 | /** 32 | * Gets the ver field. Schema version 33 | */ 34 | public function getVer() 35 | { 36 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 37 | return NULL; 38 | } 39 | 40 | /** 41 | * Sets the ver field. Schema version 42 | */ 43 | public function setVer($ver) 44 | { 45 | $this->_data['ver'] = $ver; 46 | } 47 | 48 | /** 49 | * Gets the name field. Name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template. 50 | */ 51 | public function getName() 52 | { 53 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 54 | return NULL; 55 | } 56 | 57 | /** 58 | * Sets the name field. Name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template. 59 | */ 60 | public function setName($name) 61 | { 62 | $this->_data['name'] = $name; 63 | } 64 | 65 | /** 66 | * Gets the id field. Identifier of a dependency call instance. Used for correlation with the request telemetry item corresponding to this dependency call. 67 | */ 68 | public function getId() 69 | { 70 | if (array_key_exists('id', $this->_data)) { return $this->_data['id']; } 71 | return NULL; 72 | } 73 | 74 | /** 75 | * Sets the id field. Identifier of a dependency call instance. Used for correlation with the request telemetry item corresponding to this dependency call. 76 | */ 77 | public function setId($id) 78 | { 79 | $this->_data['id'] = $id; 80 | } 81 | 82 | /** 83 | * Gets the resultCode field. Result code of a dependency call. Examples are SQL error code and HTTP status code. 84 | */ 85 | public function getResultCode() 86 | { 87 | if (array_key_exists('resultCode', $this->_data)) { return $this->_data['resultCode']; } 88 | return NULL; 89 | } 90 | 91 | /** 92 | * Sets the resultCode field. Result code of a dependency call. Examples are SQL error code and HTTP status code. 93 | */ 94 | public function setResultCode($resultCode) 95 | { 96 | $this->_data['resultCode'] = var_export($resultCode, TRUE); 97 | } 98 | 99 | /** 100 | * Gets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days. 101 | */ 102 | public function getDuration() 103 | { 104 | if (array_key_exists('duration', $this->_data)) { return $this->_data['duration']; } 105 | return NULL; 106 | } 107 | 108 | /** 109 | * Sets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days. 110 | */ 111 | public function setDuration($duration) 112 | { 113 | $this->_data['duration'] = $duration; 114 | } 115 | 116 | /** 117 | * Gets the success field. Indication of successfull or unsuccessfull call. 118 | */ 119 | public function getSuccess() 120 | { 121 | if (array_key_exists('success', $this->_data)) { return $this->_data['success']; } 122 | return NULL; 123 | } 124 | 125 | /** 126 | * Sets the success field. Indication of successfull or unsuccessfull call. 127 | */ 128 | public function setSuccess($success) 129 | { 130 | $this->_data['success'] = $success; 131 | } 132 | 133 | /** 134 | * Gets the data field. Command initiated by this dependency call. Examples are SQL statement and HTTP URL's with all query parameters. 135 | */ 136 | public function getData() 137 | { 138 | if (array_key_exists('data', $this->_data)) { return $this->_data['data']; } 139 | return NULL; 140 | } 141 | 142 | /** 143 | * Sets the data field. Command initiated by this dependency call. Examples are SQL statement and HTTP URL's with all query parameters. 144 | */ 145 | public function setData($data) 146 | { 147 | $this->_data['data'] = $data; 148 | } 149 | 150 | /** 151 | * Gets the target field. Target site of a dependency call. Examples are server name, host address. 152 | */ 153 | public function getTarget() 154 | { 155 | if (array_key_exists('target', $this->_data)) { return $this->_data['target']; } 156 | return NULL; 157 | } 158 | 159 | /** 160 | * Sets the target field. Target site of a dependency call. Examples are server name, host address. 161 | */ 162 | public function setTarget($target) 163 | { 164 | $this->_data['target'] = $target; 165 | } 166 | 167 | /** 168 | * Gets the type field. Dependency type name. Very low cardinality value for logical grouping of dependencies and interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP. 169 | */ 170 | public function getType() 171 | { 172 | if (array_key_exists('type', $this->_data)) { return $this->_data['type']; } 173 | return NULL; 174 | } 175 | 176 | /** 177 | * Sets the type field. Dependency type name. Very low cardinality value for logical grouping of dependencies and interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP. 178 | */ 179 | public function setType($type) 180 | { 181 | $this->_data['type'] = $type; 182 | } 183 | 184 | /** 185 | * Gets the properties field. Collection of custom properties. 186 | */ 187 | public function getProperties() 188 | { 189 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 190 | return NULL; 191 | } 192 | 193 | /** 194 | * Sets the properties field. Collection of custom properties. 195 | */ 196 | public function setProperties($properties) 197 | { 198 | $this->_data['properties'] = $properties; 199 | } 200 | 201 | /** 202 | * Gets the measurements field. Collection of custom measurements. 203 | */ 204 | public function getMeasurements() 205 | { 206 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 207 | return NULL; 208 | } 209 | 210 | /** 211 | * Sets the measurements field. Collection of custom measurements. 212 | */ 213 | public function setMeasurements($measurements) 214 | { 215 | $this->_data['measurements'] = $measurements; 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Device.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Device. 14 | */ 15 | class Device 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Device. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the id field. Unique client device id. Computer name in most cases. 34 | */ 35 | public function getId() 36 | { 37 | if (array_key_exists('ai.device.id', $this->_data)) { return $this->_data['ai.device.id']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the id field. Unique client device id. Computer name in most cases. 43 | */ 44 | public function setId($id) 45 | { 46 | $this->_data['ai.device.id'] = $id; 47 | } 48 | 49 | /** 50 | * Gets the locale field. Device locale using - pattern, following RFC 5646. Example 'en-US'. 51 | */ 52 | public function getLocale() 53 | { 54 | if (array_key_exists('ai.device.locale', $this->_data)) { return $this->_data['ai.device.locale']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the locale field. Device locale using - pattern, following RFC 5646. Example 'en-US'. 60 | */ 61 | public function setLocale($locale) 62 | { 63 | $this->_data['ai.device.locale'] = $locale; 64 | } 65 | 66 | /** 67 | * Gets the model field. Model of the device the end user of the application is using. Used for client scenarios. If this field is empty then it is derived from the user agent. 68 | */ 69 | public function getModel() 70 | { 71 | if (array_key_exists('ai.device.model', $this->_data)) { return $this->_data['ai.device.model']; } 72 | return NULL; 73 | } 74 | 75 | /** 76 | * Sets the model field. Model of the device the end user of the application is using. Used for client scenarios. If this field is empty then it is derived from the user agent. 77 | */ 78 | public function setModel($model) 79 | { 80 | $this->_data['ai.device.model'] = $model; 81 | } 82 | 83 | /** 84 | * Gets the oemName field. Client device OEM name taken from the browser. 85 | */ 86 | public function getOemName() 87 | { 88 | if (array_key_exists('ai.device.oemName', $this->_data)) { return $this->_data['ai.device.oemName']; } 89 | return NULL; 90 | } 91 | 92 | /** 93 | * Sets the oemName field. Client device OEM name taken from the browser. 94 | */ 95 | public function setOemName($oemName) 96 | { 97 | $this->_data['ai.device.oemName'] = $oemName; 98 | } 99 | 100 | /** 101 | * Gets the osVersion field. Operating system name and version of the device the end user of the application is using. If this field is empty then it is derived from the user agent. Example 'Windows 10 Pro 10.0.10586.0' 102 | */ 103 | public function getOsVersion() 104 | { 105 | if (array_key_exists('ai.device.osVersion', $this->_data)) { return $this->_data['ai.device.osVersion']; } 106 | return NULL; 107 | } 108 | 109 | /** 110 | * Sets the osVersion field. Operating system name and version of the device the end user of the application is using. If this field is empty then it is derived from the user agent. Example 'Windows 10 Pro 10.0.10586.0' 111 | */ 112 | public function setOsVersion($osVersion) 113 | { 114 | $this->_data['ai.device.osVersion'] = $osVersion; 115 | } 116 | 117 | /** 118 | * Gets the type field. The type of the device the end user of the application is using. Used primarily to distinguish JavaScript telemetry from server side telemetry. Examples: 'PC', 'Phone', 'Browser'. 'PC' is the default value. 119 | */ 120 | public function getType() 121 | { 122 | if (array_key_exists('ai.device.type', $this->_data)) { return $this->_data['ai.device.type']; } 123 | return NULL; 124 | } 125 | 126 | /** 127 | * Sets the type field. The type of the device the end user of the application is using. Used primarily to distinguish JavaScript telemetry from server side telemetry. Examples: 'PC', 'Phone', 'Browser'. 'PC' is the default value. 128 | */ 129 | public function setType($type) 130 | { 131 | $this->_data['ai.device.type'] = $type; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Envelope.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Envelope. System variables for a telemetry item. 14 | */ 15 | class Envelope 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Envelope. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data['ver'] = 1; 30 | $this->_data['name'] = NULL; 31 | $this->_data['time'] = NULL; 32 | $this->_data['sampleRate'] = 100.0; 33 | } 34 | 35 | /** 36 | * Gets the ver field. Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1. 37 | */ 38 | public function getVer() 39 | { 40 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 41 | return NULL; 42 | } 43 | 44 | /** 45 | * Sets the ver field. Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1. 46 | */ 47 | public function setVer($ver) 48 | { 49 | $this->_data['ver'] = $ver; 50 | } 51 | 52 | /** 53 | * Gets the name field. Type name of telemetry data item. 54 | */ 55 | public function getName() 56 | { 57 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 58 | return NULL; 59 | } 60 | 61 | /** 62 | * Sets the name field. Type name of telemetry data item. 63 | */ 64 | public function setName($name) 65 | { 66 | $this->_data['name'] = $name; 67 | } 68 | 69 | /** 70 | * Gets the time field. Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z. 71 | */ 72 | public function getTime() 73 | { 74 | if (array_key_exists('time', $this->_data)) { return $this->_data['time']; } 75 | return NULL; 76 | } 77 | 78 | /** 79 | * Sets the time field. Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z. 80 | */ 81 | public function setTime($time) 82 | { 83 | $this->_data['time'] = $time; 84 | } 85 | 86 | /** 87 | * Gets the sampleRate field. Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items. 88 | */ 89 | public function getSampleRate() 90 | { 91 | if (array_key_exists('sampleRate', $this->_data)) { return $this->_data['sampleRate']; } 92 | return NULL; 93 | } 94 | 95 | /** 96 | * Sets the sampleRate field. Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items. 97 | */ 98 | public function setSampleRate($sampleRate) 99 | { 100 | $this->_data['sampleRate'] = $sampleRate; 101 | } 102 | 103 | /** 104 | * Gets the seq field. Sequence field used to track absolute order of uploaded events. 105 | */ 106 | public function getSeq() 107 | { 108 | if (array_key_exists('seq', $this->_data)) { return $this->_data['seq']; } 109 | return NULL; 110 | } 111 | 112 | /** 113 | * Sets the seq field. Sequence field used to track absolute order of uploaded events. 114 | */ 115 | public function setSeq($seq) 116 | { 117 | $this->_data['seq'] = $seq; 118 | } 119 | 120 | /** 121 | * Gets the iKey field. The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive. 122 | */ 123 | public function getInstrumentationKey() 124 | { 125 | if (array_key_exists('iKey', $this->_data)) { return $this->_data['iKey']; } 126 | return NULL; 127 | } 128 | 129 | /** 130 | * Sets the iKey field. The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive. 131 | */ 132 | public function setInstrumentationKey($iKey) 133 | { 134 | $this->_data['iKey'] = $iKey; 135 | } 136 | 137 | /** 138 | * Gets the tags field. Key/value collection of context properties. See ContextTagKeys for information on available properties. 139 | */ 140 | public function getTags() 141 | { 142 | if (array_key_exists('tags', $this->_data)) { return $this->_data['tags']; } 143 | return NULL; 144 | } 145 | 146 | /** 147 | * Sets the tags field. Key/value collection of context properties. See ContextTagKeys for information on available properties. 148 | */ 149 | public function setTags($tags) 150 | { 151 | $this->_data['tags'] = $tags; 152 | } 153 | 154 | /** 155 | * Gets the data field. Telemetry data item. 156 | */ 157 | public function getData() 158 | { 159 | if (array_key_exists('data', $this->_data)) { return $this->_data['data']; } 160 | return NULL; 161 | } 162 | 163 | /** 164 | * Sets the data field. Telemetry data item. 165 | */ 166 | public function setData($data) 167 | { 168 | $this->_data['data'] = $data; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Event_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Event_Data. Instances of Event represent structured event records that can be grouped and searched by their properties. Event data item also creates a metric of event count by name. 14 | */ 15 | class Event_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new EventData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.Event'; 24 | $this->_dataTypeName = 'EventData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['name'] = NULL; 27 | } 28 | 29 | /** 30 | * Gets the ver field. Schema version 31 | */ 32 | public function getVer() 33 | { 34 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 35 | return NULL; 36 | } 37 | 38 | /** 39 | * Sets the ver field. Schema version 40 | */ 41 | public function setVer($ver) 42 | { 43 | $this->_data['ver'] = $ver; 44 | } 45 | 46 | /** 47 | * Gets the name field. Event name. Keep it low cardinality to allow proper grouping and useful metrics. 48 | */ 49 | public function getName() 50 | { 51 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 52 | return NULL; 53 | } 54 | 55 | /** 56 | * Sets the name field. Event name. Keep it low cardinality to allow proper grouping and useful metrics. 57 | */ 58 | public function setName($name) 59 | { 60 | $this->_data['name'] = $name; 61 | } 62 | 63 | /** 64 | * Gets the properties field. Collection of custom properties. 65 | */ 66 | public function getProperties() 67 | { 68 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 69 | return NULL; 70 | } 71 | 72 | /** 73 | * Sets the properties field. Collection of custom properties. 74 | */ 75 | public function setProperties($properties) 76 | { 77 | $this->_data['properties'] = $properties; 78 | } 79 | 80 | /** 81 | * Gets the measurements field. Collection of custom measurements. 82 | */ 83 | public function getMeasurements() 84 | { 85 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 86 | return NULL; 87 | } 88 | 89 | /** 90 | * Sets the measurements field. Collection of custom measurements. 91 | */ 92 | public function setMeasurements($measurements) 93 | { 94 | $this->_data['measurements'] = $measurements; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Exception_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Exception_Data. An instance of Exception represents a handled or unhandled exception that occurred during execution of the monitored application. 14 | */ 15 | class Exception_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new ExceptionData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.Exception'; 24 | $this->_dataTypeName = 'ExceptionData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['exceptions'] = []; 27 | } 28 | 29 | /** 30 | * Gets the ver field. Schema version 31 | */ 32 | public function getVer() 33 | { 34 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 35 | return NULL; 36 | } 37 | 38 | /** 39 | * Sets the ver field. Schema version 40 | */ 41 | public function setVer($ver) 42 | { 43 | $this->_data['ver'] = $ver; 44 | } 45 | 46 | /** 47 | * Gets the exceptions field. Exception chain - list of inner exceptions. 48 | */ 49 | public function getExceptions() 50 | { 51 | if (array_key_exists('exceptions', $this->_data)) { return $this->_data['exceptions']; } 52 | return NULL; 53 | } 54 | 55 | /** 56 | * Sets the exceptions field. Exception chain - list of inner exceptions. 57 | */ 58 | public function setExceptions($exceptions) 59 | { 60 | $this->_data['exceptions'] = $exceptions; 61 | } 62 | 63 | /** 64 | * Gets the severityLevel field. Severity level. Mostly used to indicate exception severity level when it is reported by logging library. 65 | */ 66 | public function getSeverityLevel() 67 | { 68 | if (array_key_exists('severityLevel', $this->_data)) { return $this->_data['severityLevel']; } 69 | return NULL; 70 | } 71 | 72 | /** 73 | * Sets the severityLevel field. Severity level. Mostly used to indicate exception severity level when it is reported by logging library. 74 | */ 75 | public function setSeverityLevel($severityLevel) 76 | { 77 | $this->_data['severityLevel'] = $severityLevel; 78 | } 79 | 80 | /** 81 | * Gets the problemId field. Identifier of where the exception was thrown in code. Used for exceptions grouping. Typically a combination of exception type and a function from the call stack. 82 | */ 83 | public function getProblemId() 84 | { 85 | if (array_key_exists('problemId', $this->_data)) { return $this->_data['problemId']; } 86 | return NULL; 87 | } 88 | 89 | /** 90 | * Sets the problemId field. Identifier of where the exception was thrown in code. Used for exceptions grouping. Typically a combination of exception type and a function from the call stack. 91 | */ 92 | public function setProblemId($problemId) 93 | { 94 | $this->_data['problemId'] = $problemId; 95 | } 96 | 97 | /** 98 | * Gets the properties field. Collection of custom properties. 99 | */ 100 | public function getProperties() 101 | { 102 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 103 | return NULL; 104 | } 105 | 106 | /** 107 | * Sets the properties field. Collection of custom properties. 108 | */ 109 | public function setProperties($properties) 110 | { 111 | $this->_data['properties'] = $properties; 112 | } 113 | 114 | /** 115 | * Gets the measurements field. Collection of custom measurements. 116 | */ 117 | public function getMeasurements() 118 | { 119 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 120 | return NULL; 121 | } 122 | 123 | /** 124 | * Sets the measurements field. Collection of custom measurements. 125 | */ 126 | public function setMeasurements($measurements) 127 | { 128 | $this->_data['measurements'] = $measurements; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Exception_Details.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Exception_Details. Exception details of the exception in a chain. 14 | */ 15 | class Exception_Details 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new ExceptionDetails. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data['typeName'] = NULL; 30 | $this->_data['message'] = NULL; 31 | $this->_data['hasFullStack'] = true; 32 | } 33 | 34 | /** 35 | * Gets the id field. In case exception is nested (outer exception contains inner one), the id and outerId properties are used to represent the nesting. 36 | */ 37 | public function getId() 38 | { 39 | if (array_key_exists('id', $this->_data)) { return $this->_data['id']; } 40 | return NULL; 41 | } 42 | 43 | /** 44 | * Sets the id field. In case exception is nested (outer exception contains inner one), the id and outerId properties are used to represent the nesting. 45 | */ 46 | public function setId($id) 47 | { 48 | $this->_data['id'] = $id; 49 | } 50 | 51 | /** 52 | * Gets the outerId field. The value of outerId is a reference to an element in ExceptionDetails that represents the outer exception 53 | */ 54 | public function getOuterId() 55 | { 56 | if (array_key_exists('outerId', $this->_data)) { return $this->_data['outerId']; } 57 | return NULL; 58 | } 59 | 60 | /** 61 | * Sets the outerId field. The value of outerId is a reference to an element in ExceptionDetails that represents the outer exception 62 | */ 63 | public function setOuterId($outerId) 64 | { 65 | $this->_data['outerId'] = $outerId; 66 | } 67 | 68 | /** 69 | * Gets the typeName field. Exception type name. 70 | */ 71 | public function getTypeName() 72 | { 73 | if (array_key_exists('typeName', $this->_data)) { return $this->_data['typeName']; } 74 | return NULL; 75 | } 76 | 77 | /** 78 | * Sets the typeName field. Exception type name. 79 | */ 80 | public function setTypeName($typeName) 81 | { 82 | $this->_data['typeName'] = $typeName; 83 | } 84 | 85 | /** 86 | * Gets the message field. Exception message. 87 | */ 88 | public function getMessage() 89 | { 90 | if (array_key_exists('message', $this->_data)) { return $this->_data['message']; } 91 | return NULL; 92 | } 93 | 94 | /** 95 | * Sets the message field. Exception message. 96 | */ 97 | public function setMessage($message) 98 | { 99 | $this->_data['message'] = $message; 100 | } 101 | 102 | /** 103 | * Gets the hasFullStack field. Indicates if full exception stack is provided in the exception. The stack may be trimmed, such as in the case of a StackOverflow exception. 104 | */ 105 | public function getHasFullStack() 106 | { 107 | if (array_key_exists('hasFullStack', $this->_data)) { return $this->_data['hasFullStack']; } 108 | return NULL; 109 | } 110 | 111 | /** 112 | * Sets the hasFullStack field. Indicates if full exception stack is provided in the exception. The stack may be trimmed, such as in the case of a StackOverflow exception. 113 | */ 114 | public function setHasFullStack($hasFullStack) 115 | { 116 | $this->_data['hasFullStack'] = $hasFullStack; 117 | } 118 | 119 | /** 120 | * Gets the stack field. Text describing the stack. Either stack or parsedStack should have a value. 121 | */ 122 | public function getStack() 123 | { 124 | if (array_key_exists('stack', $this->_data)) { return $this->_data['stack']; } 125 | return NULL; 126 | } 127 | 128 | /** 129 | * Sets the stack field. Text describing the stack. Either stack or parsedStack should have a value. 130 | */ 131 | public function setStack($stack) 132 | { 133 | $this->_data['stack'] = $stack; 134 | } 135 | 136 | /** 137 | * Gets the parsedStack field. List of stack frames. Either stack or parsedStack should have a value. 138 | */ 139 | public function getParsedStack() 140 | { 141 | if (array_key_exists('parsedStack', $this->_data)) { return $this->_data['parsedStack']; } 142 | return NULL; 143 | } 144 | 145 | /** 146 | * Sets the parsedStack field. List of stack frames. Either stack or parsedStack should have a value. 147 | */ 148 | public function setParsedStack($parsedStack) 149 | { 150 | $this->_data['parsedStack'] = $parsedStack; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Internal.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Internal. 14 | */ 15 | class Internal 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Internal. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the sdkVersion field. SDK version. See https://github.com/Microsoft/ApplicationInsights-Home/blob/master/SDK-AUTHORING.md#sdk-version-specification for information. 34 | */ 35 | public function getSdkVersion() 36 | { 37 | if (array_key_exists('ai.internal.sdkVersion', $this->_data)) { return $this->_data['ai.internal.sdkVersion']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the sdkVersion field. SDK version. See https://github.com/Microsoft/ApplicationInsights-Home/blob/master/SDK-AUTHORING.md#sdk-version-specification for information. 43 | */ 44 | public function setSdkVersion($sdkVersion) 45 | { 46 | $this->_data['ai.internal.sdkVersion'] = $sdkVersion; 47 | } 48 | 49 | /** 50 | * Gets the agentVersion field. Agent version. Used to indicate the version of StatusMonitor installed on the computer if it is used for data collection. 51 | */ 52 | public function getAgentVersion() 53 | { 54 | if (array_key_exists('ai.internal.agentVersion', $this->_data)) { return $this->_data['ai.internal.agentVersion']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the agentVersion field. Agent version. Used to indicate the version of StatusMonitor installed on the computer if it is used for data collection. 60 | */ 61 | public function setAgentVersion($agentVersion) 62 | { 63 | $this->_data['ai.internal.agentVersion'] = $agentVersion; 64 | } 65 | 66 | /** 67 | * Gets the nodeName field. This is the node name used for billing purposes. Use it to override the standard detection of nodes. 68 | */ 69 | public function getNodeName() 70 | { 71 | if (array_key_exists('ai.internal.nodeName', $this->_data)) { return $this->_data['ai.internal.nodeName']; } 72 | return NULL; 73 | } 74 | 75 | /** 76 | * Sets the nodeName field. This is the node name used for billing purposes. Use it to override the standard detection of nodes. 77 | */ 78 | public function setNodeName($nodeName) 79 | { 80 | $this->_data['ai.internal.nodeName'] = $nodeName; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Json_Serializer.php: -------------------------------------------------------------------------------- 1 | _data); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Location.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Location. 14 | */ 15 | class Location 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Location. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the ip field. The IP address of the client device. IPv4 and IPv6 are supported. Information in the location context fields is always about the end user. When telemetry is sent from a service, the location context is about the user that initiated the operation in the service. 34 | */ 35 | public function getIp() 36 | { 37 | if (array_key_exists('ai.location.ip', $this->_data)) { return $this->_data['ai.location.ip']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the ip field. The IP address of the client device. IPv4 and IPv6 are supported. Information in the location context fields is always about the end user. When telemetry is sent from a service, the location context is about the user that initiated the operation in the service. 43 | */ 44 | public function setIp($ip) 45 | { 46 | $this->_data['ai.location.ip'] = $ip; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Message_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Message_Data. Instances of Message represent printf-like trace statements that are text-searched. Log4Net, NLog and other text-based log file entries are translated into intances of this type. The message does not have measurements. 14 | */ 15 | class Message_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new MessageData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.Message'; 24 | $this->_dataTypeName = 'MessageData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['message'] = NULL; 27 | } 28 | 29 | /** 30 | * Gets the ver field. Schema version 31 | */ 32 | public function getVer() 33 | { 34 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 35 | return NULL; 36 | } 37 | 38 | /** 39 | * Sets the ver field. Schema version 40 | */ 41 | public function setVer($ver) 42 | { 43 | $this->_data['ver'] = $ver; 44 | } 45 | 46 | /** 47 | * Gets the message field. Trace message 48 | */ 49 | public function getMessage() 50 | { 51 | if (array_key_exists('message', $this->_data)) { return $this->_data['message']; } 52 | return NULL; 53 | } 54 | 55 | /** 56 | * Sets the message field. Trace message 57 | */ 58 | public function setMessage($message) 59 | { 60 | $this->_data['message'] = $message; 61 | } 62 | 63 | /** 64 | * Gets the severityLevel field. Trace severity level. 65 | */ 66 | public function getSeverityLevel() 67 | { 68 | if (array_key_exists('severityLevel', $this->_data)) { return $this->_data['severityLevel']; } 69 | return NULL; 70 | } 71 | 72 | /** 73 | * Sets the severityLevel field. Trace severity level. 74 | */ 75 | public function setSeverityLevel($severityLevel) 76 | { 77 | $this->_data['severityLevel'] = $severityLevel; 78 | } 79 | 80 | /** 81 | * Gets the properties field. Collection of custom properties. 82 | */ 83 | public function getProperties() 84 | { 85 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 86 | return NULL; 87 | } 88 | 89 | /** 90 | * Sets the properties field. Collection of custom properties. 91 | */ 92 | public function setProperties($properties) 93 | { 94 | $this->_data['properties'] = $properties; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Message_Severity_Level.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Metric_Data. An instance of the Metric item is a list of measurements (single data points) and/or aggregations. 14 | */ 15 | class Metric_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new MetricData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.Metric'; 24 | $this->_dataTypeName = 'MetricData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['metrics'] = []; 27 | } 28 | 29 | /** 30 | * Gets the ver field. Schema version 31 | */ 32 | public function getVer() 33 | { 34 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 35 | return NULL; 36 | } 37 | 38 | /** 39 | * Sets the ver field. Schema version 40 | */ 41 | public function setVer($ver) 42 | { 43 | $this->_data['ver'] = $ver; 44 | } 45 | 46 | /** 47 | * Gets the metrics field. List of metrics. Only one metric in the list is currently supported by Application Insights storage. If multiple data points were sent only the first one will be used. 48 | */ 49 | public function getMetrics() 50 | { 51 | if (array_key_exists('metrics', $this->_data)) { return $this->_data['metrics']; } 52 | return NULL; 53 | } 54 | 55 | /** 56 | * Sets the metrics field. List of metrics. Only one metric in the list is currently supported by Application Insights storage. If multiple data points were sent only the first one will be used. 57 | */ 58 | public function setMetrics($metrics) 59 | { 60 | $this->_data['metrics'] = $metrics; 61 | } 62 | 63 | /** 64 | * Gets the properties field. Collection of custom properties. 65 | */ 66 | public function getProperties() 67 | { 68 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 69 | return NULL; 70 | } 71 | 72 | /** 73 | * Sets the properties field. Collection of custom properties. 74 | */ 75 | public function setProperties($properties) 76 | { 77 | $this->_data['properties'] = $properties; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Operation.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Operation. 14 | */ 15 | class Operation 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Operation. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the id field. A unique identifier for the operation instance. The operation.id is created by either a request or a page view. All other telemetry sets this to the value for the containing request or page view. Operation.id is used for finding all the telemetry items for a specific operation instance. 34 | */ 35 | public function getId() 36 | { 37 | if (array_key_exists('ai.operation.id', $this->_data)) { return $this->_data['ai.operation.id']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the id field. A unique identifier for the operation instance. The operation.id is created by either a request or a page view. All other telemetry sets this to the value for the containing request or page view. Operation.id is used for finding all the telemetry items for a specific operation instance. 43 | */ 44 | public function setId($id) 45 | { 46 | $this->_data['ai.operation.id'] = $id; 47 | } 48 | 49 | /** 50 | * Gets the name field. The name (group) of the operation. The operation.name is created by either a request or a page view. All other telemetry items set this to the value for the containing request or page view. Operation.name is used for finding all the telemetry items for a group of operations (i.e. 'GET Home/Index'). 51 | */ 52 | public function getName() 53 | { 54 | if (array_key_exists('ai.operation.name', $this->_data)) { return $this->_data['ai.operation.name']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the name field. The name (group) of the operation. The operation.name is created by either a request or a page view. All other telemetry items set this to the value for the containing request or page view. Operation.name is used for finding all the telemetry items for a group of operations (i.e. 'GET Home/Index'). 60 | */ 61 | public function setName($name) 62 | { 63 | $this->_data['ai.operation.name'] = $name; 64 | } 65 | 66 | /** 67 | * Gets the parentId field. The unique identifier of the telemetry item's immediate parent. 68 | */ 69 | public function getParentId() 70 | { 71 | if (array_key_exists('ai.operation.parentId', $this->_data)) { return $this->_data['ai.operation.parentId']; } 72 | return NULL; 73 | } 74 | 75 | /** 76 | * Sets the parentId field. The unique identifier of the telemetry item's immediate parent. 77 | */ 78 | public function setParentId($parentId) 79 | { 80 | $this->_data['ai.operation.parentId'] = $parentId; 81 | } 82 | 83 | /** 84 | * Gets the syntheticSource field. Name of synthetic source. Some telemetry from the application may represent a synthetic traffic. It may be web crawler indexing the web site, site availability tests or traces from diagnostic libraries like Application Insights SDK itself. 85 | */ 86 | public function getSyntheticSource() 87 | { 88 | if (array_key_exists('ai.operation.syntheticSource', $this->_data)) { return $this->_data['ai.operation.syntheticSource']; } 89 | return NULL; 90 | } 91 | 92 | /** 93 | * Sets the syntheticSource field. Name of synthetic source. Some telemetry from the application may represent a synthetic traffic. It may be web crawler indexing the web site, site availability tests or traces from diagnostic libraries like Application Insights SDK itself. 94 | */ 95 | public function setSyntheticSource($syntheticSource) 96 | { 97 | $this->_data['ai.operation.syntheticSource'] = $syntheticSource; 98 | } 99 | 100 | /** 101 | * Gets the correlationVector field. The correlation vector is a light weight vector clock which can be used to identify and order related events across clients and services. 102 | */ 103 | public function getCorrelationVector() 104 | { 105 | if (array_key_exists('ai.operation.correlationVector', $this->_data)) { return $this->_data['ai.operation.correlationVector']; } 106 | return NULL; 107 | } 108 | 109 | /** 110 | * Sets the correlationVector field. The correlation vector is a light weight vector clock which can be used to identify and order related events across clients and services. 111 | */ 112 | public function setCorrelationVector($correlationVector) 113 | { 114 | $this->_data['ai.operation.correlationVector'] = $correlationVector; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Page_View_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Page_View_Data. An instance of PageView represents a generic action on a page like a button click. It is also the base type for PageView. 14 | */ 15 | class Page_View_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new PageViewData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.PageView'; 24 | $this->_dataTypeName = 'PageViewData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['name'] = NULL; 27 | } 28 | 29 | /** 30 | * Gets the ver field. Schema version 31 | */ 32 | public function getVer() 33 | { 34 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 35 | return NULL; 36 | } 37 | 38 | /** 39 | * Sets the ver field. Schema version 40 | */ 41 | public function setVer($ver) 42 | { 43 | $this->_data['ver'] = $ver; 44 | } 45 | 46 | /** 47 | * Gets the url field. Request URL with all query string parameters 48 | */ 49 | public function getUrl() 50 | { 51 | if (array_key_exists('url', $this->_data)) { return $this->_data['url']; } 52 | return NULL; 53 | } 54 | 55 | /** 56 | * Sets the url field. Request URL with all query string parameters 57 | */ 58 | public function setUrl($url) 59 | { 60 | $this->_data['url'] = $url; 61 | } 62 | 63 | /** 64 | * Gets the name field. Event name. Keep it low cardinality to allow proper grouping and useful metrics. 65 | */ 66 | public function getName() 67 | { 68 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 69 | return NULL; 70 | } 71 | 72 | /** 73 | * Sets the name field. Event name. Keep it low cardinality to allow proper grouping and useful metrics. 74 | */ 75 | public function setName($name) 76 | { 77 | $this->_data['name'] = $name; 78 | } 79 | 80 | /** 81 | * Gets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. For a page view (PageViewData), this is the duration. For a page view with performance information (PageViewPerfData), this is the page load time. Must be less than 1000 days. 82 | */ 83 | public function getDuration() 84 | { 85 | if (array_key_exists('duration', $this->_data)) { return $this->_data['duration']; } 86 | return NULL; 87 | } 88 | 89 | /** 90 | * Sets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. For a page view (PageViewData), this is the duration. For a page view with performance information (PageViewPerfData), this is the page load time. Must be less than 1000 days. 91 | */ 92 | public function setDuration($duration) 93 | { 94 | $this->_data['duration'] = $duration; 95 | } 96 | 97 | /** 98 | * Gets the id field. Identifier of a page view instance. Used for correlation between page view and other telemetry items. 99 | */ 100 | public function getId() 101 | { 102 | if (array_key_exists('id', $this->_data)) { return $this->_data['id']; } 103 | return NULL; 104 | } 105 | 106 | /** 107 | * Sets the id field. Identifier of a page view instance. Used for correlation between page view and other telemetry items. 108 | */ 109 | public function setId($id) 110 | { 111 | $this->_data['id'] = $id; 112 | } 113 | 114 | /** 115 | * Gets the referrerUri field. Fully qualified page URI or URL of the referring page; if unknown, leave blank. 116 | */ 117 | public function getReferrerUri() 118 | { 119 | if (array_key_exists('referrerUri', $this->_data)) { return $this->_data['referrerUri']; } 120 | return NULL; 121 | } 122 | 123 | /** 124 | * Sets the referrerUri field. Fully qualified page URI or URL of the referring page; if unknown, leave blank. 125 | */ 126 | public function setReferrerUri($referrerUri) 127 | { 128 | $this->_data['referrerUri'] = $referrerUri; 129 | } 130 | 131 | /** 132 | * Gets the properties field. Collection of custom properties. 133 | */ 134 | public function getProperties() 135 | { 136 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 137 | return NULL; 138 | } 139 | 140 | /** 141 | * Sets the properties field. Collection of custom properties. 142 | */ 143 | public function setProperties($properties) 144 | { 145 | $this->_data['properties'] = $properties; 146 | } 147 | 148 | /** 149 | * Gets the measurements field. Collection of custom measurements. 150 | */ 151 | public function getMeasurements() 152 | { 153 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 154 | return NULL; 155 | } 156 | 157 | /** 158 | * Sets the measurements field. Collection of custom measurements. 159 | */ 160 | public function setMeasurements($measurements) 161 | { 162 | $this->_data['measurements'] = $measurements; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Page_View_Perf_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Page_View_Perf_Data. An instance of PageViewPerf represents: a page view with no performance data, a page view with performance data, or just the performance data of an earlier page request. 14 | */ 15 | class Page_View_Perf_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new PageViewPerfData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.PageViewPerf'; 24 | $this->_dataTypeName = 'PageViewPerfData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['name'] = NULL; 27 | } 28 | 29 | /** 30 | * Gets the ver field. Schema version 31 | */ 32 | public function getVer() 33 | { 34 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 35 | return NULL; 36 | } 37 | 38 | /** 39 | * Sets the ver field. Schema version 40 | */ 41 | public function setVer($ver) 42 | { 43 | $this->_data['ver'] = $ver; 44 | } 45 | 46 | /** 47 | * Gets the url field. Request URL with all query string parameters 48 | */ 49 | public function getUrl() 50 | { 51 | if (array_key_exists('url', $this->_data)) { return $this->_data['url']; } 52 | return NULL; 53 | } 54 | 55 | /** 56 | * Sets the url field. Request URL with all query string parameters 57 | */ 58 | public function setUrl($url) 59 | { 60 | $this->_data['url'] = $url; 61 | } 62 | 63 | /** 64 | * Gets the perfTotal field. Performance total in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 65 | */ 66 | public function getPerfTotal() 67 | { 68 | if (array_key_exists('perfTotal', $this->_data)) { return $this->_data['perfTotal']; } 69 | return NULL; 70 | } 71 | 72 | /** 73 | * Sets the perfTotal field. Performance total in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 74 | */ 75 | public function setPerfTotal($perfTotal) 76 | { 77 | $this->_data['perfTotal'] = $perfTotal; 78 | } 79 | 80 | /** 81 | * Gets the name field. Event name. Keep it low cardinality to allow proper grouping and useful metrics. 82 | */ 83 | public function getName() 84 | { 85 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 86 | return NULL; 87 | } 88 | 89 | /** 90 | * Sets the name field. Event name. Keep it low cardinality to allow proper grouping and useful metrics. 91 | */ 92 | public function setName($name) 93 | { 94 | $this->_data['name'] = $name; 95 | } 96 | 97 | /** 98 | * Gets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. For a page view (PageViewData), this is the duration. For a page view with performance information (PageViewPerfData), this is the page load time. Must be less than 1000 days. 99 | */ 100 | public function getDuration() 101 | { 102 | if (array_key_exists('duration', $this->_data)) { return $this->_data['duration']; } 103 | return NULL; 104 | } 105 | 106 | /** 107 | * Sets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. For a page view (PageViewData), this is the duration. For a page view with performance information (PageViewPerfData), this is the page load time. Must be less than 1000 days. 108 | */ 109 | public function setDuration($duration) 110 | { 111 | $this->_data['duration'] = $duration; 112 | } 113 | 114 | /** 115 | * Gets the networkConnect field. Network connection time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 116 | */ 117 | public function getNetworkConnect() 118 | { 119 | if (array_key_exists('networkConnect', $this->_data)) { return $this->_data['networkConnect']; } 120 | return NULL; 121 | } 122 | 123 | /** 124 | * Sets the networkConnect field. Network connection time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 125 | */ 126 | public function setNetworkConnect($networkConnect) 127 | { 128 | $this->_data['networkConnect'] = $networkConnect; 129 | } 130 | 131 | /** 132 | * Gets the sentRequest field. Sent request time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 133 | */ 134 | public function getSentRequest() 135 | { 136 | if (array_key_exists('sentRequest', $this->_data)) { return $this->_data['sentRequest']; } 137 | return NULL; 138 | } 139 | 140 | /** 141 | * Sets the sentRequest field. Sent request time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 142 | */ 143 | public function setSentRequest($sentRequest) 144 | { 145 | $this->_data['sentRequest'] = $sentRequest; 146 | } 147 | 148 | /** 149 | * Gets the receivedResponse field. Received response time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 150 | */ 151 | public function getReceivedResponse() 152 | { 153 | if (array_key_exists('receivedResponse', $this->_data)) { return $this->_data['receivedResponse']; } 154 | return NULL; 155 | } 156 | 157 | /** 158 | * Sets the receivedResponse field. Received response time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 159 | */ 160 | public function setReceivedResponse($receivedResponse) 161 | { 162 | $this->_data['receivedResponse'] = $receivedResponse; 163 | } 164 | 165 | /** 166 | * Gets the id field. Identifier of a page view instance. Used for correlation between page view and other telemetry items. 167 | */ 168 | public function getId() 169 | { 170 | if (array_key_exists('id', $this->_data)) { return $this->_data['id']; } 171 | return NULL; 172 | } 173 | 174 | /** 175 | * Sets the id field. Identifier of a page view instance. Used for correlation between page view and other telemetry items. 176 | */ 177 | public function setId($id) 178 | { 179 | $this->_data['id'] = $id; 180 | } 181 | 182 | /** 183 | * Gets the domProcessing field. DOM processing time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 184 | */ 185 | public function getDomProcessing() 186 | { 187 | if (array_key_exists('domProcessing', $this->_data)) { return $this->_data['domProcessing']; } 188 | return NULL; 189 | } 190 | 191 | /** 192 | * Sets the domProcessing field. DOM processing time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff 193 | */ 194 | public function setDomProcessing($domProcessing) 195 | { 196 | $this->_data['domProcessing'] = $domProcessing; 197 | } 198 | 199 | /** 200 | * Gets the referrerUri field. Fully qualified page URI or URL of the referring page; if unknown, leave blank. 201 | */ 202 | public function getReferrerUri() 203 | { 204 | if (array_key_exists('referrerUri', $this->_data)) { return $this->_data['referrerUri']; } 205 | return NULL; 206 | } 207 | 208 | /** 209 | * Sets the referrerUri field. Fully qualified page URI or URL of the referring page; if unknown, leave blank. 210 | */ 211 | public function setReferrerUri($referrerUri) 212 | { 213 | $this->_data['referrerUri'] = $referrerUri; 214 | } 215 | 216 | /** 217 | * Gets the properties field. Collection of custom properties. 218 | */ 219 | public function getProperties() 220 | { 221 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 222 | return NULL; 223 | } 224 | 225 | /** 226 | * Sets the properties field. Collection of custom properties. 227 | */ 228 | public function setProperties($properties) 229 | { 230 | $this->_data['properties'] = $properties; 231 | } 232 | 233 | /** 234 | * Gets the measurements field. Collection of custom measurements. 235 | */ 236 | public function getMeasurements() 237 | { 238 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 239 | return NULL; 240 | } 241 | 242 | /** 243 | * Sets the measurements field. Collection of custom measurements. 244 | */ 245 | public function setMeasurements($measurements) 246 | { 247 | $this->_data['measurements'] = $measurements; 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Request_Data.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Request_Data. An instance of Request represents completion of an external request to the application to do work and contains a summary of that request execution and the results. 14 | */ 15 | class Request_Data extends Base_Data implements Data_Interface 16 | { 17 | 18 | /** 19 | * Creates a new RequestData. 20 | */ 21 | function __construct() 22 | { 23 | $this->_envelopeTypeName = 'Microsoft.ApplicationInsights.Request'; 24 | $this->_dataTypeName = 'RequestData'; 25 | $this->_data['ver'] = 2; 26 | $this->_data['id'] = NULL; 27 | $this->_data['duration'] = NULL; 28 | $this->_data['responseCode'] = NULL; 29 | $this->_data['success'] = NULL; 30 | } 31 | 32 | /** 33 | * Gets the ver field. Schema version 34 | */ 35 | public function getVer() 36 | { 37 | if (array_key_exists('ver', $this->_data)) { return $this->_data['ver']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the ver field. Schema version 43 | */ 44 | public function setVer($ver) 45 | { 46 | $this->_data['ver'] = $ver; 47 | } 48 | 49 | /** 50 | * Gets the id field. Identifier of a request call instance. Used for correlation between request and other telemetry items. 51 | */ 52 | public function getId() 53 | { 54 | if (array_key_exists('id', $this->_data)) { return $this->_data['id']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the id field. Identifier of a request call instance. Used for correlation between request and other telemetry items. 60 | */ 61 | public function setId($id) 62 | { 63 | $this->_data['id'] = $id; 64 | } 65 | 66 | /** 67 | * Gets the source field. Source of the request. Examples are the instrumentation key of the caller or the ip address of the caller. 68 | */ 69 | public function getSource() 70 | { 71 | if (array_key_exists('source', $this->_data)) { return $this->_data['source']; } 72 | return NULL; 73 | } 74 | 75 | /** 76 | * Sets the source field. Source of the request. Examples are the instrumentation key of the caller or the ip address of the caller. 77 | */ 78 | public function setSource($source) 79 | { 80 | $this->_data['source'] = $source; 81 | } 82 | 83 | /** 84 | * Gets the name field. Name of the request. Represents code path taken to process request. Low cardinality value to allow better grouping of requests. For HTTP requests it represents the HTTP method and URL path template like 'GET /values/{id}'. 85 | */ 86 | public function getName() 87 | { 88 | if (array_key_exists('name', $this->_data)) { return $this->_data['name']; } 89 | return NULL; 90 | } 91 | 92 | /** 93 | * Sets the name field. Name of the request. Represents code path taken to process request. Low cardinality value to allow better grouping of requests. For HTTP requests it represents the HTTP method and URL path template like 'GET /values/{id}'. 94 | */ 95 | public function setName($name) 96 | { 97 | $this->_data['name'] = $name; 98 | } 99 | 100 | /** 101 | * Gets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days. 102 | */ 103 | public function getDuration() 104 | { 105 | if (array_key_exists('duration', $this->_data)) { return $this->_data['duration']; } 106 | return NULL; 107 | } 108 | 109 | /** 110 | * Sets the duration field. Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days. 111 | */ 112 | public function setDuration($duration) 113 | { 114 | $this->_data['duration'] = $duration; 115 | } 116 | 117 | /** 118 | * Gets the responseCode field. Result of a request execution. HTTP status code for HTTP requests. 119 | */ 120 | public function getResponseCode() 121 | { 122 | if (array_key_exists('responseCode', $this->_data)) { return $this->_data['responseCode']; } 123 | return NULL; 124 | } 125 | 126 | /** 127 | * Sets the responseCode field. Result of a request execution. HTTP status code for HTTP requests. 128 | */ 129 | public function setResponseCode($responseCode) 130 | { 131 | $this->_data['responseCode'] = $responseCode; 132 | } 133 | 134 | /** 135 | * Gets the success field. Indication of successfull or unsuccessfull call. 136 | */ 137 | public function getSuccess() 138 | { 139 | if (array_key_exists('success', $this->_data)) { return $this->_data['success']; } 140 | return NULL; 141 | } 142 | 143 | /** 144 | * Sets the success field. Indication of successfull or unsuccessfull call. 145 | */ 146 | public function setSuccess($success) 147 | { 148 | $this->_data['success'] = $success; 149 | } 150 | 151 | /** 152 | * Gets the url field. Request URL with all query string parameters. 153 | */ 154 | public function getUrl() 155 | { 156 | if (array_key_exists('url', $this->_data)) { return $this->_data['url']; } 157 | return NULL; 158 | } 159 | 160 | /** 161 | * Sets the url field. Request URL with all query string parameters. 162 | */ 163 | public function setUrl($url) 164 | { 165 | $this->_data['url'] = $url; 166 | } 167 | 168 | /** 169 | * Gets the properties field. Collection of custom properties. 170 | */ 171 | public function getProperties() 172 | { 173 | if (array_key_exists('properties', $this->_data)) { return $this->_data['properties']; } 174 | return NULL; 175 | } 176 | 177 | /** 178 | * Sets the properties field. Collection of custom properties. 179 | */ 180 | public function setProperties($properties) 181 | { 182 | $this->_data['properties'] = $properties; 183 | } 184 | 185 | /** 186 | * Gets the measurements field. Collection of custom measurements. 187 | */ 188 | public function getMeasurements() 189 | { 190 | if (array_key_exists('measurements', $this->_data)) { return $this->_data['measurements']; } 191 | return NULL; 192 | } 193 | 194 | /** 195 | * Sets the measurements field. Collection of custom measurements. 196 | */ 197 | public function setMeasurements($measurements) 198 | { 199 | $this->_data['measurements'] = $measurements; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Session.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Session. 14 | */ 15 | class Session 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new Session. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the id field. Session ID - the instance of the user's interaction with the app. Information in the session context fields is always about the end user. When telemetry is sent from a service, the session context is about the user that initiated the operation in the service. 34 | */ 35 | public function getId() 36 | { 37 | if (array_key_exists('ai.session.id', $this->_data)) { return $this->_data['ai.session.id']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the id field. Session ID - the instance of the user's interaction with the app. Information in the session context fields is always about the end user. When telemetry is sent from a service, the session context is about the user that initiated the operation in the service. 43 | */ 44 | public function setId($id) 45 | { 46 | $this->_data['ai.session.id'] = $id; 47 | } 48 | 49 | /** 50 | * Gets the isFirst field. Boolean value indicating whether the session identified by ai.session.id is first for the user or not. 51 | */ 52 | public function getIsFirst() 53 | { 54 | if (array_key_exists('ai.session.isFirst', $this->_data)) { return $this->_data['ai.session.isFirst']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the isFirst field. Boolean value indicating whether the session identified by ai.session.id is first for the user or not. 60 | */ 61 | public function setIsFirst($isFirst) 62 | { 63 | $this->_data['ai.session.isFirst'] = var_export($isFirst, TRUE); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Severity_Level.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | /** 12 | * Enum Severity_Level. 13 | */ 14 | abstract class Severity_Level 15 | { 16 | const Verbose = 0; 17 | const Information = 1; 18 | const Warning = 2; 19 | const Error = 3; 20 | const Critical = 4; 21 | } 22 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Stack_Frame.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type Stack_Frame. Stack frame information. 14 | */ 15 | class Stack_Frame 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new StackFrame. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data['level'] = NULL; 30 | $this->_data['method'] = NULL; 31 | } 32 | 33 | /** 34 | * Gets the level field. Level in the call stack. For the long stacks SDK may not report every function in a call stack. 35 | */ 36 | public function getLevel() 37 | { 38 | if (array_key_exists('level', $this->_data)) { return $this->_data['level']; } 39 | return NULL; 40 | } 41 | 42 | /** 43 | * Sets the level field. Level in the call stack. For the long stacks SDK may not report every function in a call stack. 44 | */ 45 | public function setLevel($level) 46 | { 47 | $this->_data['level'] = $level; 48 | } 49 | 50 | /** 51 | * Gets the method field. Method name. 52 | */ 53 | public function getMethod() 54 | { 55 | if (array_key_exists('method', $this->_data)) { return $this->_data['method']; } 56 | return NULL; 57 | } 58 | 59 | /** 60 | * Sets the method field. Method name. 61 | */ 62 | public function setMethod($method) 63 | { 64 | $this->_data['method'] = $method; 65 | } 66 | 67 | /** 68 | * Gets the assembly field. Name of the assembly (dll, jar, etc.) containing this function. 69 | */ 70 | public function getAssembly() 71 | { 72 | if (array_key_exists('assembly', $this->_data)) { return $this->_data['assembly']; } 73 | return NULL; 74 | } 75 | 76 | /** 77 | * Sets the assembly field. Name of the assembly (dll, jar, etc.) containing this function. 78 | */ 79 | public function setAssembly($assembly) 80 | { 81 | $this->_data['assembly'] = $assembly; 82 | } 83 | 84 | /** 85 | * Gets the fileName field. File name or URL of the method implementation. 86 | */ 87 | public function getFileName() 88 | { 89 | if (array_key_exists('fileName', $this->_data)) { return $this->_data['fileName']; } 90 | return NULL; 91 | } 92 | 93 | /** 94 | * Sets the fileName field. File name or URL of the method implementation. 95 | */ 96 | public function setFileName($fileName) 97 | { 98 | $this->_data['fileName'] = $fileName; 99 | } 100 | 101 | /** 102 | * Gets the line field. Line number of the code implementation. 103 | */ 104 | public function getLine() 105 | { 106 | if (array_key_exists('line', $this->_data)) { return $this->_data['line']; } 107 | return NULL; 108 | } 109 | 110 | /** 111 | * Sets the line field. Line number of the code implementation. 112 | */ 113 | public function setLine($line) 114 | { 115 | $this->_data['line'] = $line; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/User.php: -------------------------------------------------------------------------------- 1 | /Schema/generateSchema.ps1 9 | * 10 | */ 11 | 12 | /** 13 | * Data contract class for type User. 14 | */ 15 | class User 16 | { 17 | use Json_Serializer; 18 | 19 | /** 20 | * Data array that will store all the values. 21 | */ 22 | private $_data; 23 | 24 | /** 25 | * Creates a new User. 26 | */ 27 | function __construct() 28 | { 29 | $this->_data = array(); 30 | } 31 | 32 | /** 33 | * Gets the accountId field. In multi-tenant applications this is the account ID or name which the user is acting with. Examples may be subscription ID for Azure portal or blog name blogging platform. 34 | */ 35 | public function getAccountId() 36 | { 37 | if (array_key_exists('ai.user.accountId', $this->_data)) { return $this->_data['ai.user.accountId']; } 38 | return NULL; 39 | } 40 | 41 | /** 42 | * Sets the accountId field. In multi-tenant applications this is the account ID or name which the user is acting with. Examples may be subscription ID for Azure portal or blog name blogging platform. 43 | */ 44 | public function setAccountId($accountId) 45 | { 46 | $this->_data['ai.user.accountId'] = $accountId; 47 | } 48 | 49 | /** 50 | * Gets the id field. Anonymous user id. Represents the end user of the application. When telemetry is sent from a service, the user context is about the user that initiated the operation in the service. 51 | */ 52 | public function getId() 53 | { 54 | if (array_key_exists('ai.user.id', $this->_data)) { return $this->_data['ai.user.id']; } 55 | return NULL; 56 | } 57 | 58 | /** 59 | * Sets the id field. Anonymous user id. Represents the end user of the application. When telemetry is sent from a service, the user context is about the user that initiated the operation in the service. 60 | */ 61 | public function setId($id) 62 | { 63 | $this->_data['ai.user.id'] = $id; 64 | } 65 | 66 | /** 67 | * Gets the authUserId field. Authenticated user id. The opposite of ai.user.id, this represents the user with a friendly name. Since it's PII information it is not collected by default by most SDKs. 68 | */ 69 | public function getAuthUserId() 70 | { 71 | if (array_key_exists('ai.user.authUserId', $this->_data)) { return $this->_data['ai.user.authUserId']; } 72 | return NULL; 73 | } 74 | 75 | /** 76 | * Sets the authUserId field. Authenticated user id. The opposite of ai.user.id, this represents the user with a friendly name. Since it's PII information it is not collected by default by most SDKs. 77 | */ 78 | public function setAuthUserId($authUserId) 79 | { 80 | $this->_data['ai.user.authUserId'] = $authUserId; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Utils.php: -------------------------------------------------------------------------------- 1 | $value) 18 | { 19 | if ((is_array($value) && sizeof($value) == 0) || ($value == NULL && is_bool($value) == false)) 20 | { 21 | continue; 22 | } 23 | $newArray[$key] = $value; 24 | } 25 | 26 | return $newArray; 27 | } 28 | 29 | /** 30 | * Serialization helper. 31 | * @param array Items to serialize 32 | * @return array JSON serialized items, nested 33 | */ 34 | public static function getUnderlyingData($dataItems) 35 | { 36 | $queueToEncode = array(); 37 | foreach ($dataItems as $key => $dataItem) 38 | { 39 | if (is_object($dataItem) && method_exists($dataItem, 'jsonSerialize') == true) 40 | { 41 | $queueToEncode[$key] = Utils::getUnderlyingData($dataItem->jsonSerialize()); 42 | } 43 | else if (is_array($dataItem)) 44 | { 45 | $queueToEncode[$key] = Utils::getUnderlyingData($dataItem); 46 | } 47 | else 48 | { 49 | $queueToEncode[$key] = $dataItem; 50 | } 51 | } 52 | 53 | return $queueToEncode; 54 | } 55 | 56 | /** 57 | * Converts milliseconds to a timespan string as accepted by the backend 58 | * @param int $milliseconds 59 | * @return string 60 | */ 61 | public static function convertMillisecondsToTimeSpan($milliseconds) 62 | { 63 | if ($milliseconds == NULL || $milliseconds < 0 || !is_numeric($milliseconds)) 64 | { 65 | $milliseconds = 0; 66 | } 67 | 68 | $ms = $milliseconds % 1000; 69 | $sec = floor($milliseconds / 1000) % 60; 70 | $min = floor($milliseconds / (1000 * 60)) % 60; 71 | $hour = floor($milliseconds / (1000 * 60 * 60)) % 24; 72 | 73 | $ms = strlen($ms) == 1 ? '00' . $ms : (strlen($ms) === 2 ? "0" . $ms : $ms); 74 | $sec = strlen($sec) < 2 ? '0' . $sec : $sec; 75 | $min = strlen($min) < 2 ? '0' . $min : $min; 76 | $hour = strlen($hour) < 2 ? '0' . $hour : $hour; 77 | 78 | return $hour . ":" . $min . ":" . $sec . "." . $ms; 79 | } 80 | 81 | /** 82 | * Returns the proper ISO string for Application Insights service to accept. 83 | * @param mixed $time 84 | * @return string 85 | */ 86 | public static function returnISOStringForTime($time = null) 87 | { 88 | if ($time == NULL) 89 | { 90 | return gmdate('c') . 'Z'; 91 | } 92 | else 93 | { 94 | return gmdate('c', $time) . 'Z'; 95 | } 96 | } 97 | 98 | /** 99 | * Returns a Guid on all flavors of PHP. Copied from the PHP manual: http://php.net/manual/en/function.com-create-guid.php 100 | * @return mixed 101 | */ 102 | public static function returnGuid() 103 | { 104 | if (function_exists('com_create_guid') === true) 105 | { 106 | return trim(com_create_guid(), '{}'); 107 | } 108 | 109 | return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); 110 | 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Contracts/Version_Manager.php: -------------------------------------------------------------------------------- 1 | _data)) { return $this->_data['ver']; } 15 | return NULL; 16 | } 17 | 18 | /** 19 | * Sets the ver field. 20 | */ 21 | public function setVer($ver) 22 | { 23 | $this->_data['ver'] = $ver; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ApplicationInsights/Channel/Telemetry_Channel.php: -------------------------------------------------------------------------------- 1 | _endpointUrl = $endpointUrl; 41 | $this->_queue = array(); 42 | $this->_client = $client; 43 | $this->_sendGzipped = false; 44 | 45 | if ($client === null && class_exists('\GuzzleHttp\Client') == true) { 46 | // Standard case if properly pulled in composer dependencies 47 | $this->_client = new \GuzzleHttp\Client(); 48 | } 49 | } 50 | 51 | /** 52 | * Returns the current URL this TelemetrySender will send to. 53 | * @return string 54 | */ 55 | public function getEndpointUrl() 56 | { 57 | return $this->_endpointUrl; 58 | } 59 | 60 | /** 61 | * Sets the current URL this TelemetrySender will send to. 62 | * @param string $endpointUrl 63 | */ 64 | public function setEndpointUrl($endpointUrl) 65 | { 66 | $this->_endpointUrl = $endpointUrl; 67 | } 68 | 69 | /** 70 | * Returns the current queue. 71 | * @return array 72 | */ 73 | public function getQueue() 74 | { 75 | return $this->_queue; 76 | } 77 | 78 | /** 79 | * Sets the current queue. 80 | * @param array $queue 81 | */ 82 | public function setQueue($queue) 83 | { 84 | $this->_queue = $queue; 85 | } 86 | 87 | /** 88 | * @return \GuzzleHttp\Client 89 | */ 90 | public function GetClient() 91 | { 92 | return $this->_client; 93 | } 94 | 95 | /** 96 | * @param \GuzzleHttp\Client $client 97 | */ 98 | public function SetClient(\GuzzleHttp\Client $client) 99 | { 100 | $this->_client = $client; 101 | } 102 | 103 | /** 104 | * Summary of getSerializedQueue 105 | * @return string JSON representation of queue. 106 | */ 107 | public function getSerializedQueue() 108 | { 109 | $queueToEncode = array(); 110 | foreach ($this->_queue as $dataItem) 111 | { 112 | array_push($queueToEncode, Contracts\Utils::getUnderlyingData($dataItem->jsonSerialize())); 113 | } 114 | 115 | return json_encode($queueToEncode); 116 | } 117 | 118 | /** 119 | * @return bool 120 | */ 121 | public function getSendGzipped() 122 | { 123 | return $this->_sendGzipped; 124 | } 125 | 126 | /** 127 | * @param bool $sendGzipped 128 | */ 129 | public function setSendGzipped($sendGzipped) 130 | { 131 | $this->_sendGzipped = $sendGzipped; 132 | } 133 | 134 | 135 | 136 | /** 137 | * Writes the item into the sending queue for subsequent processing. 138 | * @param \ApplicationInsights\Channel\Contracts\Data_Interface $data The telemetry item to send. 139 | * @param \ApplicationInsights\Telemetry_Context $telemetryContext The context to use. 140 | */ 141 | public function addToQueue( 142 | \ApplicationInsights\Channel\Contracts\Data_Interface $data, 143 | \ApplicationInsights\Telemetry_Context $telemetryContext, 144 | $startTime = null) 145 | { 146 | // If no data or context provided, we just return to not cause upstream issues as a result of telemetry 147 | if ($data == NULL || $telemetryContext == NULL) 148 | { 149 | return; 150 | } 151 | 152 | $envelope = new Contracts\Envelope(); 153 | 154 | // Main envelope properties 155 | $envelope->setName($data->getEnvelopeTypeName()); 156 | if ($startTime == NULL) 157 | { 158 | $startTime = $data->getTime(); 159 | } 160 | 161 | $envelope->setTime(Contracts\Utils::returnISOStringForTime($startTime)); 162 | 163 | // The instrumentation key to use 164 | $envelope->setInstrumentationKey($telemetryContext->getInstrumentationKey()); 165 | 166 | // Copy all context into the Tags array 167 | $envelope->setTags(array_merge($telemetryContext->getApplicationContext()->jsonSerialize(), 168 | $telemetryContext->getDeviceContext()->jsonSerialize(), 169 | $telemetryContext->getCloudContext()->jsonSerialize(), 170 | $telemetryContext->getLocationContext()->jsonSerialize(), 171 | $telemetryContext->getOperationContext()->jsonSerialize(), 172 | $telemetryContext->getSessionContext()->jsonSerialize(), 173 | $telemetryContext->getUserContext()->jsonSerialize(), 174 | $telemetryContext->getInternalContext()->jsonSerialize())); 175 | 176 | // Merge properties from global context to local context 177 | $contextProperties = $telemetryContext->getProperties(); 178 | if (method_exists($data, 'getProperties') == true && $contextProperties != NULL && count($contextProperties) > 0) 179 | { 180 | $dataProperties = $data->getProperties(); 181 | if ($dataProperties == NULL) 182 | { 183 | $dataProperties = array(); 184 | } 185 | foreach ($contextProperties as $key => $value) 186 | { 187 | if (array_key_exists($key, $dataProperties) == false) 188 | { 189 | $dataProperties[$key] = $value; 190 | } 191 | } 192 | $data->setProperties($dataProperties); 193 | } 194 | 195 | // Embed the main data object 196 | $envelope->setData(new Contracts\Data()); 197 | $envelope->getData()->setBaseType($data->getDataTypeName()); 198 | $envelope->getData()->setBaseData($data); 199 | 200 | array_push($this->_queue, $envelope); 201 | } 202 | 203 | /** 204 | * Summary of send 205 | * @param array $options 206 | * @param bool $sendAsync 207 | * @return \GuzzleHttp\Promise\PromiseInterface|\Psr\Http\Message\ResponseInterface|null|WP_Error 208 | */ 209 | public function send($options = array(), $sendAsync = false) 210 | { 211 | $response = null; 212 | $useGuzzle = $this->_client !== null; 213 | if (count($this->_queue) == 0) 214 | { 215 | return; 216 | } 217 | 218 | $serializedTelemetryItem = $this->getSerializedQueue(); 219 | 220 | if($this->_sendGzipped && $useGuzzle) 221 | { 222 | $headersArray = array( 223 | 'Content-Encoding' => 'gzip', 224 | ); 225 | $body = gzencode($serializedTelemetryItem); 226 | } 227 | else 228 | { 229 | $headersArray = array( 230 | 'Accept' => 'application/json', 231 | 'Content-Type' => 'application/json; charset=utf-8' 232 | ); 233 | $body = utf8_encode($serializedTelemetryItem); 234 | } 235 | 236 | if ($useGuzzle) 237 | { 238 | $options = array_merge( 239 | array( 240 | 'headers' => $headersArray, 241 | 'body' => $body, 242 | 'verify' => false 243 | /* If you want to verify, you can, but you will need to provide proper CA bundle. See http://guzzle.readthedocs.org/en/latest/clients.html#verify-option */ 244 | //,'proxy' => '127.0.0.1:8888' /* For Fiddler debugging */ 245 | ), 246 | $options 247 | ); 248 | 249 | if ($sendAsync && method_exists($this->_client, 'sendAsync')) 250 | { 251 | $response = $this->_client->postAsync($this->_endpointUrl, $options); 252 | } 253 | else 254 | { 255 | $response = $this->_client->post($this->_endpointUrl, $options); 256 | } 257 | } 258 | else if (function_exists('wp_remote_post')) 259 | { 260 | // Used in WordPress 261 | $response = wp_remote_post($this->_endpointUrl, array( 262 | 'method' => 'POST', 263 | 'blocking' => !$sendAsync, 264 | 'headers' => $headersArray, 265 | 'body' => $body 266 | )); 267 | } 268 | return $response; 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /ApplicationInsights/Current_Session.php: -------------------------------------------------------------------------------- 1 | 0) 34 | { 35 | $this->id = $parts[0]; 36 | } 37 | 38 | if ($len > 1) 39 | { 40 | $this->sessionCreated = strtotime($parts[1]); 41 | } 42 | 43 | if ($len > 2) 44 | { 45 | $this->sessionLastRenewed = strtotime($parts[2]); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ApplicationInsights/Current_User.php: -------------------------------------------------------------------------------- 1 | 0) 23 | { 24 | $this->id = $parts[0]; 25 | } 26 | } 27 | 28 | if ($this->id == NULL) 29 | { 30 | $this->id = \ApplicationInsights\Channel\Contracts\Utils::returnGuid(); 31 | $_COOKIE['ai_user'] = $this->id; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ApplicationInsights/Telemetry_Client.php: -------------------------------------------------------------------------------- 1 | _context = ($context == NULL) ? new Telemetry_Context() : $context; 29 | $this->_channel = ($channel == NULL) ? new Channel\Telemetry_Channel() : $channel; 30 | } 31 | 32 | /** 33 | * Returns the Telemetry_Context this Telemetry_Client is using. 34 | * @return \ApplicationInsights\Telemetry_Context 35 | */ 36 | public function getContext() 37 | { 38 | return $this->_context; 39 | } 40 | 41 | /** 42 | * Returns the Telemetry_Channel this Telemetry_Client is using. 43 | * @return \ApplicationInsights\Channel\Telemetry_Channel 44 | */ 45 | public function getChannel() 46 | { 47 | return $this->_channel; 48 | } 49 | 50 | /** 51 | * Sends an Page_View_Data to the Application Insights service. 52 | * @param string $name The friendly name of the page view. 53 | * @param string $url The url of the page view. 54 | * @param int duration The duration in milliseconds of the page view. 55 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 56 | * @param array $measurements An array of name to double pairs. Use the name as the index and any double as the value. 57 | */ 58 | public function trackPageView($name, $url, $duration = 0, $properties = NULL, $measurements = NULL) 59 | { 60 | $data = new Channel\Contracts\Page_View_Data(); 61 | $data->setName($name); 62 | $data->setUrl($url); 63 | $data->setDuration(Channel\Contracts\Utils::convertMillisecondsToTimeSpan($duration)); 64 | if ($properties != NULL) 65 | { 66 | $data->setProperties($properties); 67 | } 68 | if ($measurements != NULL) 69 | { 70 | $data->setMeasurements($measurements); 71 | } 72 | 73 | $this->_channel->addToQueue($data, $this->_context); 74 | } 75 | 76 | /** 77 | * Sends an Metric_Data to the Application Insights service. 78 | * @param string $name Name of the metric. 79 | * @param double $value Value of the metric. 80 | * @param int $type The type of value being sent. Found: \ApplicationInsights\Channel\Contracts\Data_Point_Type::Value 81 | * @param int $count The number of samples. 82 | * @param double $min The minimum of the samples. 83 | * @param double $max The maximum of the samples. 84 | * @param double $stdDev The standard deviation of the samples. 85 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 86 | */ 87 | public function trackMetric($name, $value, $type = NULL, $count = NULL, $min = NULL, $max = NULL, $stdDev = NULL, $properties = NULL) 88 | { 89 | $dataPoint = new Channel\Contracts\Data_Point(); 90 | $dataPoint->setName($name); 91 | $dataPoint->setValue($value); 92 | $dataPoint->setKind($type == NULL ? Channel\Contracts\Data_Point_Type::Aggregation : $type); 93 | $dataPoint->setCount($count); 94 | $dataPoint->setMin($min); 95 | $dataPoint->setMax($max); 96 | $dataPoint->setStdDev($stdDev); 97 | 98 | $data = new Channel\Contracts\Metric_Data(); 99 | $data->setMetrics(array($dataPoint)); 100 | if ($properties != NULL) 101 | { 102 | $data->setProperties($properties); 103 | } 104 | 105 | $this->_channel->addToQueue($data, $this->_context); 106 | } 107 | 108 | /** 109 | * Sends an Event_Data to the Application Insights service. 110 | * @param string $name 111 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 112 | * @param array $measurements An array of name to double pairs. Use the name as the index and any double as the value. 113 | */ 114 | public function trackEvent($name, $properties = NULL, $measurements = NULL) 115 | { 116 | $data = new Channel\Contracts\Event_Data(); 117 | $data->setName($name); 118 | if ($properties != NULL) 119 | { 120 | $data->setProperties($properties); 121 | } 122 | if ($measurements != NULL) 123 | { 124 | $data->setMeasurements($measurements); 125 | } 126 | 127 | $this->_channel->addToQueue($data, $this->_context); 128 | } 129 | 130 | /** 131 | * Sends an Message_Data to the Application Insights service. 132 | * @param string $message The trace message. 133 | * @param string $severityLevel The severity level of the message. Found: \ApplicationInsights\Channel\Contracts\Message_Severity_Level::Value 134 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 135 | */ 136 | public function trackMessage($message, $severityLevel = NULL, $properties = NULL) 137 | { 138 | $data = new Channel\Contracts\Message_Data(); 139 | $data->setMessage($message); 140 | $data->setSeverityLevel($severityLevel); 141 | 142 | if ($properties != NULL) 143 | { 144 | $data->setProperties($properties); 145 | } 146 | 147 | $this->_channel->addToQueue($data, $this->_context); 148 | } 149 | 150 | /** 151 | * Sends a Request_Data to the Application Insights service. 152 | * @param string $name A friendly name of the request. 153 | * @param string $url The url of the request. 154 | * @param int $startTime The timestamp at which the request started. 155 | * @param int $durationInMilliseconds The duration, in milliseconds, of the request. 156 | * @param int $httpResponseCode The response code of the request. 157 | * @param bool $isSuccessful Whether or not the request was successful. 158 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 159 | * @param array $measurements An array of name to double pairs. Use the name as the index and any double as the value. 160 | */ 161 | public function trackRequest($name, $url, $startTime, $durationInMilliseconds = 0, $httpResponseCode = 200, $isSuccessful = true, $properties = NULL, $measurements = NULL ) 162 | { 163 | $this->endRequest($this->beginRequest($name, $url, $startTime), $durationInMilliseconds, $httpResponseCode, $isSuccessful, $properties, $measurements ); 164 | } 165 | 166 | /** 167 | * Begin a Request_Data to the Application Insights service. This request is not sent until an @see endRequest call is made, passing this request. 168 | * 169 | * @param string $name A friendly name of the request. 170 | * @param string $url The url of the request. 171 | * @param int $startTime The timestamp at which the request started. 172 | * @return \ApplicationInsights\Channel\Contracts\Request_Data an initialized Request_Data, which can be sent by using @see endRequest 173 | */ 174 | public function beginRequest($name, $url, $startTime ) 175 | { 176 | $data = new Channel\Contracts\Request_Data(); 177 | $guid = \ApplicationInsights\Channel\Contracts\Utils::returnGuid(); 178 | $data->setId($guid); 179 | $data->setName($name); 180 | $data->setUrl($url); 181 | $data->setTime($startTime); 182 | 183 | return $data; 184 | } 185 | 186 | /** 187 | * Sends a Request_Data created by @see beginRequest to the Application Insights service. 188 | * @param int $durationInMilliseconds The duration, in milliseconds, of the request. 189 | * @param int $httpResponseCode The response code of the request. 190 | * @param bool $isSuccessful Whether or not the request was successful. 191 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 192 | * @param array $measurements An array of name to double pairs. Use the name as the index and any double as the value. 193 | */ 194 | public function endRequest( Channel\Contracts\Request_Data $request, $durationInMilliseconds = 0, $httpResponseCode = 200, $isSuccessful = true, $properties = NULL, $measurements = NULL ) 195 | { 196 | $request->setResponseCode($httpResponseCode); 197 | $request->setSuccess($isSuccessful); 198 | 199 | $request->setDuration(Channel\Contracts\Utils::convertMillisecondsToTimeSpan($durationInMilliseconds)); 200 | 201 | if ($properties != NULL) 202 | { 203 | $request->setProperties($properties); 204 | } 205 | 206 | if ($measurements != NULL) 207 | { 208 | $request->setMeasurements($measurements); 209 | } 210 | 211 | $this->_channel->addToQueue($request, $this->_context); 212 | } 213 | 214 | /** 215 | * Sends an Exception_Data to the Application Insights service. 216 | * @param \Exception|\Throwable $ex The exception/throwable to send 217 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 218 | * @param array $measurements An array of name to double pairs. Use the name as the index and any double as the value. 219 | */ 220 | public function trackException($ex, $properties = NULL, $measurements = NULL) 221 | { 222 | $details = new Channel\Contracts\Exception_Details(); 223 | $details->setId(1); 224 | $details->setOuterId(0); 225 | $details->setTypeName(get_class($ex)); 226 | $details->setMessage($ex->getMessage().' in '.$ex->getFile().' on line '.$ex->getLine()); 227 | $details->setHasFullStack(true); 228 | 229 | $stackFrames = array(); 230 | 231 | // First stack frame is in the root exception 232 | $frameCounter = 0; 233 | foreach ($ex->getTrace() as $currentFrame) 234 | { 235 | $stackFrame = new Channel\Contracts\Stack_Frame(); 236 | if (array_key_exists('class', $currentFrame) == true) 237 | { 238 | $stackFrame->setAssembly($currentFrame['class']); 239 | } 240 | if (array_key_exists('file', $currentFrame) == true) 241 | { 242 | $stackFrame->setFileName($currentFrame['file']); 243 | } 244 | if (array_key_exists('line', $currentFrame) == true) 245 | { 246 | $stackFrame->setLine($currentFrame['line']); 247 | } 248 | if (array_key_exists('function', $currentFrame) == true) 249 | { 250 | $stackFrame->setMethod($currentFrame['function']); 251 | } 252 | 253 | // Make it a string to force serialization of zero 254 | $stackFrame->setLevel(''.$frameCounter); 255 | 256 | array_unshift($stackFrames, $stackFrame); 257 | $frameCounter++; 258 | } 259 | 260 | $details->setParsedStack($stackFrames); 261 | 262 | $data = new Channel\Contracts\Exception_Data(); 263 | $data->setExceptions(array($details)); 264 | 265 | if ($properties != NULL) 266 | { 267 | $data->setProperties($properties); 268 | } 269 | 270 | if ($measurements != NULL) 271 | { 272 | $data->setMeasurements($measurements); 273 | } 274 | 275 | $this->_channel->addToQueue($data, $this->_context); 276 | } 277 | 278 | /** 279 | * Sends an Dependency_Data to the Application Insights service. 280 | * @param string $name Name of the dependency. 281 | * @param string $type The Dependency type of value being sent. 282 | * @param string $commandName Command/Method of the dependency. 283 | * @param int $startTime The timestamp at which the request started. 284 | * @param int $durationInMilliseconds The duration, in milliseconds, of the request. 285 | * @param bool $isSuccessful Whether or not the request was successful. 286 | * @param int $resultCode The result code of the request. 287 | * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. 288 | */ 289 | public function trackDependency( 290 | $name, 291 | $type = "", 292 | $commandName = NULL, 293 | $startTime = NULL, 294 | $durationInMilliseconds = 0, 295 | $isSuccessful = true, 296 | $resultCode = NULL, 297 | $properties = NULL) 298 | { 299 | $data = new Channel\Contracts\Dependency_Data(); 300 | $data->setName($name); 301 | $data->setType($type); 302 | $data->setData($commandName); 303 | $data->setDuration(Channel\Contracts\Utils::convertMillisecondsToTimeSpan($durationInMilliseconds)); 304 | $data->setSuccess($isSuccessful); 305 | $data->setResultCode($resultCode); 306 | 307 | if ($properties != NULL) 308 | { 309 | $data->setProperties($properties); 310 | } 311 | 312 | $this->_channel->addToQueue($data, $this->_context, $startTime); 313 | } 314 | 315 | /** 316 | * Flushes the underlying Telemetry_Channel queue. 317 | * @param array $options - Guzzle client option overrides 318 | * @param bool $sendAsync - Send the request asynchronously 319 | * @return \GuzzleHttp\Promise\PromiseInterface|\Psr\Http\Message\ResponseInterface|null|WP_Error 320 | */ 321 | public function flush($options = array(), $sendAsync = false) 322 | { 323 | $response = $this->_channel->send($options, $sendAsync); 324 | $this->_channel->setQueue([]); 325 | return $response; 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /ApplicationInsights/Telemetry_Context.php: -------------------------------------------------------------------------------- 1 | _deviceContext = new Channel\Contracts\Device(); 75 | $this->_cloudContext = new Channel\Contracts\Cloud(); 76 | $this->_applicationContext = new Channel\Contracts\Application(); 77 | $this->_userContext = new Channel\Contracts\User(); 78 | $this->_locationContext = new Channel\Contracts\Location(); 79 | $this->_operationContext = new Channel\Contracts\Operation(); 80 | $this->_sessionContext = new Channel\Contracts\Session(); 81 | $this->_internalContext = new Channel\Contracts\Internal(); 82 | $this->_properties = array(); 83 | 84 | // Initialize user id 85 | $currentUser = new Current_User(); 86 | $this->_userContext->setId($currentUser->id); 87 | 88 | // Initialize session id 89 | $currentSession = new Current_Session(); 90 | $this->_sessionContext->setId($currentSession->id); 91 | 92 | // Initialize the operation id 93 | $operationId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid(); 94 | $this->_operationContext->setId($operationId); 95 | 96 | // Initialize client ip 97 | if (array_key_exists('REMOTE_ADDR', $_SERVER) && sizeof(explode('.', $_SERVER['REMOTE_ADDR'])) >= 4) 98 | { 99 | $this->_locationContext->setIp($_SERVER['REMOTE_ADDR']); 100 | } 101 | 102 | $this->_internalContext->setSdkVersion('php:0.4.6'); 103 | } 104 | 105 | /** 106 | * The instrumentation key for your Application Insights application. 107 | * @return string (Guid) 108 | */ 109 | public function getInstrumentationKey() 110 | { 111 | return $this->_instrumentationKey; 112 | } 113 | 114 | /** 115 | * Sets the instrumetation key on the context. This is the key for you application in Application Insights. 116 | * @param string $instrumentationKey (Guid) 117 | */ 118 | public function setInstrumentationKey($instrumentationKey) 119 | { 120 | $this->_instrumentationKey = $instrumentationKey; 121 | } 122 | 123 | /** 124 | * The device context object. Allows you to set properties that will be attached to all telemetry about the device. 125 | * @return \ApplicationInsights\Channel\Contracts\Device 126 | */ 127 | public function getDeviceContext() 128 | { 129 | return $this->_deviceContext; 130 | } 131 | 132 | /** 133 | * Sets device context object. Allows you to set properties that will be attached to all telemetry about the device. 134 | * @param \ApplicationInsights\Channel\Contracts\Device $deviceContext 135 | */ 136 | public function setDeviceContext(Channel\Contracts\Device $deviceContext) 137 | { 138 | $this->_deviceContext = $deviceContext; 139 | } 140 | 141 | /** 142 | * The cloud context object. Allows you to set properties that will be attached to all telemetry about the cloud placement of an application. 143 | * @return \ApplicationInsights\Channel\Contracts\Cloud 144 | */ 145 | public function getCloudContext() 146 | { 147 | return $this->_cloudContext; 148 | } 149 | 150 | /** 151 | * Sets cloud context object. Allows you to set properties that will be attached to all telemetry about the cloud placement of an application. 152 | * @param \ApplicationInsights\Channel\Contracts\Cloud $cloudContext 153 | */ 154 | public function setCloudContext(Channel\Contracts\Cloud $cloudContext) 155 | { 156 | $this->_cloudContext = $cloudContext; 157 | } 158 | 159 | /** 160 | * The application context object. Allows you to set properties that will be attached to all telemetry about the application. 161 | * @return \ApplicationInsights\Channel\Contracts\Application 162 | */ 163 | public function getApplicationContext() 164 | { 165 | return $this->_applicationContext; 166 | } 167 | 168 | /** 169 | * Sets application context object. Allows you to set properties that will be attached to all telemetry about the application. 170 | * @param \ApplicationInsights\Channel\Contracts\Application $applicationContext 171 | */ 172 | public function setApplicationContext(Channel\Contracts\Application $applicationContext) 173 | { 174 | $this->_applicationContext = $applicationContext; 175 | } 176 | 177 | /** 178 | * The user context object. Allows you to set properties that will be attached to all telemetry about the user. 179 | * @return \ApplicationInsights\Channel\Contracts\User 180 | */ 181 | public function getUserContext() 182 | { 183 | return $this->_userContext; 184 | } 185 | 186 | /** 187 | * Set user context object. Allows you to set properties that will be attached to all telemetry about the user. 188 | * @param \ApplicationInsights\Channel\Contracts\User $userContext 189 | */ 190 | public function setUserContext(Channel\Contracts\User $userContext) 191 | { 192 | $this->_userContext = $userContext; 193 | } 194 | 195 | /** 196 | * The location context object. Allows you to set properties that will be attached to all telemetry about the location. 197 | * @return \ApplicationInsights\Channel\Contracts\Location 198 | */ 199 | public function getLocationContext() 200 | { 201 | return $this->_locationContext; 202 | } 203 | 204 | /** 205 | * Set location context object. Allows you to set properties that will be attached to all telemetry about the location. 206 | * @param \ApplicationInsights\Channel\Contracts\Location $locationContext 207 | */ 208 | public function setLocationContext(Channel\Contracts\Location $locationContext) 209 | { 210 | $this->_locationContext = $locationContext; 211 | } 212 | 213 | /** 214 | * The operation context object. Allows you to set properties that will be attached to all telemetry about the operation. 215 | * @return \ApplicationInsights\Channel\Contracts\Operation 216 | */ 217 | public function getOperationContext() 218 | { 219 | return $this->_operationContext; 220 | } 221 | 222 | /** 223 | * Set operation context object. Allows you to set properties that will be attached to all telemetry about the operation. 224 | * @param \ApplicationInsights\Channel\Contracts\Operation $operationContext 225 | */ 226 | public function setOperationContext(Channel\Contracts\Operation $operationContext) 227 | { 228 | $this->_operationContext = $operationContext; 229 | } 230 | 231 | /** 232 | * The session context object. Allows you to set properties that will be attached to all telemetry about the session. 233 | * @return \ApplicationInsights\Channel\Contracts\Session 234 | */ 235 | public function getSessionContext() 236 | { 237 | return $this->_sessionContext; 238 | } 239 | 240 | /** 241 | * Set session context object. Allows you to set properties that will be attached to all telemetry about the session. 242 | * @param \ApplicationInsights\Channel\Contracts\Session $sessionContext 243 | */ 244 | public function setSessionContext(Channel\Contracts\Session $sessionContext) 245 | { 246 | $this->_sessionContext = $sessionContext; 247 | } 248 | 249 | /** 250 | * The session context object. Allows you to set internal details for troubleshooting. 251 | * @return \ApplicationInsights\Channel\Contracts\Internal 252 | */ 253 | public function getInternalContext() 254 | { 255 | return $this->_internalContext; 256 | } 257 | 258 | /** 259 | * Set session context object. Allows you to set internal details for troubleshooting. 260 | * @param \ApplicationInsights\Channel\Contracts\Internal $internalContext 261 | */ 262 | public function setInternalContext(Channel\Contracts\Internal $internalContext) 263 | { 264 | $this->_internalContext = $internalContext; 265 | } 266 | 267 | /** 268 | * Get the additional custom properties array. 269 | * @return array Additional properties (name/value pairs) to append as custom properties to all telemetry. 270 | */ 271 | public function getProperties() 272 | { 273 | return $this->_properties; 274 | } 275 | 276 | /** 277 | * Set the additional custom properties array. 278 | * @param array $properties Additional properties (name/value pairs) to append as custom properties to all telemetry. 279 | */ 280 | public function setProperties($properties) 281 | { 282 | $this->_properties = $properties; 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.4.6 (unreleased) 4 | 5 | TBD 6 | 7 | ## 0.4.5 8 | 9 | - Fix issue with `trackMetric` 10 | - Allow to gzip telemetry 11 | 12 | ## 0.4.4 13 | 14 | - Initialize `name` and operation id for requests telemetry. 15 | - Updated to the latest schemas. Few properties are no longer available. 16 | - Enum `Dependency_Type` and `async` argument of `TrackDependency` were removed. 17 | - New event type `Availability_Data`. 18 | - Use `Cloud` context instead of `Device` context to set role name and role 19 | instance of an application. 20 | 21 | ## 0.4.3 22 | 23 | - Support tracking Throwable and Error, not only Exceptions. 24 | - Support for internal context and override of SDK version. 25 | - Fix duration serialization for `trackPageView` call. 26 | - Do not send `User-Agent` when uploading telemetry to avoid misclassification 27 | of server telemetry as client telemetry. 28 | 29 | ## 0.4.2 30 | 31 | - Changelog started after this version. 32 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | If you're interested in contributing, take a look at the general [contributor's 4 | guide](https://github.com/Microsoft/ApplicationInsights-Home/blob/master/CONTRIBUTING.md) 5 | first. 6 | 7 | ## Build and Unit Test 8 | 9 | Unit tests uses `phpunit`. You'd need to install dependencies using composer. 10 | 11 | From the root folder: 12 | 13 | ``` sh 14 | brew install composer 15 | composer install 16 | composer selfupdate 17 | 18 | brew install phpunit 19 | phpunit -c phpunit.xml Tests/ 20 | ``` 21 | 22 | When submitting PR - make sure to include description of a change in 23 | [CHANGELOG.md](CHANGELOG.md). This will help produce release notes. 24 | 25 | ## Releasing of a new version (for maintainers only) 26 | 27 | 1. Create a release tag. Make sure tag name is incremented version from the 28 | previous release. Use [CHANGELOG.md](CHANGELOG.md) for release description. 29 | 2. [Packagist.org](https://packagist.org/packages/microsoft/application-insights) 30 | will pick up the new version from tags. 31 | 3. Bump versions in [CHANGELOG.md](CHANGELOG.md) and 32 | [Telemetry_Context.php](ApplicationInsights/Telemetry_Context.php). 33 | 34 | ## Code of conduct 35 | 36 | This project has adopted the [Microsoft Open Source Code of 37 | Conduct](https://opensource.microsoft.com/codeofconduct/). For more information 38 | see the [Code of Conduct 39 | FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact 40 | [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional 41 | questions or comments. -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ApplicationInsights-PHP 2 | 3 | Copyright (c) Microsoft Corporation 4 | 5 | All rights reserved. 6 | 7 | MIT License 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Application Insights for PHP 2 | 3 | [![Build Status](https://travis-ci.org/Microsoft/ApplicationInsights-PHP.svg?branch=master)](https://travis-ci.org/Microsoft/ApplicationInsights-PHP) 4 | [![Packagist Pre Release](https://img.shields.io/packagist/vpre/microsoft/application-insights.svg)](https://packagist.org/packages/microsoft/application-insights) 5 | 6 | This project extends the Application Insights API surface to support PHP. 7 | [Application 8 | Insights](https://azure.microsoft.com/services/application-insights/) is a 9 | service that allows developers to keep their application available, performing 10 | and succeeding. This PHP module will allow you to send telemetry of various 11 | kinds (event, trace, exception, etc.) to the Application Insights service where 12 | they can be visualized in the Azure Portal. 13 | 14 | ## Status 15 | 16 | This SDK is NOT maintained or supported by Microsoft even though we've contributed to it in the past. Note that Azure Monitor only provides support when using the [supported SDKs](https://docs.microsoft.com/en-us/azure/azure-monitor/app/platforms#unsupported-community-sdks). We’re constantly assessing opportunities to expand our support for other languages, so follow our [GitHub Announcements](https://github.com/microsoft/ApplicationInsights-Announcements/issues) page to receive the latest SDK news. 17 | 18 | ## Requirements 19 | 20 | PHP version >=5.4.2 is supported. 21 | 22 | For opening the project in Microsoft Visual Studio you will need [PHP Tools for Visual Studio](https://www.devsense.com/products/php-tools). This is not required however. 23 | 24 | ## Installation 25 | 26 | 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/). 27 | 28 | 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. 29 | 30 | ```json 31 | require: "microsoft/application-insights": "*" 32 | ``` 33 | 34 | Or you can use the composer command to automatically add the package to your composer.json file. 35 | 36 | ```json 37 | composer require microsoft/application-insights 38 | ``` 39 | 40 | Make sure you add the require statement to pull in the library: 41 | 42 | ```php 43 | require_once 'vendor/autoload.php'; 44 | ``` 45 | 46 | ## Usage 47 | 48 | Once installed, you can send telemetry to Application Insights. Here are a few samples. 49 | 50 | >**Note**: before you can send data to you will need an instrumentation key. Please see the [Getting an Application Insights Instrumentation Key](https://github.com/Microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key) section for more information. 51 | 52 | ### Initializing the client and setting the instrumentation key and other optional configurations 53 | 54 | ```php 55 | $telemetryClient = new \ApplicationInsights\Telemetry_Client(); 56 | $context = $telemetryClient->getContext(); 57 | 58 | // Necessary 59 | $context->setInstrumentationKey('YOUR INSTRUMENTATION KEY'); 60 | 61 | // Optional 62 | $context->getSessionContext()->setId(session_id()); 63 | $context->getUserContext()->setId('YOUR USER ID'); 64 | $context->getApplicationContext()->setVer('YOUR VERSION'); 65 | $context->getLocationContext()->setIp('YOUR IP'); 66 | 67 | // Start tracking 68 | $telemetryClient->trackEvent('name of your event'); 69 | $telemetryClient->flush(); 70 | ``` 71 | 72 | ### Setup Operation context 73 | 74 | For correct Application Insights reporting you need to setup Operation Context, 75 | reference to Request 76 | 77 | ```php 78 | $telemetryClient->getContext()->getOperationContext()->setId('XX'); 79 | $telemetryClient->getContext()->getOperationContext()->setName('GET Index'); 80 | ``` 81 | 82 | ### Sending a simple event telemetry item with event name 83 | 84 | ```php 85 | $telemetryClient->trackEvent('name of your event'); 86 | $telemetryClient->flush(); 87 | ``` 88 | 89 | ### Sending an event telemetry item with custom properties and measurements 90 | 91 | ```php 92 | $telemetryClient->trackEvent('name of your event', ['MyCustomProperty' => 42, 'MyCustomProperty2' => 'test'], ['duration', 42]); 93 | $telemetryClient->flush(); 94 | ``` 95 | 96 | **Sending more than one telemetry item before sending to the service is also 97 | supported; the API will batch everything until you call flush()** 98 | 99 | ```php 100 | $telemetryClient->trackEvent('name of your event'); 101 | $telemetryClient->trackEvent('name of your second event'); 102 | $telemetryClient->flush(); 103 | ``` 104 | 105 | ### Sending a simple page view telemetry item with page name and url 106 | 107 | ```php 108 | $telemetryClient->trackPageView('myPageView', 'http://www.foo.com'); 109 | $telemetryClient->flush(); 110 | ``` 111 | 112 | ### Sending a page view telemetry item with duration, custom properties and measurements 113 | 114 | ```php 115 | $telemetryClient->trackPageView('myPageView', 'http://www.foo.com', 256, ['InlineProperty' => 'test_value'], ['duration' => 42.0]); 116 | $telemetryClient->flush(); 117 | ``` 118 | 119 | ### Sending a simple metric telemetry item with metric name and value 120 | 121 | ```php 122 | $telemetryClient->trackMetric('myMetric', 42.0); 123 | $telemetryClient->flush(); 124 | ``` 125 | 126 | ### Sending a metric telemetry item with point type, count, min, max, standard deviation and measurements 127 | 128 | ```php 129 | $telemetryClient->trackMetric('myMetric', 42.0, \ApplicationInsights\Channel\Contracts\Data_Point_Type::Aggregation, 5, 0, 1, 0.2, ['InlineProperty' => 'test_value']); 130 | $telemetryClient->flush(); 131 | ``` 132 | 133 | ### Sending a simple message telemetry item with message 134 | 135 | ```php 136 | $telemetryClient->trackMessage('myMessage', \ApplicationInsights\Channel\Contracts\Message_Severity_Level::INFORMATION, ['InlineProperty' => 'test_value']); 137 | $telemetryClient->flush(); 138 | ``` 139 | 140 | **Sending a simple request telemetry item with request name, url and start 141 | time** 142 | 143 | ```php 144 | $telemetryClient->trackRequest('myRequest', 'http://foo.bar', time()); 145 | $telemetryClient->flush(); 146 | ``` 147 | 148 | ### Sending a request telemetry item with duration, http status code, whether or not the request succeeded, custom properties and measurements 149 | 150 | ```php 151 | $telemetryClient->trackRequest('myRequest', 'http://foo.bar', time(), 3754, 200, true, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); 152 | $telemetryClient->flush(); 153 | ``` 154 | 155 | ### Sending an exception telemetry, with custom properties and metrics 156 | 157 | ```php 158 | try 159 | { 160 | // Do something to throw an exception 161 | } 162 | catch (\Exception $ex) 163 | { 164 | $telemetryClient->trackException($ex, ['InlineProperty' => 'test_value'], ['duration_inner' => 42.0]); 165 | $telemetryClient->flush(); 166 | } 167 | ``` 168 | 169 | ### Set the Client to gzip the data before sending 170 | 171 | ```php 172 | $telemetryClient->getChannel()->setSendGzipped(true); 173 | ``` 174 | 175 | ### Registering an exception handler 176 | 177 | ```php 178 | class Handle_Exceptions 179 | { 180 | private $_telemetryClient; 181 | 182 | public function __construct() 183 | { 184 | $this->_telemetryClient = new \ApplicationInsights\Telemetry_Client(); 185 | $this->_telemetryClient->getContext()->setInstrumentationKey('YOUR INSTRUMENTATION KEY'); 186 | 187 | set_exception_handler(array($this, 'exceptionHandler')); 188 | } 189 | 190 | function exceptionHandler(\Exception $exception) 191 | { 192 | if ($exception != NULL) 193 | { 194 | $this->_telemetryClient->trackException($exception); 195 | $this->_telemetryClient->flush(); 196 | } 197 | } 198 | } 199 | ``` 200 | 201 | ### Sending a successful SQL dependency telemetry item 202 | 203 | ```php 204 | $telemetryClient->trackDependency('Query table', "SQL", 'SELECT * FROM table;', time(), 122, true); 205 | $telemetryClient->flush(); 206 | ``` 207 | 208 | ### Sending a failed HTTP dependency telemetry item 209 | 210 | ```php 211 | $telemetryClient->trackDependency('method', "HTTP", "http://example.com/api/method", time(), 324, false, 503); 212 | $telemetryClient->flush(); 213 | ``` 214 | 215 | ### Sending any other kind dependency telemetry item 216 | 217 | ```php 218 | $telemetryClient->trackDependency('Name of operation', "service", 'Arguments', time(), 23, true); 219 | $telemetryClient->flush(); 220 | ``` 221 | 222 | ### Changing the operation id (which links actions together) 223 | 224 | ```php 225 | $telemetryClient->trackMetric('interestingMetric', 10); 226 | $telemetryClient->getContext()->getOperationContext()->setId(\ApplicationInsights\Channel\Contracts\Utils::returnGuid()) 227 | $telemetryClient->trackMetric('differentOperationMetric', 11); 228 | $telemetryClient->flush(); 229 | ``` 230 | ## Code of conduct 231 | 232 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 233 | -------------------------------------------------------------------------------- /Schema/PublicSchema/AvailabilityData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | 3 | namespace AI 4 | 5 | [Description("Instances of AvailabilityData represent the result of executing an availability test.")] 6 | struct AvailabilityData 7 | : Domain 8 | { 9 | [Description("Schema version")] 10 | 10: required int32 ver = 2; 11 | 12 | [MaxStringLength("64")] 13 | [Description("Identifier of a test run. Use it to correlate steps of test run and telemetry generated by the service.")] 14 | [ActAsRequired("Renaming testRunId to id.")] 15 | 21: required string id; 16 | 17 | [MaxStringLength("1024")] 18 | [Description("Name of the test that these availability results represent.")] 19 | [ActAsRequired("Renaming testName to name.")] 20 | 41: required string name; 21 | 22 | [Description("Duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days.")] 23 | [CSType("TimeSpan")] 24 | 50: required string duration; 25 | 26 | [ActAsRequired("Renaming result to success.")] 27 | [Description("Success flag.")] 28 | 61: required bool success; 29 | 30 | [MaxStringLength("1024")] 31 | [Description("Name of the location where the test was run from.")] 32 | 70: string runLocation; 33 | 34 | [MaxStringLength("8192")] 35 | [Description("Diagnostic message for the result.")] 36 | 80: string message; 37 | 38 | [Description("Collection of custom properties.")] 39 | [MaxKeyLength("150")] 40 | [MaxValueLength("8192")] 41 | 100: map properties; 42 | 43 | [Description("Collection of custom measurements.")] 44 | [MaxKeyLength("150")] 45 | 200: map measurements; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Schema/PublicSchema/Base.bond: -------------------------------------------------------------------------------- 1 | 2 | namespace AI 3 | 4 | [Description("Data struct to contain only C section with custom fields.")] 5 | struct Base 6 | { 7 | [Name("ItemTypeName")] 8 | [Description("Name of item (B section) if any. If telemetry data is derived straight from this, this should be null.")] 9 | 10: string baseType; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Schema/PublicSchema/ContextTagKeys.bond: -------------------------------------------------------------------------------- 1 | 2 | namespace AI 3 | 4 | [ContextContract("Emit")] 5 | [PseudoType("JSMap")] 6 | struct ContextTagKeys 7 | { 8 | [Description("Application version. Information in the application context fields is always about the application that is sending the telemetry.")] 9 | [MaxStringLength("1024")] 10 | 10: string ApplicationVersion = "ai.application.ver"; 11 | 12 | [Description("Unique client device id. Computer name in most cases.")] 13 | [MaxStringLength("1024")] 14 | 100: string DeviceId = "ai.device.id"; 15 | 16 | [Description("Device locale using - pattern, following RFC 5646. Example 'en-US'.")] 17 | [MaxStringLength("64")] 18 | 115: string DeviceLocale = "ai.device.locale"; 19 | 20 | [Description("Model of the device the end user of the application is using. Used for client scenarios. If this field is empty then it is derived from the user agent.")] 21 | [MaxStringLength("256")] 22 | 120: string DeviceModel = "ai.device.model"; 23 | 24 | [Description("Client device OEM name taken from the browser.")] 25 | [MaxStringLength("256")] 26 | 130: string DeviceOEMName = "ai.device.oemName"; 27 | 28 | [Description("Operating system name and version of the device the end user of the application is using. If this field is empty then it is derived from the user agent. Example 'Windows 10 Pro 10.0.10586.0'")] 29 | [MaxStringLength("256")] 30 | 140: string DeviceOSVersion = "ai.device.osVersion"; 31 | 32 | [Description("The type of the device the end user of the application is using. Used primarily to distinguish JavaScript telemetry from server side telemetry. Examples: 'PC', 'Phone', 'Browser'. 'PC' is the default value.")] 33 | [MaxStringLength("64")] 34 | 160: string DeviceType = "ai.device.type"; 35 | 36 | [Description("The IP address of the client device. IPv4 and IPv6 are supported. Information in the location context fields is always about the end user. When telemetry is sent from a service, the location context is about the user that initiated the operation in the service.")] 37 | [MaxStringLength("46")] 38 | 200: string LocationIp = "ai.location.ip"; 39 | 40 | [Description("A unique identifier for the operation instance. The operation.id is created by either a request or a page view. All other telemetry sets this to the value for the containing request or page view. Operation.id is used for finding all the telemetry items for a specific operation instance.")] 41 | [MaxStringLength("128")] 42 | 300: string OperationId = "ai.operation.id"; 43 | 44 | [Description("The name (group) of the operation. The operation.name is created by either a request or a page view. All other telemetry items set this to the value for the containing request or page view. Operation.name is used for finding all the telemetry items for a group of operations (i.e. 'GET Home/Index').")] 45 | [MaxStringLength("1024")] 46 | 305: string OperationName = "ai.operation.name"; 47 | 48 | [Description("The unique identifier of the telemetry item's immediate parent.")] 49 | [MaxStringLength("128")] 50 | 310: string OperationParentId = "ai.operation.parentId"; 51 | 52 | [Description("Name of synthetic source. Some telemetry from the application may represent a synthetic traffic. It may be web crawler indexing the web site, site availability tests or traces from diagnostic libraries like Application Insights SDK itself.")] 53 | [MaxStringLength("1024")] 54 | 320: string OperationSyntheticSource = "ai.operation.syntheticSource"; 55 | 56 | [Description("The correlation vector is a light weight vector clock which can be used to identify and order related events across clients and services.")] 57 | [MaxStringLength("64")] 58 | 330: string OperationCorrelationVector = "ai.operation.correlationVector"; 59 | 60 | [Description("Session ID - the instance of the user's interaction with the app. Information in the session context fields is always about the end user. When telemetry is sent from a service, the session context is about the user that initiated the operation in the service.")] 61 | [MaxStringLength("64")] 62 | 400: string SessionId = "ai.session.id"; 63 | 64 | [Description("Boolean value indicating whether the session identified by ai.session.id is first for the user or not.")] 65 | [MaxStringLength("5")] 66 | [Question("Should it be marked as JSType-bool for breeze?")] 67 | 405: string SessionIsFirst = "ai.session.isFirst"; 68 | 69 | [Description("In multi-tenant applications this is the account ID or name which the user is acting with. Examples may be subscription ID for Azure portal or blog name blogging platform.")] 70 | [MaxStringLength("1024")] 71 | 505: string UserAccountId = "ai.user.accountId"; 72 | 73 | [Description("Anonymous user id. Represents the end user of the application. When telemetry is sent from a service, the user context is about the user that initiated the operation in the service.")] 74 | [MaxStringLength("128")] 75 | 515: string UserId = "ai.user.id"; 76 | 77 | [Description("Authenticated user id. The opposite of ai.user.id, this represents the user with a friendly name. Since it's PII information it is not collected by default by most SDKs.")] 78 | [MaxStringLength("1024")] 79 | 525: string UserAuthUserId = "ai.user.authUserId"; 80 | 81 | [Description("Name of the role the application is a part of. Maps directly to the role name in azure.")] 82 | [MaxStringLength("256")] 83 | 705: string CloudRole = "ai.cloud.role"; 84 | 85 | [Description("Name of the instance where the application is running. Computer name for on-premisis, instance name for Azure.")] 86 | [MaxStringLength("256")] 87 | 715: string CloudRoleInstance = "ai.cloud.roleInstance"; 88 | 89 | [Description("SDK version. See https://github.com/Microsoft/ApplicationInsights-Home/blob/master/SDK-AUTHORING.md#sdk-version-specification for information.")] 90 | [MaxStringLength("64")] 91 | 1000: string InternalSdkVersion = "ai.internal.sdkVersion"; 92 | 93 | [Description("Agent version. Used to indicate the version of StatusMonitor installed on the computer if it is used for data collection.")] 94 | [MaxStringLength("64")] 95 | 1001: string InternalAgentVersion = "ai.internal.agentVersion"; 96 | 97 | [Description("This is the node name used for billing purposes. Use it to override the standard detection of nodes.")] 98 | [MaxStringLength("256")] 99 | 1002: string InternalNodeName = "ai.internal.nodeName"; 100 | 101 | } 102 | -------------------------------------------------------------------------------- /Schema/PublicSchema/Data.bond: -------------------------------------------------------------------------------- 1 | import "Base.bond" 2 | 3 | namespace AI 4 | 5 | [Description("Data struct to contain both B and C sections.")] 6 | struct Data 7 | : Base 8 | { 9 | [Name("Item")] 10 | [Description("Container for data item (B section).")] 11 | 20: required TDomain baseData; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Schema/PublicSchema/DataPoint.bond: -------------------------------------------------------------------------------- 1 | import "DataPointType.bond" 2 | 3 | namespace AI 4 | 5 | [Description("Metric data single measurement.")] 6 | struct DataPoint 7 | { 8 | [Description("Namespace of the metric.")] 9 | [MaxStringLength("256")] 10 | 5: string ns; 11 | 12 | [Description("Name of the metric.")] 13 | [MaxStringLength("1024")] 14 | 10: required string name; 15 | 16 | [Description("Metric type. Single measurement or the aggregated value.")] 17 | 20: AI.DataPointType kind = Measurement; 18 | 19 | [Description("Single value for measurement. Sum of individual measurements for the aggregation.")] 20 | 30: required double value; 21 | 22 | [Description("Metric weight of the aggregated metric. Should not be set for a measurement.")] 23 | 40: nullable count; 24 | 25 | [Description("Minimum value of the aggregated metric. Should not be set for a measurement.")] 26 | 50: nullable min; 27 | 28 | [Description("Maximum value of the aggregated metric. Should not be set for a measurement.")] 29 | 60: nullable max; 30 | 31 | [Description("Standard deviation of the aggregated metric. Should not be set for a measurement.")] 32 | 70: nullable stdDev; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Schema/PublicSchema/DataPointType.bond: -------------------------------------------------------------------------------- 1 | namespace AI 2 | 3 | [Description("Type of the metric data measurement.")] 4 | enum DataPointType 5 | { 6 | Measurement, 7 | Aggregation, 8 | } 9 | -------------------------------------------------------------------------------- /Schema/PublicSchema/Domain.bond: -------------------------------------------------------------------------------- 1 | 2 | namespace AI 3 | 4 | [Description("The abstract common base of all domains.")] 5 | struct Domain 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /Schema/PublicSchema/Envelope.bond: -------------------------------------------------------------------------------- 1 | import "Base.bond" 2 | 3 | namespace AI 4 | 5 | [Description("System variables for a telemetry item.")] 6 | struct Envelope 7 | { 8 | [Description("Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1.")] 9 | [Name("SchemaVersion")] 10 | 10: int32 ver = 1; 11 | 12 | [Description("Type name of telemetry data item.")] 13 | [Name("DataTypeName")] 14 | [MaxStringLength("1024")] 15 | 20: required string name; 16 | 17 | [Description("Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z.")] 18 | [Name("DateTime")] 19 | [CSType("DateTimeOffset")] 20 | [JSType("Date")] 21 | [HockeyAppMinDateOffsetFromNow("2592000000")] 22 | [MinDateOffsetFromNow("172800000")] 23 | [MaxDateOffsetFromNow("7200000")] 24 | [MaxStringLength("64")] 25 | 30: required string time; 26 | 27 | [Name("SamplingRate")] 28 | [Description("Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items.")] 29 | 40: double sampleRate = 100.0; 30 | 31 | [Description("Sequence field used to track absolute order of uploaded events.")] 32 | [Name("SequenceNumber")] 33 | [MaxStringLength("64")] 34 | 50: string seq; 35 | 36 | [Description("The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive.")] 37 | [Name("InstrumentationKey")] 38 | [MaxStringLength("40")] 39 | 60: string iKey; 40 | 41 | [Name("Tags")] 42 | [TypeAlias("ContextTagKeys")] 43 | [Description("Key/value collection of context properties. See ContextTagKeys for information on available properties.")] 44 | 500: map tags; 45 | 46 | [Name("TelemetryData")] 47 | [Description("Telemetry data item.")] 48 | 999: Base data; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Schema/PublicSchema/EventData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | 3 | namespace AI 4 | 5 | [Description("Instances of Event represent structured event records that can be grouped and searched by their properties. Event data item also creates a metric of event count by name.")] 6 | struct EventData 7 | : Domain 8 | { 9 | [Description("Schema version")] 10 | 10: required int32 ver = 2; 11 | 12 | [MaxStringLength("512")] 13 | [Description("Event name. Keep it low cardinality to allow proper grouping and useful metrics.")] 14 | [Question("Why Custom Event name is shorter than Request name or dependency name?")] 15 | 20: required string name; 16 | 17 | [Description("Collection of custom properties.")] 18 | [MaxKeyLength("150")] 19 | [MaxValueLength("8192")] 20 | 100: map properties; 21 | 22 | [Description("Collection of custom measurements.")] 23 | [MaxKeyLength("150")] 24 | 200: map measurements; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Schema/PublicSchema/ExceptionData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | import "ExceptionDetails.bond" 3 | import "SeverityLevel.bond" 4 | 5 | namespace AI 6 | 7 | [Description("An instance of Exception represents a handled or unhandled exception that occurred during execution of the monitored application.")] 8 | struct ExceptionData 9 | : Domain 10 | { 11 | [Description("Schema version")] 12 | 10: required int32 ver = 2; 13 | 14 | [Description("Exception chain - list of inner exceptions.")] 15 | 50: required vector exceptions; 16 | 17 | [Description("Severity level. Mostly used to indicate exception severity level when it is reported by logging library.")] 18 | 60: nullable severityLevel; 19 | 20 | [Description("Identifier of where the exception was thrown in code. Used for exceptions grouping. Typically a combination of exception type and a function from the call stack.")] 21 | [MaxStringLength("1024")] 22 | 80: string problemId; 23 | 24 | [Description("Collection of custom properties.")] 25 | [MaxKeyLength("150")] 26 | [MaxValueLength("8192")] 27 | 100: map properties; 28 | 29 | [Description("Collection of custom measurements.")] 30 | [MaxKeyLength("150")] 31 | 200: map measurements; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Schema/PublicSchema/ExceptionDetails.bond: -------------------------------------------------------------------------------- 1 | import "StackFrame.bond" 2 | 3 | namespace AI 4 | 5 | [Description("Exception details of the exception in a chain.")] 6 | struct ExceptionDetails 7 | { 8 | [Description("In case exception is nested (outer exception contains inner one), the id and outerId properties are used to represent the nesting.")] 9 | 10: int32 id; 10 | 11 | [Description("The value of outerId is a reference to an element in ExceptionDetails that represents the outer exception")] 12 | 20: int32 outerId; 13 | 14 | [Description("Exception type name.")] 15 | [MaxStringLength("1024")] 16 | 30: required string typeName; 17 | 18 | [Description("Exception message.")] 19 | [MaxStringLength("32768")] 20 | 40: required string message; 21 | 22 | [Description("Indicates if full exception stack is provided in the exception. The stack may be trimmed, such as in the case of a StackOverflow exception.")] 23 | 50: bool hasFullStack = true; 24 | 25 | [Description("Text describing the stack. Either stack or parsedStack should have a value.")] 26 | [MaxStringLength("32768")] 27 | 60: string stack; 28 | 29 | [Description("List of stack frames. Either stack or parsedStack should have a value.")] 30 | 70: vector parsedStack; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Schema/PublicSchema/MessageData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | import "SeverityLevel.bond" 3 | 4 | namespace AI 5 | 6 | [Description("Instances of Message represent printf-like trace statements that are text-searched. Log4Net, NLog and other text-based log file entries are translated into intances of this type. The message does not have measurements.")] 7 | struct MessageData 8 | : Domain 9 | { 10 | [Description("Schema version")] 11 | 10: required int32 ver = 2; 12 | 13 | [MaxStringLength("32768")] 14 | [Description("Trace message")] 15 | 20: required string message; 16 | 17 | [Description("Trace severity level.")] 18 | 30: nullable severityLevel; 19 | 20 | [Description("Collection of custom properties.")] 21 | [MaxKeyLength("150")] 22 | [MaxValueLength("8192")] 23 | 100: map properties; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Schema/PublicSchema/MetricData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | import "DataPoint.bond" 3 | 4 | namespace AI 5 | 6 | [Description("An instance of the Metric item is a list of measurements (single data points) and/or aggregations.")] 7 | struct MetricData 8 | : Domain 9 | { 10 | [Description("Schema version")] 11 | 10: required int32 ver = 2; 12 | 13 | [Description("List of metrics. Only one metric in the list is currently supported by Application Insights storage. If multiple data points were sent only the first one will be used.")] 14 | 20: required vector metrics; 15 | 16 | [Description("Collection of custom properties.")] 17 | [MaxKeyLength("150")] 18 | [MaxValueLength("8192")] 19 | 100: map properties; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Schema/PublicSchema/PageViewData.bond: -------------------------------------------------------------------------------- 1 | import "EventData.bond" 2 | 3 | namespace AI 4 | 5 | [Description("An instance of PageView represents a generic action on a page like a button click. It is also the base type for PageView.")] 6 | [Alias("PageviewData;PageEventData")] 7 | struct PageViewData 8 | : EventData 9 | { 10 | [MaxStringLength("2048")] 11 | [Description("Request URL with all query string parameters")] 12 | 10: string url; 13 | 14 | [CSType("TimeSpan")] 15 | [Description("Request duration in format: DD.HH:MM:SS.MMMMMM. For a page view (PageViewData), this is the duration. For a page view with performance information (PageViewPerfData), this is the page load time. Must be less than 1000 days.")] 16 | 20: string duration; 17 | 18 | [MaxStringLength("128")] 19 | [Description("Identifier of a page view instance. Used for correlation between page view and other telemetry items.")] 20 | 50: string id; 21 | 22 | [MaxStringLength("2048")] 23 | [Description("Fully qualified page URI or URL of the referring page; if unknown, leave blank.")] 24 | 60: string referrerUri; 25 | } 26 | -------------------------------------------------------------------------------- /Schema/PublicSchema/PageViewPerfData.bond: -------------------------------------------------------------------------------- 1 | import "PageViewData.bond" 2 | 3 | namespace AI 4 | 5 | [Description("An instance of PageViewPerf represents: a page view with no performance data, a page view with performance data, or just the performance data of an earlier page request.")] 6 | [Alias("PageViewPerformanceData;PageviewPerformanceData")] 7 | struct PageViewPerfData 8 | : PageViewData 9 | { 10 | [Description("Performance total in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff")] 11 | [CSType("TimeSpan")] 12 | 10: string perfTotal; 13 | 14 | [Description("Network connection time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff")] 15 | [CSType("TimeSpan")] 16 | 20: string networkConnect; 17 | 18 | [Description("Sent request time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff")] 19 | [CSType("TimeSpan")] 20 | 30: string sentRequest; 21 | 22 | [Description("Received response time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff")] 23 | [CSType("TimeSpan")] 24 | 40: string receivedResponse; 25 | 26 | [Description("DOM processing time in TimeSpan 'G' (general long) format: d:hh:mm:ss.fffffff")] 27 | [CSType("TimeSpan")] 28 | 50: string domProcessing; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Schema/PublicSchema/RemoteDependencyData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | 3 | namespace AI 4 | 5 | [Description("An instance of Remote Dependency represents an interaction of the monitored component with a remote component/service like SQL or an HTTP endpoint.")] 6 | struct RemoteDependencyData 7 | : Domain 8 | { 9 | [Description("Schema version")] 10 | 10: required int32 ver = 2; 11 | 12 | [MaxStringLength("1024")] 13 | [Description("Name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template.")] 14 | 20: required string name; 15 | 16 | [MaxStringLength("128")] 17 | [Description("Identifier of a dependency call instance. Used for correlation with the request telemetry item corresponding to this dependency call.")] 18 | 30: string id; 19 | 20 | [MaxStringLength("1024")] 21 | [Description("Result code of a dependency call. Examples are SQL error code and HTTP status code.")] 22 | 40: string resultCode; 23 | 24 | [CSType("TimeSpan")] 25 | [Description("Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days.")] 26 | [ActAsRequired("Renaming value to duration.")] 27 | 61: required string duration; 28 | 29 | [Description("Indication of successfull or unsuccessfull call.")] 30 | 120: nullable success = true; 31 | 32 | [MaxStringLength("8192")] 33 | [Description("Command initiated by this dependency call. Examples are SQL statement and HTTP URL's with all query parameters.")] 34 | 151: string data; 35 | 36 | [MaxStringLength("1024")] 37 | [Description("Dependency type name. Very low cardinality value for logical grouping of dependencies and interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP.")] 38 | 162: string type; 39 | 40 | [MaxStringLength("1024")] 41 | [Description("Target site of a dependency call. Examples are server name, host address.")] 42 | 161: string target; 43 | 44 | [Description("Collection of custom properties.")] 45 | [MaxKeyLength("150")] 46 | [MaxValueLength("8192")] 47 | 200: map properties; 48 | 49 | [Description("Collection of custom measurements.")] 50 | [MaxKeyLength("150")] 51 | 300: map measurements; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Schema/PublicSchema/RequestData.bond: -------------------------------------------------------------------------------- 1 | import "Domain.bond" 2 | 3 | namespace AI 4 | 5 | [Description("An instance of Request represents completion of an external request to the application to do work and contains a summary of that request execution and the results.")] 6 | struct RequestData 7 | : Domain 8 | { 9 | [Description("Schema version")] 10 | 10: required int32 ver = 2; 11 | 12 | [MaxStringLength("128")] 13 | [Description("Identifier of a request call instance. Used for correlation between request and other telemetry items.")] 14 | 20: required string id; 15 | 16 | [CSType("TimeSpan")] 17 | [Description("Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days.")] 18 | 50: required string duration; 19 | 20 | [MaxStringLength("1024")] 21 | [Description("Result of a request execution. HTTP status code for HTTP requests.")] 22 | 60: required string responseCode; 23 | 24 | [Description("Indication of successfull or unsuccessfull call.")] 25 | 70: required bool success; 26 | 27 | [MaxStringLength("1024")] 28 | [Description("Source of the request. Examples are the instrumentation key of the caller or the ip address of the caller.")] 29 | 29: string source; 30 | 31 | [MaxStringLength("1024")] 32 | [Description("Name of the request. Represents code path taken to process request. Low cardinality value to allow better grouping of requests. For HTTP requests it represents the HTTP method and URL path template like 'GET /values/{id}'.")] 33 | 30: string name; 34 | 35 | [MaxStringLength("2048")] 36 | [Description("Request URL with all query string parameters.")] 37 | 90: string url; 38 | 39 | [Description("Collection of custom properties.")] 40 | [MaxKeyLength("150")] 41 | [MaxValueLength("8192")] 42 | 100: map properties; 43 | 44 | [Description("Collection of custom measurements.")] 45 | [MaxKeyLength("150")] 46 | 200: map measurements; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Schema/PublicSchema/SeverityLevel.bond: -------------------------------------------------------------------------------- 1 | namespace AI 2 | 3 | [Description("Defines the level of severity for the event.")] 4 | enum SeverityLevel 5 | { 6 | Verbose, 7 | Information, 8 | Warning, 9 | Error, 10 | Critical, 11 | } 12 | -------------------------------------------------------------------------------- /Schema/PublicSchema/StackFrame.bond: -------------------------------------------------------------------------------- 1 | 2 | namespace AI 3 | 4 | [Description("Stack frame information.")] 5 | struct StackFrame 6 | { 7 | [Description("Level in the call stack. For the long stacks SDK may not report every function in a call stack.")] 8 | 10: required int32 level; 9 | 10 | [Description("Method name.")] 11 | [MaxStringLength("1024")] 12 | 20: required string method; 13 | 14 | [Description("Name of the assembly (dll, jar, etc.) containing this function.")] 15 | [MaxStringLength("1024")] 16 | 30: string assembly; 17 | 18 | [Description("File name or URL of the method implementation.")] 19 | [MaxStringLength("1024")] 20 | 50: string fileName; 21 | 22 | [Description("Line number of the code implementation.")] 23 | 60: int32 line; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Schema/generateSchema.ps1: -------------------------------------------------------------------------------- 1 | $generatorPath = "C:\src\mseng\AppInsights-Common" 2 | $publicSchemaLocation = "https://raw.githubusercontent.com/Microsoft/ApplicationInsights-Home/master/EndpointSpecs/Schemas/Bond" 3 | $currentDir = $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 4 | $schemasPath = "$currentDir\PublicSchema" 5 | 6 | #fix path 7 | $generatorPath = "$generatorPath\..\bin\Debug\BondSchemaGenerator\BondSchemaGenerator" 8 | 9 | 10 | ##################################################################### 11 | ## PUBLIC SCHEMA 12 | ##################################################################### 13 | mkdir -Force $schemasPath 14 | 15 | function RegExReplace([string]$fileName, [string]$regex, [string]$replacement="") 16 | { 17 | $content = Get-Content $fileName 18 | $content = $content -creplace $regex,$replacement 19 | $content | Set-Content $fileName 20 | } 21 | 22 | # Download public schema from the github 23 | @( 24 | "AvailabilityData.bond", 25 | "Base.bond", 26 | "ContextTagKeys.bond", 27 | "Data.bond", 28 | "DataPoint.bond", 29 | "DataPointType.bond", 30 | "Domain.bond", 31 | "Envelope.bond", 32 | "EventData.bond", 33 | "ExceptionData.bond", 34 | "ExceptionDetails.bond", 35 | "MessageData.bond", 36 | "MetricData.bond", 37 | "PageViewData.bond", 38 | "PageViewPerfData.bond", 39 | "RemoteDependencyData.bond", 40 | "RequestData.bond", 41 | "SeverityLevel.bond", 42 | "StackFrame.bond" 43 | ) | ForEach-Object { 44 | $fileName = $_ 45 | & Invoke-WebRequest -o "$currentDir\PublicSchema\$fileName" "$publicSchemaLocation/$fileName" 46 | RegExReplace "$currentDir\PublicSchema\$fileName" "`n" "`r`n" 47 | } 48 | 49 | # Generate public schema using bond generator 50 | & "$generatorPath\BondSchemaGenerator.exe" -v -i "$schemasPath\AvailabilityData.bond" -i "$schemasPath\Base.bond" -i "$schemasPath\ContextTagKeys.bond" -i "$schemasPath\Data.bond" -i "$schemasPath\DataPoint.bond" -i "$schemasPath\DataPointType.bond" -i "$schemasPath\Domain.bond" -i "$schemasPath\Envelope.bond" -i "$schemasPath\EventData.bond" -i "$schemasPath\ExceptionData.bond" -i "$schemasPath\ExceptionDetails.bond" -i "$schemasPath\MessageData.bond" -i "$schemasPath\MetricData.bond" -i "$schemasPath\PageViewData.bond" -i "$schemasPath\PageViewPerfData.bond" -i "$schemasPath\RemoteDependencyData.bond" -i "$schemasPath\RequestData.bond" -i "$schemasPath\SeverityLevel.bond" -i "$schemasPath\StackFrame.bond" -o "$currentDir\..\" -e PHPProductLanguage -t PHPProductLayout 51 | 52 | 53 | #-v -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\AvailabilityData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\Base.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\ContextTagKeys.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\Data.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\DataPoint.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\DataPointType.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\Domain.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\Envelope.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\EventData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\ExceptionData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\ExceptionDetails.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\MessageData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\MetricData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\PageViewData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\PageViewPerfData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\RemoteDependencyData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\RequestData.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\SeverityLevel.bond" -i "C:\src\github\ApplicationInsights\php\Schema\PublicSchema\StackFrame.bond" -o "C:\src\github\ApplicationInsights\php\" -e PHPProductLanguage -t PHPProductLayout 54 | 55 | -------------------------------------------------------------------------------- /Tests/Bootstrap.php: -------------------------------------------------------------------------------- 1 | assertEquals(Utils::convertMillisecondsToTimeSpan(0), "00:00:00.000"); 14 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(1), "00:00:00.001", "milliseconds digit 1"); 15 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(10), "00:00:00.010", "milliseconds digit 2"); 16 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(100), "00:00:00.100", "milliseconds digit 3"); 17 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(1 * 1000), "00:00:01.000", "seconds digit 1"); 18 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(10 * 1000), "00:00:10.000", "seconds digit 2"); 19 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(1 * 60 * 1000), "00:01:00.000", "minutes digit 1"); 20 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(10 * 60 * 1000), "00:10:00.000", "minutes digit 2"); 21 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(1 * 60 * 60 * 1000), "01:00:00.000", "hours digit 1"); 22 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(10 * 60 * 60 * 1000), "10:00:00.000", "hours digit 2"); 23 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(24 * 60 * 60 * 1000), "00:00:00.000", "hours overflow"); 24 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(11 * 3600000 + 11 * 60000 + 11111), "11:11:11.111", "all digits"); 25 | 26 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(""), "00:00:00.000", "invalid input"); 27 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan("'"), "00:00:00.000", "invalid input"); 28 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(NULL), "00:00:00.000", "invalid input"); 29 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan([]), "00:00:00.000", "invalid input"); 30 | $this->assertEquals(Utils::convertMillisecondsToTimeSpan(-1), "00:00:00.000", "invalid input"); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tests/Channel/Telemetry_Channel_Test.php: -------------------------------------------------------------------------------- 1 | assertEquals($telemetryChannel->getEndpointUrl(), 'https://dc.services.visualstudio.com/v2/track', 'Default Endpoint URL is incorrect.'); 15 | $this->assertEquals($telemetryChannel->getQueue(), [], 'Queue should be empty by default.'); 16 | } 17 | 18 | public function testEndpointUrl() 19 | { 20 | $telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel(); 21 | $telemetryChannel->setEndpointUrl('http://foo.com'); 22 | $this->assertEquals($telemetryChannel->getEndpointUrl(), 'http://foo.com'); 23 | } 24 | 25 | public function testQueue() 26 | { 27 | $telemetryChannel = new \ApplicationInsights\Channel\Telemetry_Channel(); 28 | $telemetryChannel->setQueue([42, 42, 42]); 29 | $this->assertEquals($telemetryChannel->getQueue(), [42, 42, 42]); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/Current_Session_Test.php: -------------------------------------------------------------------------------- 1 | sessionId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid(); 18 | $this->sessionCreatedTime = time(); 19 | $this->sessionLastRenewedTime = time() - 10000; 20 | Utils::setSessionCookie($this->sessionId, $this->sessionCreatedTime, $this->sessionLastRenewedTime); 21 | } 22 | 23 | protected function tearDown() 24 | { 25 | Utils::clearSessionCookie(); 26 | } 27 | 28 | /** 29 | * Verifies the object is constructed properly. 30 | */ 31 | public function testConstructor() 32 | { 33 | $currentSession = new \ApplicationInsights\Current_Session(); 34 | 35 | $this->assertEquals($currentSession->id, $this->sessionId); 36 | $this->assertEquals($currentSession->sessionCreated, $this->sessionCreatedTime); 37 | $this->assertEquals($currentSession->sessionLastRenewed, $this->sessionLastRenewedTime); 38 | } 39 | 40 | /** 41 | * Verifies the object is constructed properly. 42 | */ 43 | public function testConstructorWithNoCookie() 44 | { 45 | Utils::clearSessionCookie(); 46 | $currentSession = new \ApplicationInsights\Current_Session(); 47 | 48 | $this->assertEquals($currentSession->id, NULL); 49 | $this->assertEquals($currentSession->sessionCreated, NULL); 50 | $this->assertEquals($currentSession->sessionLastRenewed, NULL); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Tests/Current_User_Test.php: -------------------------------------------------------------------------------- 1 | userId = \ApplicationInsights\Channel\Contracts\Utils::returnGuid(); 16 | Utils::setUserCookie($this->userId); 17 | } 18 | 19 | protected function tearDown() 20 | { 21 | Utils::clearUserCookie(); 22 | } 23 | 24 | /** 25 | * Verifies the object is constructed properly. 26 | */ 27 | public function testConstructor() 28 | { 29 | $currentUser = new \ApplicationInsights\Current_User(); 30 | 31 | $this->assertEquals($currentUser->id, $this->userId); 32 | } 33 | 34 | /** 35 | * Verifies the object is constructed properly. 36 | */ 37 | public function testConstructorWithNoCookie() 38 | { 39 | Utils::clearUserCookie(); 40 | $currentUser = new \ApplicationInsights\Current_User(); 41 | 42 | $this->assertTrue($currentUser->id != NULL && $currentUser->id != $this->userId); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Tests/Telemetry_Context_Test.php: -------------------------------------------------------------------------------- 1 | setInstrumentationKey($instrumentationKey); 16 | $this->assertEquals($instrumentationKey, $telemetryContext->getInstrumentationKey()); 17 | } 18 | 19 | public function testDeviceContext() 20 | { 21 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 22 | $context = $telemetryContext->getDeviceContext(); 23 | $this->assertEquals($context, new \ApplicationInsights\Channel\Contracts\Device()); 24 | $telemetryContext->setDeviceContext(Utils::getSampleDeviceContext()); 25 | $context = $telemetryContext->getDeviceContext(); 26 | $this->assertEquals($context, Utils::getSampleDeviceContext()); 27 | } 28 | 29 | public function testCloudContext() 30 | { 31 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 32 | $context = $telemetryContext->getCloudContext(); 33 | $this->assertEquals($context, new \ApplicationInsights\Channel\Contracts\Cloud()); 34 | $telemetryContext->setCloudContext(Utils::getSampleCloudContext()); 35 | $context = $telemetryContext->getCloudContext(); 36 | $this->assertEquals($context, Utils::getSampleCloudContext()); 37 | } 38 | 39 | public function testApplicationContext() 40 | { 41 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 42 | $context = $telemetryContext->getApplicationContext(); 43 | $this->assertEquals($context, new \ApplicationInsights\Channel\Contracts\Application()); 44 | $telemetryContext->setApplicationContext(Utils::getSampleApplicationContext()); 45 | $context = $telemetryContext->getApplicationContext(); 46 | $this->assertEquals($context, Utils::getSampleApplicationContext()); 47 | } 48 | 49 | public function testUserContext() 50 | { 51 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 52 | $context = $telemetryContext->getUserContext(); 53 | 54 | $defaultUserContext = new \ApplicationInsights\Channel\Contracts\User(); 55 | $currentUser = new \ApplicationInsights\Current_User(); 56 | $defaultUserContext->setId($currentUser->id); 57 | $this->assertEquals($context, $defaultUserContext); 58 | 59 | $telemetryContext->setUserContext(Utils::getSampleUserContext()); 60 | $context = $telemetryContext->getUserContext(); 61 | $this->assertEquals($context, Utils::getSampleUserContext()); 62 | } 63 | 64 | public function testLocationContext() 65 | { 66 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 67 | $context = $telemetryContext->getLocationContext(); 68 | $this->assertEquals($context, new \ApplicationInsights\Channel\Contracts\Location()); 69 | $telemetryContext->setLocationContext(Utils::getSampleLocationContext()); 70 | $context = $telemetryContext->getLocationContext(); 71 | $this->assertEquals($context, Utils::getSampleLocationContext()); 72 | } 73 | 74 | public function testOperationContext() 75 | { 76 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 77 | $context = $telemetryContext->getOperationContext(); 78 | $this->assertNotEmpty($context->getId()); 79 | $telemetryContext->setOperationContext(Utils::getSampleOperationContext()); 80 | $context = $telemetryContext->getOperationContext(); 81 | $this->assertEquals($context, Utils::getSampleOperationContext()); 82 | } 83 | 84 | public function testSessionContext() 85 | { 86 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 87 | $context = $telemetryContext->getSessionContext(); 88 | 89 | $defaultSessionContext = new \ApplicationInsights\Channel\Contracts\Session(); 90 | $currentSession = new \ApplicationInsights\Current_Session(); 91 | $defaultSessionContext->setId($currentSession->id); 92 | $this->assertEquals($context, $defaultSessionContext); 93 | 94 | $telemetryContext->setSessionContext(Utils::getSampleSessionContext()); 95 | $context = $telemetryContext->getSessionContext(); 96 | $this->assertEquals($context, Utils::getSampleSessionContext()); 97 | } 98 | 99 | public function testProperties() 100 | { 101 | $telemetryContext = new \ApplicationInsights\Telemetry_Context(); 102 | $properties = $telemetryContext->getProperties(); 103 | $this->assertEquals($properties, []); 104 | $telemetryContext->setProperties(Utils::getSampleCustomProperties()); 105 | $properties = $telemetryContext->getProperties(); 106 | $this->assertEquals($properties, Utils::getSampleCustomProperties()); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Tests/Utils.php: -------------------------------------------------------------------------------- 1 | setId('my_device_id'); 35 | $context->setLocale('EN'); 36 | $context->setModel('my_device_model'); 37 | $context->setOemName('my_device_oem_name'); 38 | $context->setOsVersion('Windows 8'); 39 | $context->setType('PC'); 40 | return $context; 41 | } 42 | 43 | /** 44 | * Gets a sample ApplicationInsights\Channel\Contracts\Cloud 45 | * @return \ApplicationInsights\Channel\Contracts\Cloud 46 | */ 47 | public static function getSampleCloudContext() 48 | { 49 | $context = new \ApplicationInsights\Channel\Contracts\Cloud(); 50 | $context->setRole('my_role_name'); 51 | $context->setRoleInstance('my_role_instance'); 52 | return $context; 53 | } 54 | 55 | /** 56 | * Gets a sample ApplicationInsights\Channel\Contracts\Application 57 | * @return \ApplicationInsights\Channel\Contracts\Application 58 | */ 59 | public static function getSampleApplicationContext() 60 | { 61 | $context = new \ApplicationInsights\Channel\Contracts\Application(); 62 | $context->setVer('1.0.0.0'); 63 | return $context; 64 | } 65 | 66 | /** 67 | * Gets a sample ApplicationInsights\Channel\Contracts\User 68 | * @return \ApplicationInsights\Channel\Contracts\User 69 | */ 70 | public static function getSampleUserContext() 71 | { 72 | $context = new \ApplicationInsights\Channel\Contracts\User(); 73 | $context->setId('my_user_id'); 74 | $context->setAccountId('my_account_id'); 75 | return $context; 76 | } 77 | 78 | /** 79 | * Gets a sample ApplicationInsights\Channel\Contracts\Location 80 | * @return \ApplicationInsights\Channel\Contracts\Location 81 | */ 82 | public static function getSampleLocationContext() 83 | { 84 | $context = new \ApplicationInsights\Channel\Contracts\Location(); 85 | $context->setIp("127.0.0.0"); 86 | return $context; 87 | } 88 | 89 | /** 90 | * Gets a sample ApplicationInsights\Channel\Contracts\Operation 91 | * @return \ApplicationInsights\Channel\Contracts\Operation 92 | */ 93 | public static function getSampleOperationContext() 94 | { 95 | $context = new \ApplicationInsights\Channel\Contracts\Operation(); 96 | $context->setId('my_operation_id'); 97 | $context->setName('my_operation_name'); 98 | $context->setParentId('my_operation_parent_id'); 99 | return $context; 100 | } 101 | 102 | /** 103 | * Gets a sample ApplicationInsights\Channel\Contracts\Session 104 | * @return \ApplicationInsights\Channel\Contracts\Session 105 | */ 106 | public static function getSampleSessionContext() 107 | { 108 | $context = new \ApplicationInsights\Channel\Contracts\Session(); 109 | $context->setId('my_session_id'); 110 | $context->setIsFirst(false); 111 | return $context; 112 | } 113 | 114 | /** 115 | * Gets a sample custom property array. 116 | * @return array 117 | */ 118 | public static function getSampleCustomProperties() 119 | { 120 | return ['MyCustomProperty' => 42, 'MyCustomProperty2' => 'test']; 121 | } 122 | 123 | /** 124 | * Used for testing exception related code 125 | */ 126 | public static function throwNestedException($depth = 0) 127 | { 128 | if ($depth <= 0) 129 | { 130 | throw new \Exception("testException"); 131 | } 132 | 133 | Utils::throwNestedException($depth - 1); 134 | } 135 | 136 | /** 137 | * Used for testing error related code 138 | */ 139 | public static function throwError() 140 | { 141 | eval('sdklafjha asdlkja asdaksd al'); 142 | } 143 | 144 | /** 145 | * Creates user cookie for testing. 146 | */ 147 | public static function setUserCookie($userId = NULL) 148 | { 149 | $_COOKIE['ai_user'] = $userId == NULL ? \ApplicationInsights\Channel\Contracts\Utils::returnGuid() : $userId; 150 | } 151 | 152 | /** 153 | * Clears the user cookie. 154 | */ 155 | public static function clearUserCookie() 156 | { 157 | $_COOKIE['ai_user'] = NULL; 158 | } 159 | 160 | /** 161 | * Creates session cookie for testing. 162 | */ 163 | public static function setSessionCookie($sessionId = NULL, $sessionCreatedDate = NULL, $lastRenewedDate = NULL) 164 | { 165 | $sessionId = $sessionId == NULL ? \ApplicationInsights\Channel\Contracts\Utils::returnGuid() : $sessionId; 166 | 167 | $sessionCreatedDate == NULL ? $sessionCreatedDate = time() : $sessionCreatedDate; 168 | $lastRenewedDate == NULL ? $lastRenewedDate = time() : $lastRenewedDate; 169 | 170 | $_COOKIE['ai_session'] = $sessionId.'|'.\ApplicationInsights\Channel\Contracts\Utils::returnISOStringForTime($sessionCreatedDate).'|'.\ApplicationInsights\Channel\Contracts\Utils::returnISOStringForTime($lastRenewedDate); 171 | } 172 | 173 | /** 174 | * Clears the user cookie. 175 | */ 176 | public static function clearSessionCookie() 177 | { 178 | $_COOKIE['ai_session'] = NULL; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "microsoft/application-insights", 3 | "description": "This project extends the Application Insights API surface to support PHP.", 4 | "type": "library", 5 | "keywords": ["log","logging","telemetry","insights","monitoring"], 6 | "homepage": "https://github.com/Microsoft/ApplicationInsights-PHP", 7 | "license": "MIT", 8 | "require": { 9 | "php": ">=5.4.0", 10 | "guzzlehttp/guzzle": ">=5.0 <=6.3.3" 11 | }, 12 | "require-dev": { 13 | "phpunit/phpunit": "~4.8.36", 14 | "evert/phpdoc-md" : "~0.0.7" 15 | }, 16 | "autoload": { 17 | "psr-4": { 18 | "ApplicationInsights\\": "ApplicationInsights/" 19 | } 20 | }, 21 | "autoload-dev": { 22 | "psr-4": { 23 | "ApplicationInsights\\Tests\\": "Tests/" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /phpdoc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | data/output 5 | 6 | 7 | data/output 8 | 9 | 10 |