Reputation: 2835
I'm experimenting with AppInsights and use the following code: (fetch fails with a 500 reply)
private callMethod(): void {
this._callMethodInternal();
}
private async _callMethodInternal(): Promise<void> {
try {
await fetch("https://localhost:44369/api/values", {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "text/json"
}
});
} catch (err) {
AppInsights.trackException(err);
throw err;
}
}
The exception is shown in Application Insights, but the "Failed method" property shows "Unknown" as value. Is there a way to show the correct method name?
Thanks
(https://github.com/Microsoft/ApplicationInsights-JS/issues/680)
Upvotes: 2
Views: 3600
Reputation: 35
The type of object expected by trackException
is IExceptionTelemtry
rather than a native Error
object. In other words, you can't pass the caught error directly to trackException
.
The API reference outlines all of the IExceptionTelemtry
properties, but the most important is the exception
property, as it is required.
Example:
try {
// logic that throws
} catch (error) {
AppInsights.trackException({ exception: error });
}
Upvotes: 1
Reputation: 21
you are not passing proper params. Follwoing is the updated method
trackException(exception: Error, handledAt?: string, properties?: {[string]:string}, measurements?: {[string]:number}, severityLevel?: AI.SeverityLevel)
For reference, check following link https://github.com/microsoft/ApplicationInsights-JS/blob/master/API-reference.md
Upvotes: 1