io.opencensus.trace.MessageEvent.Type Java Examples
The following examples show how to use
io.opencensus.trace.MessageEvent.Type.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractHttpHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
/** * Instrument an HTTP span after a message is sent. Typically called for every chunk of request or * response is sent. * * @param context request specific {@link HttpRequestContext} * @param bytes bytes sent. * @since 0.19 */ public final void handleMessageSent(HttpRequestContext context, long bytes) { checkNotNull(context, "context"); context.sentMessageSize.addAndGet(bytes); if (context.span.getOptions().contains(Options.RECORD_EVENTS)) { // record compressed size recordMessageEvent(context.span, context.sentSeqId.addAndGet(1L), Type.SENT, bytes, 0L); } }
Example #2
Source File: OpenCensusUtils.java From google-http-java-client with Apache License 2.0 | 5 votes |
/** * Records a message event of a certain {@link MessageEvent.Type}. This method is package * protected since {@link MessageEvent} might be deprecated in future releases. * * @param span The {@code span} in which the event occurs. * @param size Size of the message. * @param eventType The {@code NetworkEvent.Type} of the message event. */ @VisibleForTesting static void recordMessageEvent(Span span, long size, Type eventType) { Preconditions.checkArgument(span != null, "span should not be null."); if (size < 0) { size = 0; } MessageEvent event = MessageEvent.builder(eventType, idGenerator.getAndIncrement()) .setUncompressedMessageSize(size) .build(); span.addMessageEvent(event); }
Example #3
Source File: JaegerExporterHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
private static SpanRefType linkTypeToRefType(final Link.Type type) { switch (type) { case CHILD_LINKED_SPAN: return SpanRefType.CHILD_OF; case PARENT_LINKED_SPAN: return SpanRefType.FOLLOWS_FROM; } throw new UnsupportedOperationException( format("Failed to convert link type [%s] to a Jaeger SpanRefType.", type)); }
Example #4
Source File: TraceProtoUtils.java From opencensus-java with Apache License 2.0 | 5 votes |
private static Link.Type toLinkTypeProto(io.opencensus.trace.Link.Type type) { if (type == io.opencensus.trace.Link.Type.PARENT_LINKED_SPAN) { return Link.Type.PARENT_LINKED_SPAN; } else { return Link.Type.CHILD_LINKED_SPAN; } }
Example #5
Source File: TraceProtoUtils.java From opencensus-java with Apache License 2.0 | 5 votes |
private static TimeEvent.MessageEvent.Type toMessageEventTypeProto( io.opencensus.trace.MessageEvent messageEvent) { if (messageEvent.getType() == Type.RECEIVED) { return MessageEvent.Type.RECEIVED; } else { return MessageEvent.Type.SENT; } }
Example #6
Source File: StackdriverV2ExporterHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
private static Link.Type toLinkTypeProto(io.opencensus.trace.Link.Type type) { if (type == io.opencensus.trace.Link.Type.PARENT_LINKED_SPAN) { return Link.Type.PARENT_LINKED_SPAN; } else { return Link.Type.CHILD_LINKED_SPAN; } }
Example #7
Source File: StackdriverV2ExporterHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
private static TimeEvent.MessageEvent.Type toMessageEventTypeProto( io.opencensus.trace.MessageEvent messageEvent) { if (messageEvent.getType() == Type.RECEIVED) { return MessageEvent.Type.RECEIVED; } else { return MessageEvent.Type.SENT; } }
Example #8
Source File: AbstractHttpHandlerTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void handleMessageReceived() { Type type = Type.RECEIVED; long uncompressed = 456L; HttpRequestContext context = new HttpRequestContext(fakeSpan, tagContext); handler.handleMessageReceived(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); }
Example #9
Source File: AbstractHttpHandlerTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@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); }
Example #10
Source File: AbstractHttpHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
/** * Instrument an HTTP span after a message is received. Typically called for every chunk of * request or response is received. * * @param context request specific {@link HttpRequestContext} * @param bytes bytes received. * @since 0.19 */ public final void handleMessageReceived(HttpRequestContext context, long bytes) { checkNotNull(context, "context"); context.receiveMessageSize.addAndGet(bytes); if (context.span.getOptions().contains(Options.RECORD_EVENTS)) { // record compressed size recordMessageEvent( context.span, context.receviedSeqId.addAndGet(1L), Type.RECEIVED, bytes, 0L); } }
Example #11
Source File: CensusTracingModule.java From grpc-java with Apache License 2.0 | 5 votes |
private static void recordMessageEvent( Span span, MessageEvent.Type type, int seqNo, long optionalWireSize, long optionalUncompressedSize) { MessageEvent.Builder eventBuilder = MessageEvent.builder(type, seqNo); if (optionalUncompressedSize != -1) { eventBuilder.setUncompressedMessageSize(optionalUncompressedSize); } if (optionalWireSize != -1) { eventBuilder.setCompressedMessageSize(optionalWireSize); } span.addMessageEvent(eventBuilder.build()); }
Example #12
Source File: RecordTraceEventsBenchmark.java From opencensus-java with Apache License 2.0 | 5 votes |
/** This benchmark attempts to measure performance of adding a link to the span. */ @Benchmark @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public Span addLink(Data data) { data.span.addLink( Link.fromSpanContext(data.linkedSpan.getContext(), Link.Type.PARENT_LINKED_SPAN)); return data.span; }
Example #13
Source File: RecordTraceEventsBenchmark.java From opencensus-java with Apache License 2.0 | 5 votes |
/** This benchmark attempts to measure performance of adding a network event to the span. */ @Benchmark @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public Span addMessageEvent(Data data) { data.span.addMessageEvent( io.opencensus.trace.MessageEvent.builder(Type.RECEIVED, 1) .setUncompressedMessageSize(3) .build()); return data.span; }
Example #14
Source File: CensusTracingModule.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
private static void recordMessageEvent( Span span, MessageEvent.Type type, int seqNo, long optionalWireSize, long optionalUncompressedSize) { MessageEvent.Builder eventBuilder = MessageEvent.builder(type, seqNo); if (optionalUncompressedSize != -1) { eventBuilder.setUncompressedMessageSize(optionalUncompressedSize); } if (optionalWireSize != -1) { eventBuilder.setCompressedMessageSize(optionalWireSize); } span.addMessageEvent(eventBuilder.build()); }
Example #15
Source File: CensusModulesTest.java From grpc-java with Apache License 2.0 | 4 votes |
@Test public void serverBasicTracingNoHeaders() { ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory(); ServerStreamTracer serverStreamTracer = tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata()); verifyZeroInteractions(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(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0)); assertEquals( MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1)); assertEquals( MessageEvent.builder(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); }
Example #16
Source File: CensusTracingModule.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public void outboundMessageSent( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.SENT, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #17
Source File: CensusTracingModule.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public void inboundMessageRead( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.RECEIVED, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #18
Source File: CensusTracingModule.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public void outboundMessageSent( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.SENT, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #19
Source File: CensusTracingModule.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public void inboundMessageRead( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.RECEIVED, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #20
Source File: CensusModulesTest.java From grpc-java with Apache License 2.0 | 4 votes |
@Test public void clientBasicTracingDefaultSpan() { CensusTracingModule.ClientCallTracer callTracer = censusTracing.newClientCallTracer(null, method); Metadata headers = new Metadata(); ClientStreamTracer clientStreamTracer = callTracer.newClientStreamTracer(STREAM_INFO, headers); verify(tracer).spanBuilderWithExplicitParent( eq("Sent.package1.service2.method3"), ArgumentMatchers.<Span>isNull()); verify(spyClientSpan, 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); inOrder.verify(spyClientSpan, times(3)).addMessageEvent(messageEventCaptor.capture()); List<MessageEvent> events = messageEventCaptor.getAllValues(); assertEquals( MessageEvent.builder(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0)); assertEquals( MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1)); assertEquals( MessageEvent.builder(Type.RECEIVED, 0) .setCompressedMessageSize(255) .setUncompressedMessageSize(90) .build(), events.get(2)); inOrder.verify(spyClientSpan).end( EndSpanOptions.builder() .setStatus(io.opencensus.trace.Status.OK) .setSampleToLocalSpanStore(false) .build()); verifyNoMoreInteractions(spyClientSpan); verifyNoMoreInteractions(tracer); }
Example #21
Source File: CensusModulesTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Test public void serverBasicTracingNoHeaders() { ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory(); ServerStreamTracer serverStreamTracer = tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata()); verifyZeroInteractions(mockTracingPropagationHandler); verify(tracer).spanBuilderWithRemoteParent( eq("Recv.package1.service2.method3"), isNull(SpanContext.class)); verify(spyServerSpanBuilder).setRecordEvents(eq(true)); Context filteredContext = serverStreamTracer.filterContext(Context.ROOT); assertSame(spyServerSpan, ContextUtils.CONTEXT_SPAN_KEY.get(filteredContext)); serverStreamTracer.serverCallStarted( new ServerCallInfoImpl<String, String>(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(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0)); assertEquals( MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1)); assertEquals( MessageEvent.builder(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); }
Example #22
Source File: CensusModulesTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Test public void clientBasicTracingDefaultSpan() { CensusTracingModule.ClientCallTracer callTracer = censusTracing.newClientCallTracer(null, method); Metadata headers = new Metadata(); ClientStreamTracer clientStreamTracer = callTracer.newClientStreamTracer(CallOptions.DEFAULT, headers); verify(tracer).spanBuilderWithExplicitParent( eq("Sent.package1.service2.method3"), isNull(Span.class)); verify(spyClientSpan, 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); inOrder.verify(spyClientSpan, times(3)).addMessageEvent(messageEventCaptor.capture()); List<MessageEvent> events = messageEventCaptor.getAllValues(); assertEquals( MessageEvent.builder(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0)); assertEquals( MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1)); assertEquals( MessageEvent.builder(Type.RECEIVED, 0) .setCompressedMessageSize(255) .setUncompressedMessageSize(90) .build(), events.get(2)); inOrder.verify(spyClientSpan).end( EndSpanOptions.builder() .setStatus(io.opencensus.trace.Status.OK) .setSampleToLocalSpanStore(false) .build()); verifyNoMoreInteractions(spyClientSpan); verifyNoMoreInteractions(tracer); }
Example #23
Source File: CensusTracingModule.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public void inboundMessageRead( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.RECEIVED, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #24
Source File: CensusTracingModule.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public void outboundMessageSent( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.SENT, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #25
Source File: CensusTracingModule.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public void inboundMessageRead( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.RECEIVED, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #26
Source File: CensusTracingModule.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public void outboundMessageSent( int seqNo, long optionalWireSize, long optionalUncompressedSize) { recordMessageEvent( span, Type.SENT, seqNo, optionalWireSize, optionalUncompressedSize); }
Example #27
Source File: AbstractHttpHandler.java From opencensus-java with Apache License 2.0 | 3 votes |
/** * 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); }
Example #28
Source File: OpenCensusUtils.java From google-http-java-client with Apache License 2.0 | 2 votes |
/** * Records a new message event which contains the size of the response content. Note that the size * represents the message size in application layer, i.e., content-length. * * @param span The {@code span} in which the receive event occurs. * @param size Size of the response. */ public static void recordReceivedMessageEvent(Span span, long size) { recordMessageEvent(span, size, Type.RECEIVED); }
Example #29
Source File: OpenCensusUtils.java From google-http-java-client with Apache License 2.0 | 2 votes |
/** * Records a new message event which contains the size of the request content. Note that the size * represents the message size in application layer, i.e., content-length. * * @param span The {@code span} in which the send event occurs. * @param size Size of the request. */ public static void recordSentMessageEvent(Span span, long size) { recordMessageEvent(span, size, Type.SENT); }