io.opencensus.trace.propagation.TextFormat Java Examples

The following examples show how to use io.opencensus.trace.propagation.TextFormat. 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: TracingAsyncClientHttpRequestInterceptor.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
TracingAsyncClientHttpRequestInterceptor(
    @Nullable TextFormat propagator,
    @Nullable HttpExtractor<HttpRequest, ClientHttpResponse> extractor) {

  tracer = Tracing.getTracer();

  if (propagator == null) {
    propagator = Tracing.getPropagationComponent().getTraceContextFormat();
  }

  if (extractor == null) {
    extractor = (HttpExtractor<HttpRequest, ClientHttpResponse>) new HttpClientExtractor();
  }

  handler =
      new HttpClientHandler<HttpRequest, ClientHttpResponse, HttpRequest>(
          Tracing.getTracer(), extractor, propagator, setter);
}
 
Example #2
Source File: HttpServerHandler.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link HttpServerHandler} with given parameters.
 *
 * @param tracer the Open Census tracing component.
 * @param extractor the {@code HttpExtractor} used to extract information from the
 *     request/response.
 * @param textFormat the {@code TextFormat} used in HTTP propagation.
 * @param getter the getter used when extracting information from the {@code carrier}.
 * @param publicEndpoint set to true for publicly accessible HTTP(S) server. If true then incoming
 *     tracecontext will be added as a link instead of as a parent.
 * @since 0.19
 */
public HttpServerHandler(
    Tracer tracer,
    HttpExtractor<Q, P> extractor,
    TextFormat textFormat,
    TextFormat.Getter<C> getter,
    Boolean publicEndpoint) {
  super(extractor);
  checkNotNull(tracer, "tracer");
  checkNotNull(textFormat, "textFormat");
  checkNotNull(getter, "getter");
  checkNotNull(publicEndpoint, "publicEndpoint");
  this.tracer = tracer;
  this.textFormat = textFormat;
  this.getter = getter;
  this.publicEndpoint = publicEndpoint;
  this.statsRecorder = Stats.getStatsRecorder();
  this.tagger = Tags.getTagger();
}
 
Example #3
Source File: HttpClientHandler.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link HttpClientHandler} with given parameters.
 *
 * @param tracer the Open Census tracing component.
 * @param extractor the {@code HttpExtractor} used to extract information from the
 *     request/response.
 * @param textFormat the {@code TextFormat} used in HTTP propagation.
 * @param setter the setter used when injecting information to the {@code carrier}.
 * @since 0.19
 */
public HttpClientHandler(
    Tracer tracer,
    HttpExtractor<Q, P> extractor,
    TextFormat textFormat,
    TextFormat.Setter<C> setter) {
  super(extractor);
  checkNotNull(setter, "setter");
  checkNotNull(textFormat, "textFormat");
  checkNotNull(tracer, "tracer");
  this.setter = setter;
  this.textFormat = textFormat;
  this.tracer = tracer;
  this.statsRecorder = Stats.getStatsRecorder();
  this.tagger = Tags.getTagger();
}
 
Example #4
Source File: TraceWebAsyncClientAutoConfiguration.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Bean
public TracingAsyncClientHttpRequestInterceptor asyncTracingClientHttpRequestInterceptor() {
  TextFormat propagator;

  if (propagation != null && propagation == Propagation.TRACE_PROPAGATION_B3) {
    propagator = Tracing.getPropagationComponent().getB3Format();
  } else {
    propagator = Tracing.getPropagationComponent().getTraceContextFormat();
  }
  return (TracingAsyncClientHttpRequestInterceptor)
      TracingAsyncClientHttpRequestInterceptor.create(propagator, extractor);
}
 
Example #5
Source File: OcJettyHttpClient.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static HttpClientHandler<Request, Response, Request> buildHandler(
    @Nullable HttpExtractor<Request, Response> extractor, @Nullable TextFormat propagator) {
  if (extractor == null) {
    extractor = new OcJettyHttpClientExtractor();
  }

  if (propagator == null) {
    propagator = Tracing.getPropagationComponent().getTraceContextFormat();
  }

  return new HttpClientHandler<Request, Response, Request>(
      Tracing.getTracer(), extractor, propagator, setter);
}
 
Example #6
Source File: OcHttpServletFilter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
static HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest>
    buildHttpServerHandlerWithOptions(
        HttpExtractor<HttpServletRequest, HttpServletResponse> extractor,
        TextFormat propagator,
        Boolean publicEndpoint) {
  return new HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest>(
      Tracing.getTracer(), extractor, propagator, getter, publicEndpoint);
}
 
Example #7
Source File: PropagationComponentImpl.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public TextFormat getB3Format() {
  return b3Format;
}
 
Example #8
Source File: PropagationComponentImpl.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public TextFormat getTraceContextFormat() {
  return traceContextFormat;
}
 
Example #9
Source File: TextFormatBenchmarkBase.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
TextFormatBenchmarkBase(TextFormat textFormat) {
  this.textFormat = textFormat;
}
 
Example #10
Source File: BasicOperationsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
private static String encodeSpanContextText(TextFormat format, SpanContext context) {
  StringBuilder builder = new StringBuilder();
  format.inject(context, builder, textSetter);
  return builder.toString();
}
 
