Skip to content

Commit

Permalink
draft eager exception capture
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Dec 12, 2023
1 parent 08bc842 commit 5a0442c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.awssdk.v1;

import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.awssdk.v2;

import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.servlet;

public class EagerThrowable extends Throwable {

private final Class<? extends Throwable> originalType;

public EagerThrowable(Throwable t) {
super(t.getMessage(), t.getCause(), false, false);
setStackTrace(t.getStackTrace());
this.originalType = t.getClass();
}

public Class<? extends Throwable> getOriginalType() {
return originalType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,18 @@ public void onAfter(Transaction<?> transaction, @Nullable Throwable exception, b
@Nullable String servletPath, @Nullable String pathInfo, @Nullable String contentTypeHeader, boolean deactivate) {
try {
// thrown the first time a JSP is invoked in order to register it
if (exception != null && "weblogic.servlet.jsp.AddToMapException".equals(exception.getClass().getName())) {
boolean ignoreTransaction = false;

if(exception != null){
Class<?> exceptionType;
if (exception instanceof EagerThrowable) {
exceptionType = ((EagerThrowable) exception).getOriginalType();
} else {
exceptionType = exception.getClass();
}
ignoreTransaction = "weblogic.servlet.jsp.AddToMapException".equals(exceptionType.getName());
}
if(ignoreTransaction){
transaction.ignoreTransaction();
} else {
doOnAfter(transaction, exception, committed, status, overrideStatusCodeOnThrowable, method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
import co.elastic.apm.agent.servlet.Constants;
import co.elastic.apm.agent.servlet.EagerThrowable;
import co.elastic.apm.agent.servlet.adapter.ServletRequestAdapter;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -63,7 +64,8 @@ public static <HttpServletRequest> void captureRequestError(ServletRequestAdapte
@Nullable HttpServletRequest request,
@Nullable Exception e) {
if (request != null && e != null) {
adapter.setAttribute(request, "co.elastic.apm.exception", e);

adapter.setAttribute(request, "co.elastic.apm.exception", new EagerThrowable(e));
}
}
}
Expand Down

0 comments on commit 5a0442c

Please sign in to comment.