Use trace data as metric in Application Insights - azure-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.

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.

Related

Kusto nested json coming as null

I am using Application Insights Log-Explorer query window to visualize the below query.
Inside the field customDimensions.RemotePC I am string a json payload.
When I try to index the stored json via propery-indexing, i get the value as null. I tried to access it as array that turns null as well.
Could you please help me to access the FirstName property in below diagram.
Try this:
| extend todynamic(tostring(rpc)).FirstName
I believe that the issue is that rpc is string (although it looks as json). Thus you need to "cast" it to dynamic. You first need to tell the compiler though that this is a string value.

Kusto's `parse_json` doesn't work on custom dimensions

I'm hoping to be able to analyze structured data stored in a custom dimension of a custom telemetry event emitted to application insights, and getting some weird behavior. It seems like the JSON can't be parsed normally, but if I pass it through strcat it is able to parse the json just fine.
customEvents
| where name == "PbConfigFilterComponentSaved"
| take 1
| project
jsonType=gettype(customDimensions.Json),
parsedType=gettype(parse_json(customDimensions.Json)),
strcatType=gettype(strcat('', customDimensions.Json)),
strcatParsedType=gettype(parse_json(strcat('', customDimensions.Json)))
Result:
jsonType: string
parsedType: string
strcatType: string
strcatParsedType: dictionary
Is there a better approach to getting parse_json to work on this kind of value?
Update
In case it's in any way relevant, here's the value of customDimensions.Json:
{"filterComponentKey":"CatalystAgeRange","typeKey":"TemporalConstraint","uiConfig":{"name":"Age","displayMode":"Age"},"config":{"dateSelector":"pat.BirthDTS"},"disabledForScenes":false,"disabledForFilters":false}
Could you please demonstrate a sample record that isn't parsed correctly?
Speculating (before seeing the data): Have you verified the final paragraph here doesn't apply to your case?
It is somewhat common to have a JSON string describing a property bag in which one of the "slots" is another JSON string. […] In such cases, it is not only necessary to invoke parse_json twice, but also to make sure that in the second call, tostring will be used. Otherwise, the second call to parse_json will simply pass-on the input to the output as-is, because its declared type is dynamic.
The type of customDimensions is dynamic and so accessing a property like customDimensions.json from it will return a string typed as dynamic.
You have to explicitly cast it as string and then parse it:
todynamic(tostring(customDimensions.json)).property
I think the "Notes" section in the documentation is exactly the issue, as mentioned by Yoni L. in the previous answer.

Get the results of a CosmosDb query as a Raw string (payload of the http response)

I'm using the .NET API of CosmosDB and I'm getting a hard time trying to figure out how to get the raw result of a CosmosDB query prior to it getting deserialized into a class. Browsing the documentation, all examples I find cast the results to an specific class or to a dynamic. That is:
//This returns a Document, wich actually is a dynamic...
client.ReadDocumentAsync(...)
//This returns an object of type MyClass, wich I supose is casted internally by the API
client.ReadDocumentAsync<MyClass>(...)
What I want to do is to get the original raw JSON payload of the result to inspect it without the overhead of deserializing it to anything else.
Does anybody know if it's possible to get the raw result with the .NET api? If so, how?
In other cases, I need to use the result as an ExpandoObject to treat it dynamically, but I find that the "dynamic" results given by the api are not "expandables" so I'm forced to serialize them and then deserialize again in a recursive form into an ExpandoObject. Furthermore, the result is polluted with _rid, Etag, etc. properties that I don't need on my object. It's quite anoying.
I think it's an unnecesary overhead to serialize and then deserialize again, so maybe the optimus way would be to get the raw JSON result and write a method to deserialize directly to Expando.
Or maybe I'm loosing any point and there's an API to get the results as Expandos. Does anybody know it?
Check out this question that I had earlier:
Converting arbitrary json response to list of "things"
Altough I didn't named it, the API in question was actually DocumentDb, so I think you'll be able to use that code.
Seen some bad advice here, but it is built into the SDK natively.
Document doc = cosmosClient.ReadDocumentAsync(yourDocLink);
string json = doc.ToString();

How to customize segment using query string or cookie in Adobe CQ5.6?

How to customize segment using query string or cookie in Adobe CQ5.6?
My requirement as follows:
I wanted to target querystring parameters in Segment which is added in my Experience, Teaser, Promotion, Voucher for owned site.
Thanks in advance.
You can define your own segment at outlined here: https://docs.adobe.com/docs/en/cq/5-6-1/administering/segmentation.html#Defining%20a%20New%20Segment
In step 6 where you edit the segment, you need to supply a JavaScript expression that will resolve to a boolean, true or false. You can put any JavaScript expression here that meets your need, so you can include script that will have a complex expression if you want. But rather than write a complex JavaScript expression here, it would be better to write JavaScript that exposes a function which returns true or false and then include that JavaScript function on your pages via a client library. Then, in the segment, you can simply invoke the function rather defined in your client library than try to write a complex expression.
As long as the JavaScript expression defined in the segment evaluates to true/false, the segment will be usable.
Without your own JavaScript you can easily fetch query string values of look at cookies. See these other questions for details on that:
What is the shortest function for reading a cookie by name in JavaScript?
How can I get query string values in JavaScript?

How to write method having many parameters in REST webservice

I need to develop a web method that has many parameters. In REST, I understand a webservice has its own significance by attaching itself to particular entity and HttpVerb determines operation type.
This webmethod cannot be associated with an entity, it just calls a stored procedure and returns data, so I assume it only has only a GET method. But it has too many parameters to be fit into a URL. So, do I need to consider using POST method instead of GET.
It wouldn't really pass as 100% true to REST but you can have one web method that you call that looks at query string part of the url to get the additional parameters.
You would have a web method with a route of '/GetData'.
domain.com/GetData?Parameters=firstParm=1^secondParm=info^thirdParm=test
then in the web method, you would check the query string for Parameters and then split the string by the '^' symbol.
or
domain.com/GetData?firstParm=1&secondParm=info&thirdParm=test
this you would have to do a query string for each parameter.

Resources