Example #11
Source File: HttpPropagationUtilTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Test
public void cloudTraceFormatNotNull() {
  TextFormat cloudTraceFormat = HttpPropagationUtil.getCloudTraceFormat();
  assertThat(cloudTraceFormat).isNotNull();
  assertThat(cloudTraceFormat).isInstanceOf(CloudTraceFormat.class);
}
 
Example #12
Source File: OcJettyHttpClient.java    From opencensus-java with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new {@code OcJettyHttpClient} with support for HTTPS, extractor and propagator.
 *
 * @param transport {@link HttpClientTransport} The transport implementation.
 * @param sslContextFactory {@link SslContextFactory} Used to configure SSL connectors.
 * @param extractor {@link HttpExtractor} to extract request and response specific attributes. If
 *     it is null then default extractor is used.
 * @param propagator {@link TextFormat} to propagate trace context to remote peer. If it is null
 *     then default propagator (TraceContextFormat) is used.
 * @since 0.20
 */
public OcJettyHttpClient(
    HttpClientTransport transport,
    SslContextFactory sslContextFactory,
    @Nullable HttpExtractor<Request, Response> extractor,
    @Nullable TextFormat propagator) {
  super(transport, sslContextFactory);
  handler = buildHandler(extractor, propagator);
}
 
Example #13
Source File: JaxrsContainerFilter.java    From opencensus-java with Apache License 2.0 3 votes vote down vote up
/**
 * Construct instance with custom configuration.
 *
 * @param extractor the {@code HttpExtractor} used to extract information from the
 *     request/response.
 * @param propagationFormat the {@code TextFormat} used in HTTP propagation.
 * @param publicEndpoint set to true for publicly accessible HTTP(S) server. If true then incoming
 *     tracecontext will be added as a link instead of as a parent.
 */
public JaxrsContainerFilter(
    HttpExtractor<ExtendedContainerRequest, ContainerResponseContext> extractor,
    TextFormat propagationFormat,
    Boolean publicEndpoint) {
  this.handler =
      new HttpServerHandler<>(
          Tracing.getTracer(), extractor, propagationFormat, GETTER, publicEndpoint);
}
 
Example #14
Source File: OpenCensusUtils.java    From google-http-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the {@link io.opencensus.trace.propagation.TextFormat.Setter} used in context propagation.
 *
 * <p>This API allows users of google-http-client to specify other text format setter, or disable
 * context propagation by setting it to {@code null}. It should be used along with {@link
 * #setPropagationTextFormat} for setting purpose.
 *
 * @param textFormatSetter the {@code TextFormat.Setter} for the text format.
 */
public static void setPropagationTextFormatSetter(@Nullable TextFormat.Setter textFormatSetter) {
  propagationTextFormatSetter = textFormatSetter;
}
 
Example #15
Source File: OpenCensusUtils.java    From google-http-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the {@link TextFormat} used in context propagation.
 *
 * <p>This API allows users of google-http-client to specify other text format, or disable context
 * propagation by setting it to {@code null}. It should be used along with {@link
 * #setPropagationTextFormatSetter} for setting purpose.
 *
 * @param textFormat the text format.
 */
public static void setPropagationTextFormat(@Nullable TextFormat textFormat) {
  propagationTextFormat = textFormat;
}
 
Example #16
Source File: JaxrsClientFilter.java    From opencensus-java with Apache License 2.0 2 votes vote down vote up
/**
 * Construct new client filter with custom configuration.
 *
 * @param extractor the {@code HttpExtractor} used to extract information from the
 *     request/response.
 * @param propagationFormat the {@code TextFormat} used in HTTP propagation.
 */
public JaxrsClientFilter(
    HttpExtractor<ClientRequestContext, ClientResponseContext> extractor,
    TextFormat propagationFormat) {
  handler = new HttpClientHandler<>(Tracing.getTracer(), extractor, propagationFormat, SETTER);
}
 
Example #17
Source File: HttpPropagationUtil.java    From opencensus-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the Stack Driver format implementation. The header specification for this format is
 * "X-Cloud-Trace-Context: &lt;TRACE_ID&gt;/&lt;SPAN_ID&gt;[;o=&lt;TRACE_TRUE&gt;]". See this <a
 * href="https://cloud.google.com/trace/docs/support">page</a> for more information.
 *
 * @since 0.11.0
 * @return the Stack Driver format.
 */
public static TextFormat getCloudTraceFormat() {
  return new CloudTraceFormat();
}
 
Example #18
Source File: TracingAsyncClientHttpRequestInterceptor.java    From opencensus-java with Apache License 2.0 2 votes vote down vote up
/**
 * Create an instance of {@code TracingAsyncClientHttpRequestInterceptor}.
 *
 * @param extractor {@link HttpExtractor} to extract request and response specific attributes. If
 *     it is null then default extractor is used.
 * @param propagator {@link TextFormat} to propagate trace context to remote peer. If it is null
 *     then default propagator (TraceContextFormat) is used.
 * @return {@code TracingAsyncClientHttpRequestInterceptor}
 * @since 0.23.0
 */
public static TracingAsyncClientHttpRequestInterceptor create(
    @Nullable TextFormat propagator,
    @Nullable HttpExtractor<HttpRequest, ClientHttpResponse> extractor) {
  return new TracingAsyncClientHttpRequestInterceptor(propagator, extractor);
}