I am creating some LogError calls in my ASP.NET Core webapp on the line of
_logger.LogError(new EventId(5000,"CustomName"),"description");``
I can find this event in Application Insights by querying like this
traces | where timestamp > ago(10m) |where customDimensions.EventId == 5000
Is there any list of event ids that is reserved? I only want to get my own events. I know that a third party library that i bind to my project theoretically can write some events with the above event id, but I am thinking more if Microsoft has a list of reserved event ids. If I do this search in my log
traces | where timestamp > ago(10m) |where customDimensions.EventId > 1
I get some hits, on Azure Function startup, so I know that Microsoft are using this also.
I have searched the docs, but haven't found any list.
No, there're no reserved EventIDs in app insights. You always need to provide it by yourself.
Related
I was getting some exceptions around 60 exceptions when I run my .NET Core Application - of a particular type - Partner center exceptions.
I have dealt with those exceptions but now I am writing some KQL queries so that I come to know if anything goes wrong beforehand.
I want to write KQL query which in future catches exceptions from partner center but not that type of exception - so how to filter them out?
My Query looks like -
traces
| where customDimensions.LogLevel == "Error"
| where operation_Name == "functionName"
| where iKey != "************"
I saw this iKey - what is it? and how can I write a desired query is what I need to know.
Also :
Could not find purchase charge for customer and "errorName":"RelationshipDoesNotExist" ----> this all comes in message and also customDimensions field
Can I extract this errorName and exclude these type of exceptions? Any way to do that?
For now I have used :
where message !contains_cs "Could not find purchase charge for customer"
but it has high compute price, so looking for an alternate to optimize the query.
iKey correspondents to the instrumentation key:
When you set up Application Insights monitoring for your web app, you create an Application Insights resource in Microsoft Azure. You open this resource in the Azure portal in order to see and analyze the telemetry collected from your app. The resource is identified by an instrumentation key (ikey). When you install the Application Insights package to monitor your app, you configure it with the instrumentation key, so that it knows where to send the telemetry.
(source)
I want to write KQL query which in future catches exceptions from partner center but not that type of exception - so how to filter them out?
Exceptions are stored in the exceptions table. You can filter them based on a known property like the exception type. For example, say you want all exceptions except those of type NullReferenceException you can do something like this:
exceptions
| where ['type'] != "System.NullReferenceException"
I have around 10 microservice applications in .net, all hosted on Azure ServiceFabric.
These applications are setup in a sequence for example
API call to Application 1 > stores data in cosmos > sends message to Application 2
Application 2 > Depending on data and business logic send a message to relative department (application 3, 4, 5, etc)
Application 3 processes and stores the data in database
I want a performance metric which shows some start/end time or total time taken to perform 1 End to End cycle for a payload.
I have come through certain solutions for tihs
Log metrics in Application Insights before and after method calls
Example:
Create and use a unique Guid as correlationId
Application 1 > Method1() - Record Start Time
Application 1 > Method() - Record start and end time
Application 3 > Method2() - Record start and end time
Application 3 > Method2() - Record End Time
This is available in Insights when I search for that Guid
Even here I have a question how could I improve the visibility of this, maybe charts, reports, what options I could use in Application Insights?
Log as above but in a separate database, this way we have control on data (application insights have huge data and cant be a separate API)
Create a new API with input as Guid, the response will be seomthing like below
Total EndToEnd Time: 10seconds
Application1> Method2(): 2 seconds
...
I know there could be better options but need some direction on this please.
There are two options to do it with Application Insights. Both are not ideal at this point.
Option I. If you store all telemetry in the same resource and your app doesn't have too much load then you can group by (summarize) by CorrelationId. Here is an idea (you might want to extend it by recording start time when it comes to Application 1 and end time when it comes to Application 3):
let Source = datatable(RoleName:string, CorrelationId:string, Timestamp:datetime)
[
'Application 1', '1', '2021-04-22T05:00:45.237Z',
'Application 2', '1', '2021-04-22T05:01:45.237Z',
'Application 3', '1', '2021-04-22T05:02:45.237Z',
'Application 1', '2', '2021-04-22T05:00:45.237Z',
'Application 2', '2', '2021-04-22T05:01:46.237Z',
'Application 3', '2', '2021-04-22T05:02:47.237Z',
];
Source
| summarize min_timestamp=min(Timestamp), max_timestamp=max(Timestamp) by CorrelationId
| extend duration = max_timestamp - min_timestamp
| project CorrelationId, duration
Option II. Application Insights supports W3C standard of Distributed Tracing for HTTPS calls. If you manually propagate distributed tracing context through your message (between applications) and restore this context, then you can do the following:
In Application 1 you can put start time in a Baggage
This field will get propagated across applications [note, OperationId will also propagate]
In Application N you will know exactly when a particular request/transaction started, so you will be able to emit proper metric
My C# code is log.BeginScope("Testing Scope1"); and log.BeginScope("Testing Scope2");. How can I use in Azure Application Insights (in https://portal.azure.com)?
If your code like below:
using (_logger.BeginScope("Testing Scope1"))
{
_logger.LogInformation("this is an info from index page 111111");
}
Then, after the code is executed, nav to azure portal -> your application insights -> Logs -> in the traces table, write the following query(also note that select a proper "time range"):
traces
| where customDimensions.Scope contains "Testing Scope1"
| project message, customDimensions
The screenshot is as below:
By the way, it may take a few minutes for the logs being generated. And please also set the proper log level in your application(like set the proper log level in your azure function).
I want to search Application Insights logs by messages inside. For example, I have the following log:
I want to search all calls, when message: 'FunctionCallEfsApi no messages' consists...
How can I do it?
If you are looking inside traces or exceptions inside Application Insights, you can use following query to get all messages when message contains : 'FunctionCallEfsApi no messages'
traces | where message contains "FunctionCallEfsApi no messages"
You can navigate to Logs(Analytics) on Application Insights resource you have and write a query to fetch those information,
traces
| where message contains "FunctionCallEfsApi no messages"
I have a 3-week-old Function on the v2 SDK and uses the out-box App Insights support, i.e. just set the environment variable and ...magic.
I did read that by default it doesn't send Information level logs to AppInsights and this looks correct because I can't see any of my information tracing but I do see occasional errors I've logged out with my custom message.
But for metrics, its broken. I can see some semblance of my telemetry in the logs, sort of. It's strange.
Look.
Now look at these curious logs.
...see those n/a that match the LogMetric lines in my code?
And when I search explicitly for one of them, nothing is found.
And if I drill down on those n/a logs.
...they're pretty empty.
Is it me or is this all rather fishy?
How do I log metrics from a Function in a way that works?
First, for the metric, do you mean custom metrics? If yes, then you should find it in the customMetrics table in your app insights.
Second, what's the method are you using to send metrics? From your code, what's the implementation of this.Logger?.LogMetric method?
For sending metrics, you can use TrackMetric(just tested with this method, and works) or GetMetric method.
A sample code use TrackMetric(deprecated, but still can use) / GetMetric(recommended) method:
TelemetryConfiguration.Active.InstrumentationKey = "your key";
TelemetryClient client = new TelemetryClient();
client.TrackMetric("my metric", 60);
client.GetMetric("my metric").TrackValue(89);
client.Flush();
In my case, the settings in the host.json file were excluding the metrics from getting to Application Insights. The metrics are being logged at the Information level and I originally had mine configured for the Warning level.
"logging": {
"logLevel": {
"Function.<function name>": "Information", //<--won't see metrics if set to Warning
...
See here for more information on configuring the logging levels.