17
17
18
18
19
19
import com .navercorp .pinpoint .bootstrap .context .AsyncContext ;
20
+ import com .navercorp .pinpoint .bootstrap .context .AsyncState ;
20
21
import com .navercorp .pinpoint .bootstrap .context .ParsingResult ;
21
22
import com .navercorp .pinpoint .bootstrap .context .SpanEventRecorder ;
22
23
import com .navercorp .pinpoint .common .trace .AnnotationKey ;
38
39
import org .apache .logging .log4j .LogManager ;
39
40
import org .apache .logging .log4j .Logger ;
40
41
42
+ import javax .annotation .Nullable ;
41
43
import java .util .Objects ;
42
44
43
45
/**
@@ -49,18 +51,34 @@ public class WrappedSpanEventRecorder extends AbstractRecorder implements SpanEv
49
51
private static final Logger logger = LogManager .getLogger (DefaultTrace .class .getName ());
50
52
private static final boolean isDebug = logger .isDebugEnabled ();
51
53
52
- protected final TraceRoot traceRoot ;
53
- protected final AsyncContextFactory asyncContextFactory ;
54
+ private final TraceRoot traceRoot ;
55
+ private final AsyncContextFactory asyncContextFactory ;
56
+ @ Nullable
57
+ private final AsyncState asyncState ;
54
58
55
59
private SpanEvent spanEvent ;
56
60
57
- public WrappedSpanEventRecorder (TraceRoot traceRoot , AsyncContextFactory asyncContextFactory ,
58
- final StringMetaDataService stringMetaDataService , final SqlMetaDataService sqlMetaCacheService ,
61
+ public WrappedSpanEventRecorder (TraceRoot traceRoot ,
62
+ AsyncContextFactory asyncContextFactory ,
63
+ StringMetaDataService stringMetaDataService ,
64
+ SqlMetaDataService sqlMetaDataService ,
65
+ IgnoreErrorHandler ignoreErrorHandler ) {
66
+
67
+ this (traceRoot , asyncContextFactory , null , stringMetaDataService , sqlMetaDataService , ignoreErrorHandler );
68
+ }
69
+
70
+ public WrappedSpanEventRecorder (TraceRoot traceRoot ,
71
+ AsyncContextFactory asyncContextFactory ,
72
+ @ Nullable
73
+ final AsyncState asyncState ,
74
+ final StringMetaDataService stringMetaDataService ,
75
+ final SqlMetaDataService sqlMetaCacheService ,
59
76
final IgnoreErrorHandler errorHandler ) {
60
77
super (stringMetaDataService , sqlMetaCacheService , errorHandler );
61
78
this .traceRoot = Objects .requireNonNull (traceRoot , "traceRoot" );
62
79
63
80
this .asyncContextFactory = Objects .requireNonNull (asyncContextFactory , "asyncContextFactory" );
81
+ this .asyncState = asyncState ;
64
82
}
65
83
66
84
public void setWrapped (final SpanEvent spanEvent ) {
@@ -137,6 +155,15 @@ protected boolean isOverflowState() {
137
155
138
156
@ Override
139
157
public AsyncContext recordNextAsyncContext (boolean asyncStateSupport ) {
158
+ if (asyncStateSupport && asyncState != null ) {
159
+ final TraceRoot traceRoot = this .traceRoot ;
160
+ final AsyncId asyncIdObject = getNextAsyncId ();
161
+ final boolean isDisabled = isOverflowState ();
162
+
163
+ final AsyncState asyncState = this .asyncState ;
164
+ asyncState .setup ();
165
+ return asyncContextFactory .newAsyncContext (traceRoot , asyncIdObject , isDisabled , asyncState );
166
+ }
140
167
return recordNextAsyncContext ();
141
168
}
142
169
0 commit comments