Jon List
Jon List

Reputation: 1512

Use trace data as metric in Application Insights

Is it possible to mark data from a trace as being a metric?

E.g. if i have a trace with a JSON message, would I be able to mark a field in the JSON document as a metric.

Does it even make sense doing so, or are there better alternatives? I just want to be able to track/graph and receive alerts on the field in the JSON document.

Upvotes: 0

Views: 345

Answers (1)

John Gardner
John Gardner

Reputation: 25136

The closest thing i can think of would be to parse out the metric part of your json document, and actually send it as a metric in your trace call?

string theMessage = whatever;
// .. code to parse apart the message, find the json, and grab metric values
// and put them into a dictionary<string,double>
// and any other string values into a dictionary<string,string>
telemetryClient.TrackTrace( theMessage,    
    optionalDictionaryOfStringToStringProperties,    
    optionalDictionaryOfStringToDoubleMetricValues );

there's no "automatic" way to do what you want, having the backend parse out values from a trace that contains json.

However, you could parse those values back out in a query if you're using the analytics portal. the query language there lets you do string manipulations, parsing, json parsing, etc. so if you just need it downstream for some kind of analysis, you don't need to do any of that, just do it in the query.

Upvotes: 1

Related Questions