0

I am messing around with application insights in Azure and was wondering if there is a way to also log the payload that is being processed in for example the Api when logging data with application insights?

Maybe i have misunderstood the use-case of A.I.. is this even a good way to use it or am i suppose to do this kind of logging in another resource?

EDIT

So i managed to do it in some what the way i wanted it to loo like. i can now see custom values in analytics though Application Insights. I used this simple code to Create my properties and then save related values to them.

The only drawback is that the value of a specific key can only be about 100 chars or so. Which is understandable regarding the amount of data they would otherwise store... Would be nice to be able to save the whole stack trace with line numbers and such though...

var telemetry = new TelemetryClient();
...
try
{ ...
}
catch (Exception ex)
{
   // Set up some properties:
   var properties = new Dictionary <string, string>
     {{"Game", currentGame.Name}};

   var measurements = new Dictionary <string, double>
     {{"Users", currentGame.Users.Count}};

   // Send the exception telemetry:
   telemetry.TrackException(ex, properties, measurements);
}

(Code-snippet taken from Microsofts documentation: here)

My idea of solving my little problem with stack-trace is to sub-string the different snippets i want to store. Such as location and line number for example.

H4p7ic
  • 1,669
  • 2
  • 32
  • 61
  • What do you mean with 'payload'? The request body and post content? Out of the box it does not do that, it would also be costly since you also pay for the amount of data you log. – Peter Bons Jan 24 '18 at 12:47
  • Hi @PeterBons, yes "The request body" for example. Ok but is there another for doing this in conjunction with application insight? lets say an exception gets thrown in the api and its because of something like invalid data in the request body, how do i see that if not in a log? – H4p7ic Jan 24 '18 at 12:51
  • Try a custom telemetry initializer like shown [here](https://stackoverflow.com/questions/42686363/view-post-request-body-in-application-insights) – Peter Bons Jan 24 '18 at 18:22
  • @PeterBons i looked at the post you recommended and implemented it. But its says in the comments that, that solution will be deprecated soon. Is there any other way to do this. What i want to do in te end is to save and object with the payload and maybe even the error-message and stacktrace so that i can easily find them in something like log analytics. – H4p7ic Feb 12 '18 at 07:32
  • The solution as a whole is not going to be deprecated, just the RequestTelemetry.HttpMethod Property. The http method is included in the Name property, so you should get it from there. – Peter Bons Feb 12 '18 at 08:43
  • @PeterBons Ok, hmm well i will definitely check that out. But i managed to do it in another way. at least save my stack-trace and such so that i can see it in Analytics. Check out the edit. – H4p7ic Feb 12 '18 at 12:35

0 Answers0