Class OpenCensusUtils

public class OpenCensusUtils

Beta
Utilities for Census monitoring and tracing.

Inheritance

java.lang.Object > OpenCensusUtils

Fields

SPAN_NAME_HTTP_REQUEST_EXECUTE

public static final String SPAN_NAME_HTTP_REQUEST_EXECUTE

Span name for tracing HttpRequest#execute().

Field Value
TypeDescription
String

Methods

getEndSpanOptions(Integer statusCode)

public static EndSpanOptions getEndSpanOptions(Integer statusCode)

Returns an EndSpanOptions to end a http span according to the status code.

Parameter
NameDescription
statusCodeInteger

the status code, can be null to represent no valid response is returned.

Returns
TypeDescription
io.opencensus.trace.EndSpanOptions

an EndSpanOptions that best suits the status code.

getTracer()

public static Tracer getTracer()

Returns the tracing component of OpenCensus.

Returns
TypeDescription
io.opencensus.trace.Tracer

the tracing component of OpenCensus.

isRecordEvent()

public static boolean isRecordEvent()

Returns whether spans should be recorded locally.

Returns
TypeDescription
boolean

whether spans should be recorded locally.

propagateTracingContext(Span span, HttpHeaders headers)

public static void propagateTracingContext(Span span, HttpHeaders headers)

Propagate information of current tracing context. This information will be injected into HTTP header.

Parameters
NameDescription
spanio.opencensus.trace.Span

the span to be propagated.

headersHttpHeaders

the headers used in propagation.

recordReceivedMessageEvent(Span span, long size)

public static void recordReceivedMessageEvent(Span span, long size)

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.

Parameters
NameDescription
spanio.opencensus.trace.Span

The span in which the receive event occurs.

sizelong

Size of the response.

recordSentMessageEvent(Span span, long size)

public static void recordSentMessageEvent(Span span, long size)

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.

Parameters
NameDescription
spanio.opencensus.trace.Span

The span in which the send event occurs.

sizelong

Size of the request.

setIsRecordEvent(boolean recordEvent)

public static void setIsRecordEvent(boolean recordEvent)

Sets whether spans should be recorded locally.

This API allows users of google-http-client to turn on/off local span collection.

Parameter
NameDescription
recordEventboolean

record span locally if true.

setPropagationTextFormat(TextFormat textFormat)

public static void setPropagationTextFormat(TextFormat textFormat)

Sets the TextFormat used in context propagation.

This API allows users of google-http-client to specify other text format, or disable context propagation by setting it to null. It should be used along with #setPropagationTextFormatSetter for setting purpose.

Parameter
NameDescription
textFormatio.opencensus.trace.propagation.TextFormat

the text format.

setPropagationTextFormatSetter(TextFormat.Setter textFormatSetter)

public static void setPropagationTextFormatSetter(TextFormat.Setter textFormatSetter)

Sets the io.opencensus.trace.propagation.TextFormat.Setter used in context propagation.

This API allows users of google-http-client to specify other text format setter, or disable context propagation by setting it to null. It should be used along with #setPropagationTextFormat for setting purpose.

Parameter
NameDescription
textFormatSetterio.opencensus.trace.propagation.TextFormat.Setter

the TextFormat.Setter for the text format.