diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java index 489dff5858df..86dd16e2edad 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java @@ -2,7 +2,6 @@ import com.navercorp.pinpoint.bootstrap.context.AsyncState; import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder; import com.navercorp.pinpoint.profiler.context.storage.Storage; @@ -16,9 +15,8 @@ public AsyncDefaultTrace(Span span, Storage storage, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, - ExceptionContext exceptionContext, AsyncState asyncState) { - super(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, CloseListener.EMPTY); + super(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, CloseListener.EMPTY); this.asyncState = Objects.requireNonNull(asyncState, "asyncState"); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java index 5a554eae203b..931b61a4a3a3 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java @@ -23,7 +23,6 @@ import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; import com.navercorp.pinpoint.exception.PinpointException; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder; import com.navercorp.pinpoint.profiler.context.scope.DefaultTraceScopePool; @@ -47,8 +46,6 @@ public class ChildTrace implements Trace { private final SpanRecorder spanRecorder; private final WrappedSpanEventRecorder wrappedSpanEventRecorder; - private final ExceptionContext exceptionContext; - private boolean closed = false; // lazy initialize private DefaultTraceScopePool scopePool; @@ -58,7 +55,6 @@ public class ChildTrace implements Trace { public ChildTrace(final TraceRoot traceRoot, CallStack callStack, Storage storage, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, - ExceptionContext exceptionContext, final LocalAsyncId localAsyncId) { this.traceRoot = Objects.requireNonNull(traceRoot, "traceRoot"); @@ -67,7 +63,6 @@ public ChildTrace(final TraceRoot traceRoot, CallStack callStack, Sto this.spanRecorder = Objects.requireNonNull(spanRecorder, "spanRecorder"); this.wrappedSpanEventRecorder = Objects.requireNonNull(wrappedSpanEventRecorder, "wrappedSpanEventRecorder"); - this.exceptionContext = Objects.requireNonNull(exceptionContext, "exceptionRecordingContext"); this.localAsyncId = Objects.requireNonNull(localAsyncId, "localAsyncId"); traceBlockBegin(ASYNC_BEGIN_STACK_ID); @@ -79,7 +74,7 @@ private TraceRoot getTraceRoot() { } private SpanEventRecorder wrappedSpanEventRecorder(WrappedSpanEventRecorder wrappedSpanEventRecorder, SpanEvent spanEvent) { - wrappedSpanEventRecorder.setWrapped(spanEvent, this.exceptionContext); + wrappedSpanEventRecorder.setWrapped(spanEvent); return wrappedSpanEventRecorder; } @@ -185,7 +180,7 @@ public void close0() { } else { logSpan(); } - + this.wrappedSpanEventRecorder.close(); this.storage.close(); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java index dac2bb18ef5e..3e62b169cd30 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java @@ -25,8 +25,6 @@ import com.navercorp.pinpoint.common.annotations.InterfaceAudience; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContextFactory; import com.navercorp.pinpoint.profiler.context.id.ListenableAsyncState; import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot; import com.navercorp.pinpoint.profiler.context.id.LoggingAsyncState; @@ -61,7 +59,6 @@ public class DefaultBaseTraceFactory implements BaseTraceFactory { private final TraceRootFactory traceRootFactory; private final ActiveTraceRepository activeTraceRepository; - private final ExceptionContextFactory exceptionContextFactory; private final UriStatStorage uriStatStorage; public DefaultBaseTraceFactory(TraceRootFactory traceRootFactory, @@ -70,7 +67,6 @@ public DefaultBaseTraceFactory(TraceRootFactory traceRootFactory, TraceSampler traceSampler, SpanFactory spanFactory, RecorderFactory recorderFactory, ActiveTraceRepository activeTraceRepository, - ExceptionContextFactory exceptionContextFactory, UriStatStorage uriStatStorage) { this.traceRootFactory = Objects.requireNonNull(traceRootFactory, "traceRootFactory"); @@ -81,7 +77,6 @@ public DefaultBaseTraceFactory(TraceRootFactory traceRootFactory, this.spanFactory = Objects.requireNonNull(spanFactory, "spanFactory"); this.recorderFactory = Objects.requireNonNull(recorderFactory, "recorderFactory"); this.activeTraceRepository = Objects.requireNonNull(activeTraceRepository, "activeTraceRepository"); - this.exceptionContextFactory = Objects.requireNonNull(exceptionContextFactory, "exceptionContextFactory"); this.uriStatStorage = Objects.requireNonNull(uriStatStorage, "uriStatStorage"); } @@ -136,9 +131,8 @@ public Trace continueAsyncContextTraceObject(TraceRoot traceRoot, LocalAsyncId l final SpanRecorder spanRecorder = recorderFactory.newTraceRootSpanRecorder(traceRoot); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newChildTraceSpanEventRecorder(traceRoot); - final ExceptionContext exceptionContext = exceptionContextFactory.newExceptionContext(traceRoot); - return new ChildTrace(traceRoot, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, localAsyncId); + return new ChildTrace(traceRoot, callStack, storage, spanRecorder, wrappedSpanEventRecorder, localAsyncId); } @Override @@ -202,11 +196,10 @@ private DefaultTrace newDefaultTrace(TraceRoot traceRoot) { final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot); - final ExceptionContext exceptionContext = exceptionContextFactory.newExceptionContext(traceRoot); final ActiveTraceHandle handle = registerActiveTrace(traceRoot); final CloseListener closeListener = new DefaultCloseListener(traceRoot, handle, uriStatStorage); - return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, closeListener); + return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, closeListener); } private AsyncDefaultTrace newAsyncDefaultTrace(TraceRoot traceRoot) { @@ -221,9 +214,8 @@ private AsyncDefaultTrace newAsyncDefaultTrace(TraceRoot traceRoot) { final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot, asyncState); - final ExceptionContext exceptionContext = exceptionContextFactory.newExceptionContext(traceRoot); - return new AsyncDefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, asyncState); + return new AsyncDefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, asyncState); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java index b1f3fc109adb..9926b9cd22e6 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java @@ -23,7 +23,6 @@ import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; import com.navercorp.pinpoint.exception.PinpointException; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder; import com.navercorp.pinpoint.profiler.context.scope.DefaultTraceScopePool; @@ -50,8 +49,6 @@ public class DefaultTrace implements Trace { private final SpanRecorder spanRecorder; private final WrappedSpanEventRecorder wrappedSpanEventRecorder; - private final ExceptionContext exceptionContext; - private boolean closed = false; // lazy initialize private DefaultTraceScopePool scopePool; @@ -61,15 +58,13 @@ public class DefaultTrace implements Trace { private final CloseListener closeListener; public DefaultTrace(Span span, CallStack callStack, Storage storage, - SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, - ExceptionContext exceptionContext) { - this(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, CloseListener.EMPTY); + SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder) { + this(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, CloseListener.EMPTY); } public DefaultTrace(Span span, CallStack callStack, Storage storage, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, - ExceptionContext exceptionContext, CloseListener closeListener) { this.span = Objects.requireNonNull(span, "span"); @@ -78,7 +73,6 @@ public DefaultTrace(Span span, CallStack callStack, Storage storage, this.spanRecorder = Objects.requireNonNull(spanRecorder, "spanRecorder"); this.wrappedSpanEventRecorder = Objects.requireNonNull(wrappedSpanEventRecorder, "wrappedSpanEventRecorder"); - this.exceptionContext = Objects.requireNonNull(exceptionContext, "exceptionRecordingContext"); this.closeListener = closeListener; @@ -95,7 +89,7 @@ private TraceRoot getTraceRoot() { } private SpanEventRecorder wrappedSpanEventRecorder(WrappedSpanEventRecorder wrappedSpanEventRecorder, SpanEvent spanEvent) { - wrappedSpanEventRecorder.setWrapped(spanEvent, this.exceptionContext); + wrappedSpanEventRecorder.setWrapped(spanEvent); return wrappedSpanEventRecorder; } @@ -201,7 +195,7 @@ public void close() { logSpan(); } - this.exceptionContext.flush(); + this.wrappedSpanEventRecorder.close(); this.storage.close(); this.closeListener.close(afterTime); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java index 7de606dca5ee..037ec3921aba 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java @@ -22,8 +22,6 @@ import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionWrapperFactory; import com.navercorp.pinpoint.profiler.context.exception.sampler.ExceptionTraceSampler; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.util.Objects; @@ -32,23 +30,21 @@ */ public class DefaultExceptionRecordingService implements ExceptionRecordingService { - private final Logger logger = LogManager.getLogger(getClass()); - - private final boolean IS_DEBUG = logger.isDebugEnabled(); - private final ExceptionTraceSampler exceptionTraceSampler; private final ExceptionWrapperFactory exceptionWrapperFactory; + private final ExceptionContext exceptionContext; public DefaultExceptionRecordingService(ExceptionTraceSampler exceptionTraceSampler, - ExceptionWrapperFactory exceptionWrapperFactory + ExceptionWrapperFactory exceptionWrapperFactory, + ExceptionContext exceptionContext ) { - this.exceptionTraceSampler = exceptionTraceSampler; - this.exceptionWrapperFactory = exceptionWrapperFactory; + this.exceptionTraceSampler = Objects.requireNonNull(exceptionTraceSampler, "exceptionTraceSampler"); + this.exceptionWrapperFactory = Objects.requireNonNull(exceptionWrapperFactory, "exceptionWrapperFactory"); + this.exceptionContext = Objects.requireNonNull(exceptionContext, "exceptionContext"); } - public void recordException(ExceptionContext context, Throwable current, long startTime) { - Objects.requireNonNull(context); - + public void recordException(Throwable current, long startTime) { + final ExceptionContext context = this.exceptionContext; ExceptionRecordingState state = context.stateOf(current); ExceptionTraceSampler.SamplingState samplingState = getSamplingState(state, context); state.checkAndApply(context, current, startTime, samplingState, exceptionWrapperFactory); @@ -68,7 +64,8 @@ private ExceptionTraceSampler.SamplingState getSamplingState( return ExceptionTraceSampler.DISABLED; } - public void recordExceptionIdAnnotation(SpanEvent spanEvent, ExceptionContext context) { + public void recordExceptionIdAnnotation(SpanEvent spanEvent) { + final ExceptionContext context = this.exceptionContext; if (context.hasValidExceptionId()) { Annotation linkId = Annotations.of(AnnotationKey.EXCEPTION_CHAIN_ID.getCode(), context.getExceptionId()); spanEvent.addAnnotation(linkId); @@ -77,18 +74,18 @@ public void recordExceptionIdAnnotation(SpanEvent spanEvent, ExceptionContext co @Override public void recordException( - ExceptionContext exceptionContext, SpanEvent spanEvent, Throwable throwable ) { this.recordException( - exceptionContext, throwable, spanEvent.getStartTime() ); - this.recordExceptionIdAnnotation( - spanEvent, - exceptionContext - ); + this.recordExceptionIdAnnotation(spanEvent); + } + + @Override + public void close() { + this.exceptionContext.flush(); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java new file mode 100644 index 000000000000..35612b726110 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java @@ -0,0 +1,49 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.profiler.context.exception; + +import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; +import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContextFactory; +import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionWrapperFactory; +import com.navercorp.pinpoint.profiler.context.exception.sampler.ExceptionTraceSampler; +import com.navercorp.pinpoint.profiler.context.id.TraceRoot; + +import java.util.Objects; + +public class DefaultExceptionRecordingServiceFactory implements ExceptionRecordingServiceFactory { + + private final ExceptionTraceSampler exceptionTraceSampler; + private final ExceptionWrapperFactory exceptionWrapperFactory; + private final ExceptionContextFactory exceptionContextFactory; + + public DefaultExceptionRecordingServiceFactory(ExceptionTraceSampler exceptionTraceSampler, + ExceptionWrapperFactory exceptionWrapperFactory, + ExceptionContextFactory exceptionContextFactory) { + this.exceptionTraceSampler = Objects.requireNonNull(exceptionTraceSampler, "exceptionTraceSampler"); + this.exceptionWrapperFactory = Objects.requireNonNull(exceptionWrapperFactory, "exceptionWrapperFactory"); + this.exceptionContextFactory = Objects.requireNonNull(exceptionContextFactory, "exceptionContextFactory"); + + } + + @Override + public ExceptionRecordingService newService(TraceRoot traceRoot) { + Objects.requireNonNull(traceRoot, "traceRoot"); + ExceptionContext exceptionContext = this.exceptionContextFactory.newExceptionContext(traceRoot); + return new DefaultExceptionRecordingService(exceptionTraceSampler, exceptionWrapperFactory, exceptionContext); + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DisabledExceptionRecordingServiceFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DisabledExceptionRecordingServiceFactory.java new file mode 100644 index 000000000000..e91e31624864 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DisabledExceptionRecordingServiceFactory.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.profiler.context.exception; + +import com.navercorp.pinpoint.profiler.context.exception.disabled.DisabledExceptionRecordingService; +import com.navercorp.pinpoint.profiler.context.id.TraceRoot; + +public class DisabledExceptionRecordingServiceFactory implements ExceptionRecordingServiceFactory { + + public static final ExceptionRecordingServiceFactory INSTANCE = new DisabledExceptionRecordingServiceFactory(); + + public DisabledExceptionRecordingServiceFactory() { + } + + @Override + public ExceptionRecordingService newService(TraceRoot traceRoot) { + return DisabledExceptionRecordingService.INSTANCE; + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingService.java index 07014623f41d..ac23868b85c8 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingService.java @@ -16,12 +16,13 @@ package com.navercorp.pinpoint.profiler.context.exception; import com.navercorp.pinpoint.profiler.context.SpanEvent; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; /** * @author intr3p1d */ -public interface ExceptionRecordingService { +public interface ExceptionRecordingService extends AutoCloseable { - void recordException(ExceptionContext exceptionContext, SpanEvent spanEvent, Throwable throwable); + void recordException(SpanEvent spanEvent, Throwable throwable); + + void close(); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingServiceFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingServiceFactory.java new file mode 100644 index 000000000000..8292aaffdb83 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/ExceptionRecordingServiceFactory.java @@ -0,0 +1,26 @@ +/* + * Copyright 2023 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.profiler.context.exception; + +import com.navercorp.pinpoint.profiler.context.id.TraceRoot; + +/** + * @author intr3p1d + */ +public interface ExceptionRecordingServiceFactory { + + ExceptionRecordingService newService(TraceRoot traceRoot); +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/disabled/DisabledExceptionRecordingService.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/disabled/DisabledExceptionRecordingService.java index 6d573816ed52..53e9688e86a4 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/disabled/DisabledExceptionRecordingService.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/disabled/DisabledExceptionRecordingService.java @@ -17,17 +17,21 @@ import com.navercorp.pinpoint.profiler.context.SpanEvent; import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; /** * @author intr3p1d */ public class DisabledExceptionRecordingService implements ExceptionRecordingService { - public static final DisabledExceptionRecordingService INSTANCE = new DisabledExceptionRecordingService(); + public static final ExceptionRecordingService INSTANCE = new DisabledExceptionRecordingService(); @Override - public void recordException(ExceptionContext exceptionContext, SpanEvent spanEvent, Throwable throwable) { + public void recordException(SpanEvent spanEvent, Throwable throwable) { + + } + + @Override + public void close() { } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/model/DefaultExceptionContextFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/model/DefaultExceptionContextFactory.java index dffff103ae28..dc68d59faec1 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/model/DefaultExceptionContextFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/model/DefaultExceptionContextFactory.java @@ -34,8 +34,6 @@ public DefaultExceptionContextFactory(ExceptionStorageFactory exceptionStorageFa public ExceptionContext newExceptionContext(TraceRoot traceRoot) { ExceptionMetaDataFactory exceptionMetaDataFactory = new ExceptionMetaDataFactory(traceRoot); ExceptionStorage exceptionStorage = exceptionStorageFactory.createStorage(exceptionMetaDataFactory); - return new DefaultExceptionContext( - exceptionStorage - ); + return new DefaultExceptionContext(exceptionStorage); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DisabledExceptionTraceModule.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DisabledExceptionTraceModule.java index 7c633f514118..9d192f0ea3c2 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DisabledExceptionTraceModule.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DisabledExceptionTraceModule.java @@ -17,11 +17,11 @@ import com.google.inject.PrivateModule; import com.google.inject.Scopes; -import com.navercorp.pinpoint.profiler.context.provider.exception.DisabledExceptionContextFactoryProvider; -import com.navercorp.pinpoint.profiler.context.provider.exception.DisabledExceptionRecordingServiceProvider; -import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; +import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingServiceFactory; import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContextFactory; import com.navercorp.pinpoint.profiler.context.monitor.config.ExceptionTraceConfig; +import com.navercorp.pinpoint.profiler.context.provider.exception.DisabledExceptionContextFactoryProvider; +import com.navercorp.pinpoint.profiler.context.provider.exception.DisabledExceptionRecordingServiceFactoryProvider; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -47,7 +47,7 @@ protected void configure() { bind(ExceptionContextFactory.class).toProvider(DisabledExceptionContextFactoryProvider.class).in(Scopes.SINGLETON); expose(ExceptionContextFactory.class); - bind(ExceptionRecordingService.class).toProvider(DisabledExceptionRecordingServiceProvider.class).in(Scopes.SINGLETON); - expose(ExceptionRecordingService.class); + bind(ExceptionRecordingServiceFactory.class).toProvider(DisabledExceptionRecordingServiceFactoryProvider.class).in(Scopes.SINGLETON); + expose(ExceptionRecordingServiceFactory.class); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ExceptionTraceModule.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ExceptionTraceModule.java index e752f261e1ba..f6f214fe7599 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ExceptionTraceModule.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ExceptionTraceModule.java @@ -2,17 +2,17 @@ import com.google.inject.PrivateModule; import com.google.inject.Scopes; -import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionRecordingServiceProvider; +import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingServiceFactory; import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContextFactory; -import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionContextFactoryProvider; import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionWrapperFactory; -import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionWrapperFactoryProvider; import com.navercorp.pinpoint.profiler.context.exception.sampler.ExceptionTraceSampler; -import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionTraceSamplerProvider; import com.navercorp.pinpoint.profiler.context.exception.storage.ExceptionStorageFactory; -import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionStorageFactoryProvider; import com.navercorp.pinpoint.profiler.context.monitor.config.ExceptionTraceConfig; +import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionContextFactoryProvider; +import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionRecordingServiceFactoryProvider; +import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionStorageFactoryProvider; +import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionTraceSamplerProvider; +import com.navercorp.pinpoint.profiler.context.provider.exception.ExceptionWrapperFactoryProvider; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -39,7 +39,7 @@ protected void configure() { bind(ExceptionContextFactory.class).toProvider(ExceptionContextFactoryProvider.class).in(Scopes.SINGLETON); expose(ExceptionContextFactory.class); - bind(ExceptionRecordingService.class).toProvider(ExceptionRecordingServiceProvider.class).in(Scopes.SINGLETON); - expose(ExceptionRecordingService.class); + bind(ExceptionRecordingServiceFactory.class).toProvider(ExceptionRecordingServiceFactoryProvider.class).in(Scopes.SINGLETON); + expose(ExceptionRecordingServiceFactory.class); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/BaseTraceFactoryProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/BaseTraceFactoryProvider.java index a84dbb9d88bb..ec7ef678cff8 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/BaseTraceFactoryProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/BaseTraceFactoryProvider.java @@ -26,8 +26,6 @@ import com.navercorp.pinpoint.profiler.context.SpanEvent; import com.navercorp.pinpoint.profiler.context.SpanFactory; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContextFactory; -import com.navercorp.pinpoint.profiler.context.exception.storage.ExceptionStorageFactory; import com.navercorp.pinpoint.profiler.context.id.TraceRootFactory; import com.navercorp.pinpoint.profiler.context.recorder.RecorderFactory; import com.navercorp.pinpoint.profiler.context.storage.StorageFactory; @@ -51,7 +49,6 @@ public class BaseTraceFactoryProvider implements Provider { private final RecorderFactory recorderFactory; private final ActiveTraceRepository activeTraceRepository; - private final ExceptionContextFactory exceptionContextFactory; private final UriStatStorage uriStatStorage; @Inject @@ -62,8 +59,7 @@ public BaseTraceFactoryProvider(TraceRootFactory traceRootFactory, SpanFactory spanFactory, RecorderFactory recorderFactory, ActiveTraceRepository activeTraceRepository, - UriStatStorage uriStatStorage, - ExceptionContextFactory exceptionContextFactory) { + UriStatStorage uriStatStorage) { this.traceRootFactory = Objects.requireNonNull(traceRootFactory, "traceRootFactory"); this.callStackFactory = Objects.requireNonNull(callStackFactory, "callStackFactory"); @@ -73,14 +69,13 @@ public BaseTraceFactoryProvider(TraceRootFactory traceRootFactory, this.spanFactory = Objects.requireNonNull(spanFactory, "spanFactory"); this.recorderFactory = Objects.requireNonNull(recorderFactory, "recorderFactory"); this.activeTraceRepository = Objects.requireNonNull(activeTraceRepository, "activeTraceRepository"); - this.exceptionContextFactory = Objects.requireNonNull(exceptionContextFactory, "exceptionContextFactory"); this.uriStatStorage = Objects.requireNonNull(uriStatStorage, "uriStatStorage"); } @Override public BaseTraceFactory get() { BaseTraceFactory baseTraceFactory = new DefaultBaseTraceFactory(traceRootFactory, callStackFactory, storageFactory, traceSampler, - spanFactory, recorderFactory, activeTraceRepository, exceptionContextFactory, uriStatStorage); + spanFactory, recorderFactory, activeTraceRepository, uriStatStorage); if (isDebugEnabled()) { baseTraceFactory = LoggingBaseTraceFactory.wrap(baseTraceFactory); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/DisabledExceptionRecordingServiceProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/DisabledExceptionRecordingServiceFactoryProvider.java similarity index 67% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/DisabledExceptionRecordingServiceProvider.java rename to profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/DisabledExceptionRecordingServiceFactoryProvider.java index 8853690822a2..b23bdecfca9b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/DisabledExceptionRecordingServiceProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/DisabledExceptionRecordingServiceFactoryProvider.java @@ -17,20 +17,20 @@ import com.google.inject.Inject; import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.exception.disabled.DisabledExceptionRecordingService; +import com.navercorp.pinpoint.profiler.context.exception.DisabledExceptionRecordingServiceFactory; +import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingServiceFactory; /** * @author intr3p1d */ -public class DisabledExceptionRecordingServiceProvider implements Provider { +public class DisabledExceptionRecordingServiceFactoryProvider implements Provider { @Inject - public DisabledExceptionRecordingServiceProvider() { + public DisabledExceptionRecordingServiceFactoryProvider() { } @Override - public ExceptionRecordingService get() { - return DisabledExceptionRecordingService.INSTANCE; + public ExceptionRecordingServiceFactory get() { + return DisabledExceptionRecordingServiceFactory.INSTANCE; } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/ExceptionRecordingServiceProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/ExceptionRecordingServiceFactoryProvider.java similarity index 66% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/ExceptionRecordingServiceProvider.java rename to profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/ExceptionRecordingServiceFactoryProvider.java index 1f01d0ed3a04..7a653ceee74a 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/ExceptionRecordingServiceProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/provider/exception/ExceptionRecordingServiceFactoryProvider.java @@ -17,8 +17,9 @@ import com.google.inject.Inject; import com.google.inject.Provider; -import com.navercorp.pinpoint.profiler.context.exception.DefaultExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; +import com.navercorp.pinpoint.profiler.context.exception.DefaultExceptionRecordingServiceFactory; +import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingServiceFactory; +import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContextFactory; import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionWrapperFactory; import com.navercorp.pinpoint.profiler.context.exception.sampler.ExceptionTraceSampler; @@ -27,25 +28,29 @@ /** * @author intr3p1d */ -public class ExceptionRecordingServiceProvider implements Provider { +public class ExceptionRecordingServiceFactoryProvider implements Provider { private final ExceptionTraceSampler exceptionTraceSampler; private final ExceptionWrapperFactory exceptionWrapperFactory; + private final ExceptionContextFactory exceptionContextFactory; @Inject - public ExceptionRecordingServiceProvider( + public ExceptionRecordingServiceFactoryProvider( ExceptionTraceSampler exceptionTraceSampler, - ExceptionWrapperFactory exceptionWrapperFactory + ExceptionWrapperFactory exceptionWrapperFactory, + ExceptionContextFactory exceptionContextFactory ) { this.exceptionTraceSampler = Objects.requireNonNull(exceptionTraceSampler, "exceptionTraceSampler"); this.exceptionWrapperFactory = Objects.requireNonNull(exceptionWrapperFactory, "exceptionWrapperFactory"); + this.exceptionContextFactory = Objects.requireNonNull(exceptionContextFactory, "exceptionContextFactory"); } @Override - public ExceptionRecordingService get() { - return new DefaultExceptionRecordingService( + public ExceptionRecordingServiceFactory get() { + return new DefaultExceptionRecordingServiceFactory( exceptionTraceSampler, - exceptionWrapperFactory + exceptionWrapperFactory, + exceptionContextFactory ); } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java index f63404369485..29b794e26981 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java @@ -25,6 +25,7 @@ import com.navercorp.pinpoint.profiler.context.SqlCountService; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; +import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingServiceFactory; import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService; @@ -42,7 +43,7 @@ public class DefaultRecorderFactory implements RecorderFactory { private final Provider asyncContextFactoryProvider; private final IgnoreErrorHandler errorHandler; - private final ExceptionRecordingService exceptionRecordingService; + private final ExceptionRecordingServiceFactory exceptionRecordingServiceFactory; private final SqlCountService sqlCountService; @Inject @@ -50,13 +51,13 @@ public DefaultRecorderFactory(Provider asyncContextFactoryP StringMetaDataService stringMetaDataService, SqlMetaDataService sqlMetaDataService, IgnoreErrorHandler errorHandler, - ExceptionRecordingService exceptionRecordingService, + ExceptionRecordingServiceFactory exceptionRecordingServiceFactory, SqlCountService sqlCountService) { this.asyncContextFactoryProvider = Objects.requireNonNull(asyncContextFactoryProvider, "asyncContextFactoryProvider"); this.stringMetaDataService = Objects.requireNonNull(stringMetaDataService, "stringMetaDataService"); this.sqlMetaDataService = Objects.requireNonNull(sqlMetaDataService, "sqlMetaDataService"); this.errorHandler = Objects.requireNonNull(errorHandler, "errorHandler"); - this.exceptionRecordingService = Objects.requireNonNull(exceptionRecordingService, "exceptionRecordingService"); + this.exceptionRecordingServiceFactory = Objects.requireNonNull(exceptionRecordingServiceFactory, "exceptionRecordingServiceFactory"); this.sqlCountService = Objects.requireNonNull(sqlCountService, "sqlCountService"); } @@ -64,6 +65,7 @@ public DefaultRecorderFactory(Provider asyncContextFactoryP public SpanRecorder newSpanRecorder(Span span) { Objects.requireNonNull(span, "span"); + ExceptionRecordingService exceptionRecordingService = exceptionRecordingServiceFactory.newService(span.getTraceRoot()); return new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler, exceptionRecordingService); } @@ -86,6 +88,8 @@ public WrappedSpanEventRecorder newWrappedSpanEventRecorder(TraceRoot traceRoot) Objects.requireNonNull(traceRoot, "traceRoot"); final AsyncContextFactory asyncContextFactory = asyncContextFactoryProvider.get(); + ExceptionRecordingService exceptionRecordingService = exceptionRecordingServiceFactory.newService(traceRoot); + return new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler, exceptionRecordingService, sqlCountService); } @@ -96,6 +100,8 @@ public WrappedSpanEventRecorder newWrappedSpanEventRecorder(TraceRoot traceRoot, Objects.requireNonNull(asyncState, "asyncState"); final AsyncContextFactory asyncContextFactory = asyncContextFactoryProvider.get(); + ExceptionRecordingService exceptionRecordingService = exceptionRecordingServiceFactory.newService(traceRoot); + return new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, asyncState, stringMetaDataService, sqlMetaDataService, errorHandler, exceptionRecordingService, sqlCountService); } @@ -105,6 +111,8 @@ public WrappedSpanEventRecorder newChildTraceSpanEventRecorder(TraceRoot traceRo Objects.requireNonNull(traceRoot, "traceRoot"); final AsyncContextFactory asyncContextFactory = asyncContextFactoryProvider.get(); + ExceptionRecordingService exceptionRecordingService = exceptionRecordingServiceFactory.newService(traceRoot); + return new ChildTraceSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler, exceptionRecordingService, sqlCountService); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorder.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorder.java index f98c23d7c90f..ac04f9666645 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorder.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorder.java @@ -30,7 +30,6 @@ import com.navercorp.pinpoint.profiler.context.SqlCountService; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService; import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService; @@ -43,7 +42,7 @@ /** * @author jaehong.kim */ -public class WrappedSpanEventRecorder extends AbstractRecorder implements SpanEventRecorder { +public class WrappedSpanEventRecorder extends AbstractRecorder implements SpanEventRecorder, AutoCloseable { private static final Logger logger = LogManager.getLogger(WrappedSpanEventRecorder.class); private static final boolean isDebug = logger.isDebugEnabled(); @@ -56,8 +55,6 @@ public class WrappedSpanEventRecorder extends AbstractRecorder implements SpanEv private SpanEvent spanEvent; - private ExceptionContext exceptionContext; - public WrappedSpanEventRecorder(TraceRoot traceRoot, AsyncContextFactory asyncContextFactory, StringMetaDataService stringMetaDataService, @@ -84,9 +81,8 @@ public WrappedSpanEventRecorder(TraceRoot traceRoot, this.sqlCountService = Objects.requireNonNull(sqlCountService, "sqlCountService"); } - public void setWrapped(final SpanEvent spanEvent, ExceptionContext exceptionContext) { + public void setWrapped(final SpanEvent spanEvent) { this.spanEvent = spanEvent; - this.exceptionContext = exceptionContext; } @Override @@ -178,7 +174,7 @@ void setExceptionInfo(int exceptionClassId, String exceptionMessage) { } void recordDetailedException(Throwable throwable) { - this.exceptionRecordingService.recordException(exceptionContext, spanEvent, throwable); + this.exceptionRecordingService.recordException(spanEvent, throwable); } @Override @@ -241,4 +237,9 @@ protected AsyncId getNextAsyncId() { } return nextAsyncId; } + + @Override + public void close() { + exceptionRecordingService.close(); + } } \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java index ad113b4a3d3f..6801f3280274 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java @@ -22,8 +22,6 @@ import com.navercorp.pinpoint.profiler.context.errorhandler.BypassErrorHandler; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; import com.navercorp.pinpoint.profiler.context.exception.DefaultExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.exception.disabled.DisabledExceptionContext; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.id.Shared; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder; @@ -166,8 +164,7 @@ private Trace newTrace(final int maxCallStackDepth) { final SpanRecorder spanRecorder = new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler, exceptionRecordingService); final WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler, exceptionRecordingService, sqlCountService); - final ExceptionContext exceptionContext = DisabledExceptionContext.INSTANCE; - return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, CloseListener.EMPTY); + return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, CloseListener.EMPTY); } } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java index 52ec6780a7aa..10b1db9b062d 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java @@ -84,7 +84,7 @@ public void trace() { Storage storage = mock(Storage.class); - Trace trace = new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, CloseListener.EMPTY); + Trace trace = new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, CloseListener.EMPTY); trace.traceBlockBegin(); // get data form db @@ -115,7 +115,7 @@ public void popEventTest() { Storage storage = mock(Storage.class); - Trace trace = new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, exceptionContext, CloseListener.EMPTY); + Trace trace = new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, CloseListener.EMPTY); trace.close(); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorderTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorderTest.java index 115eb53bef83..91f90468c144 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorderTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/WrappedSpanEventRecorderTest.java @@ -22,8 +22,6 @@ import com.navercorp.pinpoint.profiler.context.errorhandler.BypassErrorHandler; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; import com.navercorp.pinpoint.profiler.context.exception.ExceptionRecordingService; -import com.navercorp.pinpoint.profiler.context.exception.disabled.DisabledExceptionContext; -import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionContext; import com.navercorp.pinpoint.profiler.context.id.Shared; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService; @@ -82,8 +80,7 @@ public void testSetExceptionInfo_RootMarkError() throws Exception { when(traceRoot.getShared()).thenReturn(shared); SpanEvent spanEvent = new SpanEvent(); - ExceptionContext exceptionContext = DisabledExceptionContext.INSTANCE; - sut.setWrapped(spanEvent, exceptionContext); + sut.setWrapped(spanEvent); final String exceptionMessage1 = "exceptionMessage1"; final Exception exception1 = new Exception(exceptionMessage1); @@ -104,8 +101,7 @@ public void testSetExceptionInfo_RootMarkError() throws Exception { @Test public void testRecordAPIId() throws Exception { SpanEvent spanEvent = new SpanEvent(); - ExceptionContext exceptionContext = DisabledExceptionContext.INSTANCE; - sut.setWrapped(spanEvent, exceptionContext); + sut.setWrapped(spanEvent); final int API_ID = 1000; diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultExceptionRecordingServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultExceptionRecordingServiceTest.java index 3095024dcd69..861125bfbed0 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultExceptionRecordingServiceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultExceptionRecordingServiceTest.java @@ -40,15 +40,17 @@ public class DefaultExceptionRecordingServiceTest { ExceptionTraceSampler exceptionTraceSampler = new ExceptionTraceSampler(1000); ExceptionWrapperFactory exceptionWrapperFactory = new ExceptionWrapperFactory(10, 1048); - DefaultExceptionRecordingService exceptionRecordingService = new DefaultExceptionRecordingService( - exceptionTraceSampler, exceptionWrapperFactory - ); + List exceptions = new ArrayList<>(); TestExceptionStorage exceptionStorage = new TestExceptionStorage(); ExceptionContext context = new DefaultExceptionContext(exceptionStorage); + DefaultExceptionRecordingService exceptionRecordingService = new DefaultExceptionRecordingService( + exceptionTraceSampler, exceptionWrapperFactory, context + ); + long START_TIME = 1; class TestExceptionStorage implements ExceptionStorage { @@ -93,14 +95,14 @@ private void resetContext() { private void record(Throwable throwable) { - exceptionRecordingService.recordException(context, throwable, START_TIME); + exceptionRecordingService.recordException(throwable, START_TIME); } @Test public void testRecordNothing() { resetContext(); - exceptionRecordingService.recordException(context, null, 0); + exceptionRecordingService.recordException(null, 0); List expected = new ArrayList<>(); List actual = exceptionStorage.getWrappers(); @@ -118,11 +120,11 @@ public void testRecordException() { level3Error(throwableFunction); } catch (Throwable e) { expected = exceptionWrapperFactory.newExceptionWrappers(e, START_TIME, context.getExceptionId()); - exceptionRecordingService.recordException(context, e, START_TIME); + exceptionRecordingService.recordException(e, START_TIME); actual = exceptionStorage.getWrappers(); Assertions.assertTrue(actual.isEmpty()); } - exceptionRecordingService.recordException(context, null, START_TIME); + exceptionRecordingService.recordException(null, START_TIME); actual = exceptionStorage.getWrappers(); Assertions.assertEquals(expected, actual); } @@ -141,7 +143,7 @@ public void testRecordNotChainedException() { notChainedException(throwableFunction); } catch (Throwable e) { expected1 = exceptionWrapperFactory.newExceptionWrappers(exceptions.get(exceptions.size() - 2), START_TIME, context.getExceptionId()); - exceptionRecordingService.recordException(context, e, START_TIME); + exceptionRecordingService.recordException(e, START_TIME); actual1 = exceptionStorage.getWrappers(); throwable = e; Assertions.assertFalse(actual1.isEmpty()); @@ -150,7 +152,7 @@ public void testRecordNotChainedException() { exceptionStorage.flush(); expected2 = exceptionWrapperFactory.newExceptionWrappers(throwable, START_TIME, context.getExceptionId()); - exceptionRecordingService.recordException(context, null, 0); + exceptionRecordingService.recordException(null, 0); actual2 = exceptionStorage.getWrappers(); Assertions.assertEquals(expected2, actual2); } @@ -165,12 +167,12 @@ public void testRecordRethrowGivenException() { rethrowGivenException(throwableFunction); } catch (Throwable e) { expected = exceptionWrapperFactory.newExceptionWrappers(e, START_TIME, context.getExceptionId()); - exceptionRecordingService.recordException(context, e, START_TIME); + exceptionRecordingService.recordException(e, START_TIME); actual = exceptionStorage.getWrappers(); Assertions.assertTrue(actual.isEmpty()); } - exceptionRecordingService.recordException(context, null, 0); + exceptionRecordingService.recordException(null, 0); actual = exceptionStorage.getWrappers(); Assertions.assertEquals(expected, actual); }