/** * Sends an Exception_Data to the Application Insights service. * @param Exception $ex The exception to send * @param array $properties An array of name to value pairs. Use the name as the index and any string as the value. * @param array $measurements An array of name to double pairs. Use the name as the index and any double as the value. */ public function trackException(\Exception $ex, $properties = NULL, $measurements = NULL) { $details = new Channel\Contracts\Exception_Details(); $details->setId(1); $details->setOuterId(0); $details->setTypeName(get_class($ex)); $details->setMessage($ex->getMessage() . ' in ' . $ex->getFile() . ' on line ' . $ex->getLine()); $details->setHasFullStack(true); $stackFrames = array(); // First stack frame is in the root exception $frameCounter = 0; foreach ($ex->getTrace() as $currentFrame) { $stackFrame = new Channel\Contracts\Stack_Frame(); if (array_key_exists('class', $currentFrame) == true) { $stackFrame->setAssembly($currentFrame['class']); } if (array_key_exists('file', $currentFrame) == true) { $stackFrame->setFileName($currentFrame['file']); } if (array_key_exists('line', $currentFrame) == true) { $stackFrame->setLine($currentFrame['line']); } if (array_key_exists('function', $currentFrame) == true) { $stackFrame->setMethod($currentFrame['function']); } // Make it a string to force serialization of zero $stackFrame->setLevel('' . $frameCounter); array_unshift($stackFrames, $stackFrame); $frameCounter++; } $details->setParsedStack($stackFrames); $data = new Channel\Contracts\Exception_Data(); $data->setHandledAt('UserCode'); $data->setExceptions(array($details)); if ($properties != NULL) { $data->setProperties($properties); } if ($measurements != NULL) { $data->setMeasurements($measurements); } $this->_channel->addToQueue($data, $this->_context); }