|
44 | 44 | * arguments will be captured in traces including these that may contain sensitive details.
|
45 | 45 | *
|
46 | 46 | * @author Mark Paluch
|
| 47 | + * @author Yanming Zhou |
47 | 48 | * @since 3.0
|
48 | 49 | */
|
49 | 50 | public class MicrometerTracingAdapter implements Tracing {
|
@@ -121,29 +122,28 @@ public MicrometerTracer(ObservationRegistry observationRegistry) {
|
121 | 122 |
|
122 | 123 | @Override
|
123 | 124 | public Tracer.Span nextSpan() {
|
124 |
| - return this.postProcessSpan(createObservation()); |
| 125 | + return this.postProcessSpan(createObservation(null)); |
125 | 126 | }
|
126 | 127 |
|
127 | 128 | @Override
|
128 | 129 | public Tracer.Span nextSpan(TraceContext traceContext) {
|
129 |
| - |
130 |
| - if (traceContext instanceof MicrometerTraceContext micrometerTraceContext) { |
131 |
| - |
132 |
| - return micrometerTraceContext.observation == null ? nextSpan() |
133 |
| - : postProcessSpan(createObservation().parentObservation(micrometerTraceContext.observation())); |
134 |
| - } |
135 |
| - |
136 |
| - return nextSpan(); |
| 130 | + return postProcessSpan(createObservation(traceContext)); |
137 | 131 | }
|
138 | 132 |
|
139 |
| - private Observation createObservation() { |
| 133 | + private Observation createObservation(@Nullable TraceContext traceContext) { |
140 | 134 | return RedisObservation.REDIS_COMMAND_OBSERVATION.observation(observationRegistry,
|
141 |
| - () -> new LettuceObservationContext(serviceName)); |
| 135 | + () -> { |
| 136 | + LettuceObservationContext context = new LettuceObservationContext(serviceName); |
| 137 | + if (traceContext instanceof MicrometerTraceContext micrometerTraceContext) { |
| 138 | + context.setParentObservation(micrometerTraceContext.observation); |
| 139 | + } |
| 140 | + return context; |
| 141 | + }); |
142 | 142 | }
|
143 | 143 |
|
144 | 144 | private Tracer.Span postProcessSpan(Observation observation) {
|
145 | 145 |
|
146 |
| - return observation != null && !observation.isNoop() |
| 146 | + return !observation.isNoop() |
147 | 147 | ? new MicrometerSpan(observation.observationConvention(observationConvention))
|
148 | 148 | : NoOpSpan.INSTANCE;
|
149 | 149 | }
|
@@ -292,6 +292,7 @@ public void finish() {
|
292 | 292 | record MicrometerTraceContextProvider(ObservationRegistry registry) implements TraceContextProvider {
|
293 | 293 |
|
294 | 294 | @Override
|
| 295 | + @Nullable |
295 | 296 | public TraceContext getTraceContext() {
|
296 | 297 |
|
297 | 298 | Observation observation = registry.getCurrentObservation();
|
|
0 commit comments