Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9631] Integrate ExceptionContext lifecycle into ExceptionRecordingService #10619

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,9 +15,8 @@
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);

Check warning on line 19 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java#L19

Added line #L19 was not covered by tests
this.asyncState = Objects.requireNonNull(asyncState, "asyncState");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,8 +46,6 @@
private final SpanRecorder spanRecorder;
private final WrappedSpanEventRecorder wrappedSpanEventRecorder;

private final ExceptionContext exceptionContext;

private boolean closed = false;
// lazy initialize
private DefaultTraceScopePool scopePool;
Expand All @@ -58,7 +55,6 @@

public ChildTrace(final TraceRoot traceRoot, CallStack<SpanEvent> callStack, Storage storage,
SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder,
ExceptionContext exceptionContext,
final LocalAsyncId localAsyncId) {

this.traceRoot = Objects.requireNonNull(traceRoot, "traceRoot");
Expand All @@ -67,7 +63,6 @@

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);
Expand All @@ -79,7 +74,7 @@
}

private SpanEventRecorder wrappedSpanEventRecorder(WrappedSpanEventRecorder wrappedSpanEventRecorder, SpanEvent spanEvent) {
wrappedSpanEventRecorder.setWrapped(spanEvent, this.exceptionContext);
wrappedSpanEventRecorder.setWrapped(spanEvent);

Check warning on line 77 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java#L77

Added line #L77 was not covered by tests
return wrappedSpanEventRecorder;
}

Expand Down Expand Up @@ -185,7 +180,7 @@
} else {
logSpan();
}

this.wrappedSpanEventRecorder.close();

Check warning on line 183 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ChildTrace.java#L183

Added line #L183 was not covered by tests
this.storage.close();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +59,6 @@
private final TraceRootFactory traceRootFactory;

private final ActiveTraceRepository activeTraceRepository;
private final ExceptionContextFactory exceptionContextFactory;
private final UriStatStorage uriStatStorage;

public DefaultBaseTraceFactory(TraceRootFactory traceRootFactory,
Expand All @@ -70,7 +67,6 @@
TraceSampler traceSampler,
SpanFactory spanFactory, RecorderFactory recorderFactory,
ActiveTraceRepository activeTraceRepository,
ExceptionContextFactory exceptionContextFactory,
UriStatStorage uriStatStorage) {

this.traceRootFactory = Objects.requireNonNull(traceRootFactory, "traceRootFactory");
Expand All @@ -81,7 +77,6 @@
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");

}
Expand Down Expand Up @@ -136,9 +131,8 @@

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

Check warning on line 135 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java#L135

Added line #L135 was not covered by tests
}

@Override
Expand Down Expand Up @@ -202,11 +196,10 @@

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) {
Expand All @@ -221,9 +214,8 @@

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

Check warning on line 218 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java#L218

Added line #L218 was not covered by tests
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,8 +49,6 @@
private final SpanRecorder spanRecorder;
private final WrappedSpanEventRecorder wrappedSpanEventRecorder;

private final ExceptionContext exceptionContext;

private boolean closed = false;
// lazy initialize
private DefaultTraceScopePool scopePool;
Expand All @@ -61,15 +58,13 @@
private final CloseListener closeListener;

public DefaultTrace(Span span, CallStack<SpanEvent> 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);

Check warning on line 62 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java#L62

Added line #L62 was not covered by tests
}

public DefaultTrace(Span span, CallStack<SpanEvent> callStack, Storage storage,
SpanRecorder spanRecorder,
WrappedSpanEventRecorder wrappedSpanEventRecorder,
ExceptionContext exceptionContext,
CloseListener closeListener) {

this.span = Objects.requireNonNull(span, "span");
Expand All @@ -78,7 +73,6 @@

this.spanRecorder = Objects.requireNonNull(spanRecorder, "spanRecorder");
this.wrappedSpanEventRecorder = Objects.requireNonNull(wrappedSpanEventRecorder, "wrappedSpanEventRecorder");
this.exceptionContext = Objects.requireNonNull(exceptionContext, "exceptionRecordingContext");

this.closeListener = closeListener;

Expand All @@ -95,7 +89,7 @@
}

private SpanEventRecorder wrappedSpanEventRecorder(WrappedSpanEventRecorder wrappedSpanEventRecorder, SpanEvent spanEvent) {
wrappedSpanEventRecorder.setWrapped(spanEvent, this.exceptionContext);
wrappedSpanEventRecorder.setWrapped(spanEvent);
return wrappedSpanEventRecorder;
}

Expand Down Expand Up @@ -201,7 +195,7 @@
logSpan();
}

this.exceptionContext.flush();
this.wrappedSpanEventRecorder.close();
this.storage.close();
this.closeListener.close(afterTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -68,7 +64,8 @@
return ExceptionTraceSampler.DISABLED;
}

public void recordExceptionIdAnnotation(SpanEvent spanEvent, ExceptionContext context) {
public void recordExceptionIdAnnotation(SpanEvent spanEvent) {
final ExceptionContext context = this.exceptionContext;

Check warning on line 68 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java#L68

Added line #L68 was not covered by tests
if (context.hasValidExceptionId()) {
Annotation<Long> linkId = Annotations.of(AnnotationKey.EXCEPTION_CHAIN_ID.getCode(), context.getExceptionId());
spanEvent.addAnnotation(linkId);
Expand All @@ -77,18 +74,18 @@

@Override
public void recordException(
ExceptionContext exceptionContext,
SpanEvent spanEvent,
Throwable throwable
) {
this.recordException(
exceptionContext,
throwable,
spanEvent.getStartTime()
);
this.recordExceptionIdAnnotation(
spanEvent,
exceptionContext
);
this.recordExceptionIdAnnotation(spanEvent);
}

Check warning on line 85 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java#L84-L85

Added lines #L84 - L85 were not covered by tests

@Override
public void close() {
this.exceptionContext.flush();

Check warning on line 89 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingService.java#L89

Added line #L89 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -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");

Check warning on line 39 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java#L36-L39

Added lines #L36 - L39 were not covered by tests

}

Check warning on line 41 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java#L41

Added line #L41 was not covered by tests

@Override
public ExceptionRecordingService newService(TraceRoot traceRoot) {
Objects.requireNonNull(traceRoot, "traceRoot");
ExceptionContext exceptionContext = this.exceptionContextFactory.newExceptionContext(traceRoot);
return new DefaultExceptionRecordingService(exceptionTraceSampler, exceptionWrapperFactory, exceptionContext);

Check warning on line 47 in profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java

View check run for this annotation

Codecov / codecov/patch

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/exception/DefaultExceptionRecordingServiceFactory.java#L45-L47

Added lines #L45 - L47 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Loading