• EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

사용자의 편의를 위해 제공되는 기계 번역입니다.

In the event of any inconsistency between the English version and the translated version, the English versionwill take priority. Please visit this page for more information.

문제 신고

Java 에이전트 API: 사용자 지정 콜백 구현을 사용한 오류 그룹화

New Relic Java 에이전트 API를 사용하면 Java 애플리케이션에서 사용자 지정 콜백 구현을 사용하여 사용자 지정 오류 그룹화를 설정할 수 있습니다. 이 문서는 샘플 애플리케이션에서 콜백 구현과 함께 사용자 지정 오류 그룹화를 사용하는 예를 보여줍니다.

중요

API를 사용할 때 최상의 결과를 얻으려면 최신 Java 에이전트 릴리스 가 있는지 확인하십시오.

예: 사용자 정의 오류 그룹화 콜백 구현

다음은 Java 에이전트 API를 사용하여 콜백으로 사용자 정의 오류 그룹화를 구현하고 콜백을 등록하는 샘플 애플리케이션의 예입니다.

예제 코드를 복사하여 붙여넣는 경우 명령줄에 적절한 간격을 사용해야 합니다.

package test;
import java.io.IOException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.newrelic.api.agent.ErrorGroupCallback;
import com.newrelic.api.agent.NewRelic;
public class MyServletContextListener implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// Do any cleanup if needed
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// Register the error grouping callback on application startup
NewRelic.setErrorGroupCallback(new MyErrorGrouper());
}
}
public class MyErrorGrouper implements ErrorGroupCallback {
public String generateGroupingString(ErrorData errorData) {
String clazz = errorData.getErrorClass();
String txnName = errorData.getTransactionName();
return (clazz.isEmpty() || txnName.isEmpty()) ? null : clazz + "_" + txnName;
}
}
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void processRequest(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Simulate an exception
throw new ServletException("Simulated ServletException");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
processRequest(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
processRequest(req, resp);
}
}
```
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.