use of io.opencensus.trace.MessageEvent in project instrumentation-java by census-instrumentation.
the class JaegerExporterHandler method timedEventsToLogs.
private static List<Log> timedEventsToLogs(final List<SpanData.TimedEvent<Annotation>> annotations, final List<SpanData.TimedEvent<MessageEvent>> messageEvents) {
final List<Log> logs = Lists.newArrayListWithExpectedSize(annotations.size() + messageEvents.size());
for (final SpanData.TimedEvent<Annotation> event : annotations) {
final long timestampsInMicros = timestampToMicros(event.getTimestamp());
logs.add(new Log(timestampsInMicros, attributesToTags(event.getEvent().getAttributes(), descriptionToTag(event.getEvent().getDescription()))));
}
for (final SpanData.TimedEvent<MessageEvent> event : messageEvents) {
final long timestampsInMicros = timestampToMicros(event.getTimestamp());
final Tag tagMessageId = new Tag(MESSAGE_EVENT_ID, TagType.LONG).setVLong(event.getEvent().getMessageId());
final Tag tagCompressedSize = new Tag(MESSAGE_EVENT_COMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getCompressedMessageSize());
final Tag tagUncompressedSize = new Tag(MESSAGE_EVENT_UNCOMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getUncompressedMessageSize());
logs.add(new Log(timestampsInMicros, Arrays.asList(event.getEvent().getType() == Type.RECEIVED ? RECEIVED_MESSAGE_EVENT_TAG : SENT_MESSAGE_EVENT_TAG, tagMessageId, tagCompressedSize, tagUncompressedSize)));
}
return logs;
}
use of io.opencensus.trace.MessageEvent in project grpc-java by grpc.
the class CensusModulesTest method serverBasicTracingNoHeaders.
@Test
public void serverBasicTracingNoHeaders() {
ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
ServerStreamTracer serverStreamTracer = tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata());
verifyNoInteractions(mockTracingPropagationHandler);
verify(tracer).spanBuilderWithRemoteParent(eq("Recv.package1.service2.method3"), ArgumentMatchers.<SpanContext>isNull());
verify(spyServerSpanBuilder).setRecordEvents(eq(true));
Context filteredContext = serverStreamTracer.filterContext(Context.ROOT);
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
serverStreamTracer.serverCallStarted(new CallInfo<>(method, Attributes.EMPTY, null));
verify(spyServerSpan, never()).end(any(EndSpanOptions.class));
serverStreamTracer.outboundMessage(0);
serverStreamTracer.outboundMessageSent(0, 882, -1);
serverStreamTracer.inboundMessage(0);
serverStreamTracer.outboundMessage(1);
serverStreamTracer.outboundMessageSent(1, -1, 27);
serverStreamTracer.inboundMessageRead(0, 255, 90);
serverStreamTracer.streamClosed(Status.CANCELLED);
InOrder inOrder = inOrder(spyServerSpan);
inOrder.verify(spyServerSpan, times(3)).addMessageEvent(messageEventCaptor.capture());
List<MessageEvent> events = messageEventCaptor.getAllValues();
assertEquals(MessageEvent.builder(MessageEvent.Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
assertEquals(MessageEvent.builder(MessageEvent.Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
assertEquals(MessageEvent.builder(MessageEvent.Type.RECEIVED, 0).setCompressedMessageSize(255).setUncompressedMessageSize(90).build(), events.get(2));
inOrder.verify(spyServerSpan).end(EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.CANCELLED).setSampleToLocalSpanStore(false).build());
verifyNoMoreInteractions(spyServerSpan);
}
use of io.opencensus.trace.MessageEvent in project grpc-java by grpc.
the class CensusModulesTest method clientBasicTracingDefaultSpan.
@Test
public void clientBasicTracingDefaultSpan() {
CallAttemptsTracerFactory callTracer = censusTracing.newClientCallTracer(null, method);
Metadata headers = new Metadata();
ClientStreamTracer clientStreamTracer = callTracer.newClientStreamTracer(STREAM_INFO, headers);
clientStreamTracer.streamCreated(Attributes.EMPTY, headers);
verify(tracer).spanBuilderWithExplicitParent(eq("Sent.package1.service2.method3"), ArgumentMatchers.<Span>isNull());
verify(tracer).spanBuilderWithExplicitParent(eq("Attempt.package1.service2.method3"), eq(spyClientSpan));
verify(spyClientSpan, never()).end(any(EndSpanOptions.class));
verify(spyAttemptSpan, never()).end(any(EndSpanOptions.class));
clientStreamTracer.outboundMessage(0);
clientStreamTracer.outboundMessageSent(0, 882, -1);
clientStreamTracer.inboundMessage(0);
clientStreamTracer.outboundMessage(1);
clientStreamTracer.outboundMessageSent(1, -1, 27);
clientStreamTracer.inboundMessageRead(0, 255, 90);
clientStreamTracer.streamClosed(Status.OK);
callTracer.callEnded(Status.OK);
InOrder inOrder = inOrder(spyClientSpan, spyAttemptSpan);
inOrder.verify(spyAttemptSpan).putAttribute("previous-rpc-attempts", AttributeValue.longAttributeValue(0));
inOrder.verify(spyAttemptSpan).putAttribute("transparent-retry", AttributeValue.booleanAttributeValue(false));
inOrder.verify(spyAttemptSpan, times(3)).addMessageEvent(messageEventCaptor.capture());
List<MessageEvent> events = messageEventCaptor.getAllValues();
assertEquals(MessageEvent.builder(MessageEvent.Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
assertEquals(MessageEvent.builder(MessageEvent.Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
assertEquals(MessageEvent.builder(MessageEvent.Type.RECEIVED, 0).setCompressedMessageSize(255).setUncompressedMessageSize(90).build(), events.get(2));
inOrder.verify(spyAttemptSpan).end(EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.OK).setSampleToLocalSpanStore(false).build());
inOrder.verify(spyClientSpan).end(EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.OK).setSampleToLocalSpanStore(false).build());
inOrder.verifyNoMoreInteractions();
verifyNoMoreInteractions(tracer);
}
use of io.opencensus.trace.MessageEvent in project instrumentation-java by census-instrumentation.
the class AbstractHttpHandler method recordMessageEvent.
/**
* A convenience to record a {@link MessageEvent} with given parameters.
*
* @param span the span which this {@code MessageEvent} will be added to.
* @param id the id of the event.
* @param type the {@code MessageEvent.Type} of the event.
* @param uncompressedMessageSize size of the message before compressed (optional).
* @param compressedMessageSize size of the message after compressed (optional).
* @since 0.19
*/
static void recordMessageEvent(Span span, long id, Type type, long uncompressedMessageSize, long compressedMessageSize) {
MessageEvent messageEvent = MessageEvent.builder(type, id).setUncompressedMessageSize(uncompressedMessageSize).setCompressedMessageSize(compressedMessageSize).build();
span.addMessageEvent(messageEvent);
}
use of io.opencensus.trace.MessageEvent in project instrumentation-java by census-instrumentation.
the class AbstractHttpHandlerTest method handleMessageSent.
@Test
public void handleMessageSent() {
Type type = Type.SENT;
long uncompressed = 456L;
HttpRequestContext context = new HttpRequestContext(fakeSpan, tagContext);
handler.handleMessageSent(context, uncompressed);
verify(fakeSpan).addMessageEvent(captor.capture());
MessageEvent messageEvent = captor.getValue();
assertThat(messageEvent.getType()).isEqualTo(type);
assertThat(messageEvent.getMessageId()).isEqualTo(1L);
assertThat(messageEvent.getUncompressedMessageSize()).isEqualTo(uncompressed);
assertThat(messageEvent.getCompressedMessageSize()).isEqualTo(0);
}
Aggregations