0

我們有一個Azure雲服務,它將所有異常記錄到Azure Application Insights。我們已經設置了對azure存儲表的所有例外的連續導出。最重要的是,我們有Azure Stream Analytics,它從存儲blob中提取數據並將其推送到Azure SQL數據庫。現在,問題是我們無法從異常json轉換/格式ParsedStack到varchar(max),因此我們可以將它插入數據庫。流分析查詢Azure Application Insights的異常ParsedStack連續導出

這是我們使用的流分析查詢 -

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" 
     } 
    } 
+0

A.basicException是什麼類型,它是一個數組還是數組?我試着在下面的事件的查詢下面,它的作品。你有的查詢是相似的,它應該工作,如果A.basicException是一個數組。 事件: { 「ArrayColumn」:[{ 「ID」:255},{ 「ID」:215}], 「NormalColumn」:40 「DEVICEID」: 「D2」} ASA查詢 選擇 NormalColumn, 情況下,當getarraylength(ArrayColumn)> 0 然後GetRecordPropertyValue(getarrayelement(ArrayColumn,0), 'ID') 別的 '' 端[ID], System.Timestamp [EventTimeStamp], DEVICEID 成 tableOutput from iotInput –

+0

@Vigneshwa ranChandramohan我添加了JSON對象。這裏的BasicException是兩個對象的數組。第二個對象又有兩個對象,第二個對象是ParsedStack。當我看到ParsedStack是一個大小始終在變化的對象數組時,它變得更加複雜,這是基於異常 –

回答

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」共同字段可能也工作。

+0

的堆棧跟蹤中的行感謝您的回覆@Vigneshwaran。但是,將堆棧調用爲行並不能解決問題。我將整個對象推送到一個web作業,該作業觸發包含所有這些異常細節的電子郵件。即使我能夠以普通的JSON格式獲得它也可以。有沒有辦法做到這一點? –