2

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)

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

what params would then be needed to resolve the Method: Unknown issue?
1

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 });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.