|
20 | 20 | import com.google.common.annotations.VisibleForTesting;
|
21 | 21 |
|
22 | 22 | import io.opencensus.contrib.http.util.HttpPropagationUtil;
|
| 23 | +import io.opencensus.trace.BlankSpan; |
23 | 24 | import io.opencensus.trace.EndSpanOptions;
|
24 | 25 | import io.opencensus.trace.NetworkEvent;
|
25 | 26 | import io.opencensus.trace.NetworkEvent.Type;
|
26 | 27 | import io.opencensus.trace.Span;
|
27 |
| -import io.opencensus.trace.SpanContext; |
28 | 28 | import io.opencensus.trace.Status;
|
29 | 29 | import io.opencensus.trace.Tracer;
|
30 | 30 | import io.opencensus.trace.Tracing;
|
@@ -57,6 +57,11 @@ public class OpenCensusUtils {
|
57 | 57 | */
|
58 | 58 | private static Tracer tracer = Tracing.getTracer();
|
59 | 59 |
|
| 60 | + /** |
| 61 | + * Sequence id generator for message event. |
| 62 | + */ |
| 63 | + private static AtomicLong idGenerator = new AtomicLong(); |
| 64 | + |
60 | 65 | /**
|
61 | 66 | * Whether spans should be recorded locally. Defaults to true.
|
62 | 67 | */
|
@@ -132,18 +137,18 @@ public static boolean isRecordEvent() {
|
132 | 137 | }
|
133 | 138 |
|
134 | 139 | /**
|
135 |
| - * Propagate information of a given tracing context. This information will be injected into HTTP |
| 140 | + * Propagate information of current tracing context. This information will be injected into HTTP |
136 | 141 | * header.
|
137 | 142 | *
|
138 |
| - * @param spanContext the spanContext to be propagated. |
| 143 | + * @param span the span to be propagated. |
139 | 144 | * @param headers the headers used in propagation.
|
140 | 145 | */
|
141 |
| - public static void propagateTracingContext(SpanContext spanContext, HttpHeaders headers) { |
142 |
| - Preconditions.checkArgument(spanContext != null, "spanContext should not be null."); |
| 146 | + public static void propagateTracingContext(Span span, HttpHeaders headers) { |
| 147 | + Preconditions.checkArgument(span != null, "span should not be null."); |
143 | 148 | Preconditions.checkArgument(headers != null, "headers should not be null.");
|
144 | 149 | if (propagationTextFormat != null && propagationTextFormatSetter != null) {
|
145 |
| - if (!spanContext.equals(SpanContext.INVALID)) { |
146 |
| - propagationTextFormat.inject(spanContext, headers, propagationTextFormatSetter); |
| 150 | + if (!span.equals(BlankSpan.INSTANCE)) { |
| 151 | + propagationTextFormat.inject(span.getContext(), headers, propagationTextFormatSetter); |
147 | 152 | }
|
148 | 153 | }
|
149 | 154 | }
|
@@ -193,42 +198,39 @@ public static EndSpanOptions getEndSpanOptions(@Nullable Integer statusCode) {
|
193 | 198 | * represents the message size in application layer, i.e., content-length.
|
194 | 199 | *
|
195 | 200 | * @param span The {@code span} in which the send event occurs.
|
196 |
| - * @param id The id for the message, It is unique within an {@link HttpRequest}. |
197 | 201 | * @param size Size of the request.
|
198 | 202 | */
|
199 |
| - public static void recordSentMessageEvent(Span span, long id, long size) { |
200 |
| - recordMessageEvent(span, id, size, Type.SENT); |
| 203 | + public static void recordSentMessageEvent(Span span, long size) { |
| 204 | + recordMessageEvent(span, size, Type.SENT); |
201 | 205 | }
|
202 | 206 |
|
203 | 207 | /**
|
204 | 208 | * Records a new message event which contains the size of the response content. Note that the size
|
205 | 209 | * represents the message size in application layer, i.e., content-length.
|
206 | 210 | *
|
207 | 211 | * @param span The {@code span} in which the receive event occurs.
|
208 |
| - * @param id The id for the message. It is unique within an {@link HttpRequest}. |
209 | 212 | * @param size Size of the response.
|
210 | 213 | */
|
211 |
| - public static void recordReceivedMessageEvent(Span span, long id, long size) { |
212 |
| - recordMessageEvent(span, id, size, Type.RECV); |
| 214 | + public static void recordReceivedMessageEvent(Span span, long size) { |
| 215 | + recordMessageEvent(span, size, Type.RECV); |
213 | 216 | }
|
214 | 217 |
|
215 | 218 | /**
|
216 | 219 | * Records a message event of a certain {@link NetowrkEvent.Type}. This method is package
|
217 | 220 | * protected since {@link NetworkEvent} might be deprecated in future releases.
|
218 | 221 | *
|
219 | 222 | * @param span The {@code span} in which the event occurs.
|
220 |
| - * @param id The id for the message. |
221 | 223 | * @param size Size of the message.
|
222 | 224 | * @param eventType The {@code NetworkEvent.Type} of the message event.
|
223 | 225 | */
|
224 | 226 | @VisibleForTesting
|
225 |
| - static void recordMessageEvent(Span span, long id, long size, Type eventType) { |
| 227 | + static void recordMessageEvent(Span span, long size, Type eventType) { |
226 | 228 | Preconditions.checkArgument(span != null, "span should not be null.");
|
227 | 229 | if (size < 0) {
|
228 | 230 | size = 0;
|
229 | 231 | }
|
230 | 232 | NetworkEvent event = NetworkEvent
|
231 |
| - .builder(eventType, id) |
| 233 | + .builder(eventType, idGenerator.getAndIncrement()) |
232 | 234 | .setUncompressedMessageSize(size)
|
233 | 235 | .build();
|
234 | 236 | span.addNetworkEvent(event);
|
|
0 commit comments