从Azure Application Insights持续导出的流分析查询ParsedStack of Exception

时间:2016-02-24 08:54:19

标签: azure-application-insights azure-stream-analytics cortana-intelligence

我们有一个azure云服务,可以记录Azure Application Insights的所有例外情况。我们已经设置了连续导出azure存储表的所有例外。最重要的是,我们有Azure Stream Analytics,它从存储blob中提取数据并将其推送到Azure SQL数据库。现在,问题在于我们无法正确地将ParsedStack从异常json转换/格式化为varchar(max),以便我们可以将其插入数据库。

这是我们使用的Stream Analytics查询 -

SELECT
     CASE 
        WHEN GetArrayLength(A.basicException) > 0
            THEN GetRecordPropertyValue(GetArrayElement(A.basicException, 0), 'assembly')
            ELSE ''
    END AS ExceptionAssembly 
    ,  
     CASE 
        WHEN GetArrayLength(A.basicException) > 0
            THEN GetRecordPropertyValue(GetArrayElement(A.basicException, 0), 'exceptionType')
            ELSE ''
    END AS ExceptionType 
   ,
     CASE 
        WHEN GetArrayLength(A.basicException) > 0
            THEN GetRecordPropertyValue(GetArrayElement(A.basicException, 0), 'parsedstack')
            ELSE ''
    END AS ParsedStack   
      ,A.context.device.id as DeviceId
      ,A.context.device.type as DeviceType
      ,A.context.device.browser as Browser
      ,A.context.device.browserVersion as BrowserVersion
      ,A.context.location.country as Country
      ,A.context.location.province as Province
      ,A.context.location.city as City
    INTO
      myexceptionsoutput
    FROM myexceptionsinput A

所有值在SQL表中看起来都符合预期,但ParsedStack列的值始终为Microsoft.EventProcessing.SteamR.Sql.ValueArray

修改

添加Exception对象json(完整版很长,所以修剪得更清楚) -

"basicException": [{
        "assembly": "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
        "exceptionType": "System.ServiceModel.CommunicationObjectFaultedException",
        "outerExceptionType": "System.ServiceModel.CommunicationObjectFaultedException",
        "failedUserCodeAssembly": "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
        "exceptionGroup": "System.ServiceModel.CommunicationObjectFaultedException at lambda_method",
        "count": 1,
        "outerExceptionMessage": "The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state."
    },
    {
        "parsedStack": [{
            "method": "System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage",
            "assembly": "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
            "level": 0,
            "line": 0
        },
        {
            "method": "System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke",
            "assembly": "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
            "level": 1,
            "line": 0
        },
        {
            "method": "System.IDisposable.Dispose",
            "assembly": "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
            "level": 2,
            "line": 0
        }],
        "hasFullStack": true,
        "id": "22349146",
    }],
    "internal": {
        "data": {
            "id": "bd6f2355-ed02-4883-abb9-d8ed6ceba646",
            "documentVersion": "1.61"
        }
    }

1 个答案:

答案 0 :(得分:0)

目前,无法用ASA查询语言将数组序列化为字符串。如果您可以将解析后的堆栈提取到单个行中,则可以在下面执行

with T1 as
(
select 
  GetArrayElement(iotInput.basicException,0) HighLevelDetails,
  GetRecordPropertyValue (GetArrayElement(iotInput.basicException,1), 'parsedStack') ParsedStack,
  internal.data.id Id
from 
    iotInput 
)

 select
   T1.id,
   T1.HighLevelDetails.assembly,
   T1.HighLevelDetails.exceptionType,
   ParsedStackArray.ArrayValue.method ParsedStackMethod,
   ParsedStackArray.ArrayValue.assembly ParsedStackAssembly,
   ParsedStackArray.ArrayValue.level ParsedStackLevel,
   ParsedStackArray.ArrayValue.line ParsedStackLine
 from 
  T1
 cross apply
   GetArrayElements(T1.ParsedStack) as ParsedStackArray

基于示例事件,将高级详细信息写入表并将堆栈解析为另一个表,其中“id”作为公共字段也可能有效。