io.opencensus.trace.Tracing Java Examples

The following examples show how to use io.opencensus.trace.Tracing. 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: MultiSpansTracing.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Main method.
 *
 * @param args the main arguments.
 */
public static void main(String[] args) {

  // WARNING: Be careful before you set sampler value to always sample, especially in
  // production environment. Trace data is often very large in size and is expensive to
  // collect. This is why rather than collecting traces for every request(i.e. alwaysSample),
  // downsampling is prefered.
  //
  // By default, OpenCensus provides a probabilistic sampler that will trace once in every
  // 10,000 requests, that's why if default probabilistic sampler is used
  // you might not see trace data printed or exported and this is expected behavior.

  TraceConfig traceConfig = Tracing.getTraceConfig();
  traceConfig.updateActiveTraceParams(
      traceConfig.getActiveTraceParams().toBuilder().setSampler(Samplers.alwaysSample()).build());

  LoggingTraceExporter.register();
  doWork();

  // Wait for a duration longer than reporting duration (5s) to ensure spans are exported.
  // Spans are exported every 5 seconds
  sleep(5100);
}
 
Example #2
Source File: AbstractManagedChannelImplBuilder.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
final List<ClientInterceptor> getEffectiveInterceptors() {
  List<ClientInterceptor> effectiveInterceptors =
      new ArrayList<>(this.interceptors);
  temporarilyDisableRetry = false;
  if (statsEnabled) {
    temporarilyDisableRetry = true;
    CensusStatsModule censusStats = this.censusStatsOverride;
    if (censusStats == null) {
      censusStats = new CensusStatsModule(GrpcUtil.STOPWATCH_SUPPLIER, true);
    }
    // First interceptor runs last (see ClientInterceptors.intercept()), so that no
    // other interceptor can override the tracer factory we set in CallOptions.
    effectiveInterceptors.add(
        0, censusStats.getClientInterceptor(recordStartedRpcs, recordFinishedRpcs));
  }
  if (tracingEnabled) {
    temporarilyDisableRetry = true;
    CensusTracingModule censusTracing =
        new CensusTracingModule(Tracing.getTracer(),
            Tracing.getPropagationComponent().getBinaryFormat());
    effectiveInterceptors.add(0, censusTracing.getClientInterceptor());
  }
  return effectiveInterceptors;
}
 
Example #3
Source File: AbstractServerImplBuilder.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
final List<ServerStreamTracer.Factory> getTracerFactories() {
  ArrayList<ServerStreamTracer.Factory> tracerFactories =
      new ArrayList<ServerStreamTracer.Factory>();
  if (statsEnabled) {
    CensusStatsModule censusStats = this.censusStatsOverride;
    if (censusStats == null) {
      censusStats = new CensusStatsModule(GrpcUtil.STOPWATCH_SUPPLIER, true);
    }
    tracerFactories.add(
        censusStats.getServerTracerFactory(recordStartedRpcs, recordFinishedRpcs));
  }
  if (tracingEnabled) {
    CensusTracingModule censusTracing =
        new CensusTracingModule(Tracing.getTracer(),
            Tracing.getPropagationComponent().getBinaryFormat());
    tracerFactories.add(censusTracing.getServerTracerFactory());
  }
  tracerFactories.addAll(streamTracerFactories);
  return tracerFactories;
}
 
Example #4
Source File: Poller.java    From spanner-event-exporter with Apache License 2.0 6 votes vote down vote up
private void configureTracing() {
  try {
    // Installs a handler for /tracez page.
    ZPageHandlers.startHttpServerAndRegisterAll(8080);
    // Installs an exporter for stack driver traces.
    StackdriverExporter.createAndRegister();
    Tracing.getExportComponent()
        .getSampledSpanStore()
        .registerSpanNamesForCollection(Arrays.asList(SAMPLE_SPAN));

    // Installs an exporter for stack driver stats.
    StackdriverStatsExporter.createAndRegister();
    RpcViews.registerAllCumulativeViews();
  } catch (IOException e) {
    log.error("Could not start the tracing server", e);
  }
}
 
Example #5
Source File: ElasticsearchTraceExporter.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and registers the ElasticsearchTraceExporter to the OpenCensus.
 *
 * @param elasticsearchTraceConfiguration {@link ElasticsearchTraceConfiguration}
 * @throws MalformedURLException when the Elasticsearch url is invalid.
 * @throws IllegalStateException if ElasticsearchTraceExporter is already created.
 * @throws IllegalArgumentException when mandatory parameters in the configuration are missing.
 * @since 0.20.0
 */
@SuppressWarnings("nullness")
public static void createAndRegister(
    ElasticsearchTraceConfiguration elasticsearchTraceConfiguration)
    throws MalformedURLException {
  synchronized (monitor) {
    Preconditions.checkState(handler == null, "Elasticsearch exporter already registered.");
    Preconditions.checkArgument(
        elasticsearchTraceConfiguration != null, "Elasticsearch " + "configuration not set.");
    Preconditions.checkArgument(
        elasticsearchTraceConfiguration.getElasticsearchIndex() != null,
        "Elasticsearch index not specified");
    Preconditions.checkArgument(
        elasticsearchTraceConfiguration.getElasticsearchType() != null,
        "Elasticsearch type not specified");
    Preconditions.checkArgument(
        elasticsearchTraceConfiguration.getElasticsearchUrl() != null,
        "Elasticsearch URL not specified");
    handler = new ElasticsearchTraceHandler(elasticsearchTraceConfiguration);
    register(Tracing.getExportComponent().getSpanExporter(), handler);
  }
}
 
Example #6
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 #7
Source File: MultiSpansScopedTracing.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Main method.
 *
 * @param args the main arguments.
 */
public static void main(String[] args) {

  // WARNING: Be careful before you set sampler value to always sample, especially in
  // production environment. Trace data is often very large in size and is expensive to
  // collect. This is why rather than collecting traces for every request(i.e. alwaysSample),
  // downsampling is prefered.
  //
  // By default, OpenCensus provides a probabilistic sampler that will trace once in every
  // 10,000 requests, that's why if default probabilistic sampler is used
  // you might not see trace data printed or exported and this is expected behavior.

  TraceConfig traceConfig = Tracing.getTraceConfig();
  traceConfig.updateActiveTraceParams(
      traceConfig.getActiveTraceParams().toBuilder().setSampler(Samplers.alwaysSample()).build());

  LoggingTraceExporter.register();
  try (Scope ss = tracer.spanBuilderWithExplicitParent("MyRootSpan", null).startScopedSpan()) {
    doWork();
  }

  // Wait for a duration longer than reporting duration (5s) to ensure spans are exported.
  // Spans are exported every 5 seconds
  sleep(5100);
}
 
Example #8
Source File: TelemetryUtils.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
public static boolean setupExporter() {
  boolean enable = setupStackdriverTraceExporter();
  setupStackdriverStatsExporter();
  if (enable) {
    TraceConfig traceConfig = Tracing.getTraceConfig();
    traceConfig.updateActiveTraceParams(
        traceConfig
            .getActiveTraceParams()
            .toBuilder()
            .setSampler(PROBABILITY_SAMPLER_MIDDLE)
            .build());
    enabledExporter = true;
    System.setProperty("meghanada.stackdriver.enable", "true");
    java.util.logging.LogManager.getLogManager().reset();
  }
  return enable;
}
 
Example #9
Source File: DatadogTraceExporter.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and registers the Datadog Trace exporter to the OpenCensus library. Only one Datadog
 * exporter can be registered at any point.
 *
 * @param configuration the {@code DatadogTraceConfiguration} used to create the exporter.
 * @throws MalformedURLException if the agent URL is invalid.
 * @since 0.19
 */
public static void createAndRegister(DatadogTraceConfiguration configuration)
    throws MalformedURLException {
  synchronized (monitor) {
    checkState(handler == null, "Datadog exporter is already registered.");

    String agentEndpoint = configuration.getAgentEndpoint();
    String service = configuration.getService();
    String type = configuration.getType();

    final DatadogExporterHandler exporterHandler =
        new DatadogExporterHandler(agentEndpoint, service, type, configuration.getDeadline());
    handler = exporterHandler;
    Tracing.getExportComponent()
        .getSpanExporter()
        .registerHandler(REGISTER_NAME, exporterHandler);
  }
}
 
Example #10
Source File: HttpServletFilterIntegrationTests.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setup() {
  super.setup();
  handler = new TestHandler();

  SpanExporter exporter = Tracing.getExportComponent().getSpanExporter();
  exporter.registerHandler("testing", handler);

  TraceParams params =
      Tracing.getTraceConfig()
          .getActiveTraceParams()
          .toBuilder()
          .setSampler(Samplers.alwaysSample())
          .build();
  Tracing.getTraceConfig().updateActiveTraceParams(params);
}
 
Example #11
Source File: ZipkinTraceExporter.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and registers the Zipkin Trace exporter to the OpenCensus library. Only one Zipkin
 * exporter can be registered at any point.
 *
 * @param configuration configuration for this exporter.
 * @throws IllegalStateException if a Zipkin exporter is already registered.
 * @since 0.22
 */
public static void createAndRegister(ZipkinExporterConfiguration configuration) {
  synchronized (monitor) {
    checkState(handler == null, "Zipkin exporter is already registered.");
    Sender sender = configuration.getSender();
    if (sender == null) {
      sender = URLConnectionSender.create(configuration.getV2Url());
    }
    Handler newHandler =
        new ZipkinExporterHandler(
            configuration.getEncoder(),
            sender,
            configuration.getServiceName(),
            configuration.getDeadline());
    handler = newHandler;
    register(Tracing.getExportComponent().getSpanExporter(), newHandler);
  }
}
 
Example #12
Source File: TraceStrategyImpl.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Override
public void endScope(Closeable scope, @Nullable Throwable throwable) {
  checkNotNull(scope, "scope");

  if (throwable != null) {
    Tracing.getTracer()
        .getCurrentSpan()
        .setStatus(
            Status.UNKNOWN.withDescription(
                throwable.getMessage() == null
                    ? throwable.getClass().getSimpleName()
                    : throwable.getMessage()));
  }

  try {
    scope.close();
  } catch (IOException ex) {
    // Ignore.
  }
}
 
Example #13
Source File: TraceWebAsyncClientAutoConfigurationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  handler = new TestHandler();

  SpanExporter exporter = Tracing.getExportComponent().getSpanExporter();
  exporter.registerHandler("testing", handler);

  TraceParams params =
      Tracing.getTraceConfig()
          .getActiveTraceParams()
          .toBuilder()
          .setSampler(Samplers.alwaysSample())
          .build();
  Tracing.getTraceConfig().updateActiveTraceParams(params);
}
 
Example #14
Source File: CensusSpringAspectTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  handler = new TestHandler();

  SpanExporter exporter = Tracing.getExportComponent().getSpanExporter();
  exporter.registerHandler("testing", handler);

  TraceParams params =
      Tracing.getTraceConfig()
          .getActiveTraceParams()
          .toBuilder()
          .setSampler(Samplers.alwaysSample())
          .build();
  Tracing.getTraceConfig().updateActiveTraceParams(params);
}
 
Example #15
Source File: InstanaTraceExporter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and registers the Instana Trace exporter to the OpenCensus library. Only one Instana
 * exporter can be registered at any point.
 *
 * @param configuration Configuration for InstanaTraceExporter.
 * @throws MalformedURLException if the agentEndpoint is not a valid http url.
 * @throws IllegalStateException if a Instana exporter is already registered.
 * @since 0.22
 */
public static void createAndRegister(InstanaExporterConfiguration configuration)
    throws MalformedURLException {
  synchronized (monitor) {
    checkState(handler == null, "Instana exporter is already registered.");
    Handler newHandler =
        new InstanaExporterHandler(
            new URL(configuration.getAgentEndpoint()), configuration.getDeadline());
    handler = newHandler;
    register(Tracing.getExportComponent().getSpanExporter(), newHandler);
  }
}
 
Example #16
Source File: InstanaTraceExporter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Unregisters the Instana Trace exporter from the OpenCensus library.
 *
 * @throws IllegalStateException if a Instana exporter is not registered.
 * @since 0.12
 */
public static void unregister() {
  synchronized (monitor) {
    checkState(handler != null, "Instana exporter is not registered.");
    unregister(Tracing.getExportComponent().getSpanExporter());
    handler = null;
  }
}
 
Example #17
Source File: TraceStrategyImpl.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
@Override
public Closeable startScopedSpan(String spanName) {
  checkNotNull(spanName, "spanName");

  return Tracing.getTracer()
      .spanBuilder(spanName)
      .setSampler(Samplers.alwaysSample())
      .setRecordEvents(true)
      .startScopedSpan();
}
 
Example #18
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 #19
Source File: HelloWorldClient.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static void initTracing() {
  TraceConfig traceConfig = Tracing.getTraceConfig();
  Logger.getRootLogger().setLevel(Level.INFO);
  traceConfig.updateActiveTraceParams(
      traceConfig.getActiveTraceParams().toBuilder().setSampler(Samplers.alwaysSample()).build());

  LoggingTraceExporter.register();
  // Register Jaeger Tracing. Refer to https://www.jaegertracing.io/docs/1.8/getting-started/ to
  // run Jaeger
  JaegerTraceExporter.createAndRegister("http://localhost:14268/api/traces", "helloworldclient");
}
 
Example #20
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 #21
Source File: OcJettyHttpClientTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testOcJettyHttpClientNonDefault() {
  OcJettyHttpClient defaultClient =
      new OcJettyHttpClient(
          null,
          null,
          new OcJettyHttpClientExtractor(),
          Tracing.getPropagationComponent().getB3Format());
  assertThat(defaultClient.handler).isNotNull();
}
 
Example #22
Source File: BasicSetup.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Enables OpenCensus metric and traces.
 *
 * <p>This will register all basic {@link io.opencensus.stats.View}s. When coupled with an agent,
 * it allows users to monitor application behavior.
 *
 * <p>Example usage for maven:
 *
 * <pre>{@code
 * <dependency>
 *   <groupId>io.opencensus</groupId>
 *   <artifactId>opencensus-contrib-observability-ready-util</artifactId>
 *   <version>${opencensus.version}</version>
 * </dependency>
 * }</pre>
 *
 * <p>It is recommended to call this method before doing any RPC call to avoid missing stats.
 *
 * <pre>{@code
 * BasicSetup.enableOpenCensus();
 * }</pre>
 *
 * @param endPoint the end point of OC-Agent.
 * @param probability the desired probability of sampling. Must be within [0.0, 1.0].
 * @since 0.25
 */
public static void enableOpenCensus(String endPoint, double probability) {
  // register basic rpc views
  RpcViews.registerAllGrpcBasicViews();

  // set sampling rate
  TraceConfig traceConfig = Tracing.getTraceConfig();
  TraceParams activeTraceParams = traceConfig.getActiveTraceParams();
  traceConfig.updateActiveTraceParams(
      activeTraceParams.toBuilder().setSampler(Samplers.probabilitySampler(probability)).build());

  String serviceName = firstNonNull(System.getenv("SERVICE_NAME"), DEAFULT_SERVICE_NAME);
  // create and register Trace Agent Exporter
  OcAgentTraceExporter.createAndRegister(
      OcAgentTraceExporterConfiguration.builder()
          .setEndPoint(endPoint)
          .setServiceName(serviceName)
          .setUseInsecure(true)
          .setEnableConfig(false)
          .build());

  // create and register Metrics Agent Exporter
  OcAgentMetricsExporter.createAndRegister(
      OcAgentMetricsExporterConfiguration.builder()
          .setEndPoint(endPoint)
          .setServiceName(serviceName)
          .setUseInsecure(true)
          .build());
}
 
Example #23
Source File: AbstractInteropTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 10000)
public void censusContextsPropagated() {
  Assume.assumeTrue("Skip the test because server is not in the same process.", server != null);
  Span clientParentSpan = Tracing.getTracer().spanBuilder("Test.interopTest").startSpan();
  // A valid ID is guaranteed to be unique, so we can verify it is actually propagated.
  assertTrue(clientParentSpan.getContext().getTraceId().isValid());
  Context ctx =
      Context.ROOT.withValues(
          TAG_CONTEXT_KEY,
          tagger.emptyBuilder().put(
              StatsTestUtils.EXTRA_TAG, TagValue.create("extra value")).build(),
          ContextUtils.CONTEXT_SPAN_KEY,
          clientParentSpan);
  Context origCtx = ctx.attach();
  try {
    blockingStub.unaryCall(SimpleRequest.getDefaultInstance());
    Context serverCtx = contextCapture.get();
    assertNotNull(serverCtx);

    FakeTagContext statsCtx = (FakeTagContext) TAG_CONTEXT_KEY.get(serverCtx);
    assertNotNull(statsCtx);
    Map<TagKey, TagValue> tags = statsCtx.getTags();
    boolean tagFound = false;
    for (Map.Entry<TagKey, TagValue> tag : tags.entrySet()) {
      if (tag.getKey().equals(StatsTestUtils.EXTRA_TAG)) {
        assertEquals(TagValue.create("extra value"), tag.getValue());
        tagFound = true;
      }
    }
    assertTrue("tag not found", tagFound);

    Span span = CONTEXT_SPAN_KEY.get(serverCtx);
    assertNotNull(span);
    SpanContext spanContext = span.getContext();
    assertEquals(clientParentSpan.getContext().getTraceId(), spanContext.getTraceId());
  } finally {
    ctx.detach(origCtx);
  }
}
 
Example #24
Source File: OcAgentTraceExporter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Unregisters the OC-Agent exporter from the OpenCensus library.
 *
 * @since 0.20
 */
public static void unregister() {
  synchronized (monitor) {
    unregister(Tracing.getExportComponent().getSpanExporter());
    handler = null;
  }
}
 
Example #25
Source File: ZPageHandlers.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static void enableRunningSpanStore() {
  if (!isRunningSpanStoreInitialized) {
    synchronized (monitor) {
      if (isRunningSpanStoreInitialized) {
        return; // Already initialized, small race
      }
      Tracing.getExportComponent().getRunningSpanStore().setMaxNumberOfSpans(Integer.MAX_VALUE);
      isRunningSpanStoreInitialized = true;
    }
  }
}
 
Example #26
Source File: StackdriverTraceExporter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Unregisters the Stackdriver Trace exporter from the OpenCensus library.
 *
 * @throws IllegalStateException if a Stackdriver exporter is not registered.
 * @since 0.12
 */
public static void unregister() {
  synchronized (monitor) {
    checkState(handler != null, "Stackdriver exporter is not registered.");
    unregister(Tracing.getExportComponent().getSpanExporter());
    handler = null;
  }
}
 
Example #27
Source File: OcHttpServletFilter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
static HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest>
    buildHttpServerHandler() {
  return buildHttpServerHandlerWithOptions(
      new OcHttpServletExtractor(),
      Tracing.getPropagationComponent().getTraceContextFormat(),
      /* publicEndpoint= */ false);
}
 
Example #28
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 #29
Source File: OcHttpServletFilter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  // only interested in http requests
  if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
    HttpServletRequest httpReq = (HttpServletRequest) request;
    HttpServletResponse httpResp = (HttpServletResponse) response;

    HttpRequestContext context = handler.handleStart(httpReq, httpReq);
    OcHttpServletListener listener = new OcHttpServletListener(handler, context);
    httpReq.setAttribute(OcHttpServletUtil.OPENCENSUS_SERVLET_LISTENER, listener);

    int length = httpReq.getContentLength();
    if (length > 0) {
      handler.handleMessageReceived(context, length);
    }

    Scope scope = Tracing.getTracer().withSpan(handler.getSpanFromContext(context));
    try {
      chain.doFilter(httpReq, httpResp);
    } finally {
      scope.close();
    }

    if (httpReq.isAsyncStarted()) {
      AsyncContext async = httpReq.getAsyncContext();
      async.addListener(listener, httpReq, httpResp);
    } else {
      OcHttpServletUtil.recordMessageSentEvent(handler, context, httpResp);
      handler.handleEnd(context, httpReq, httpResp, null);
    }
  } else {
    // pass request through unchanged
    chain.doFilter(request, response);
  }
}
 
Example #30
Source File: JaxrsContainerFilter.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("MustBeClosedChecker") // Close will happen in response filter method
public void filter(ContainerRequestContext requestContext) throws IOException {
  ExtendedContainerRequest extendedRequest = new ExtendedContainerRequest(requestContext, info);
  HttpRequestContext context = handler.handleStart(requestContext, extendedRequest);
  requestContext.setProperty(CONTEXT_PROPERTY, context);
  if (requestContext.getLength() > 0) {
    handler.handleMessageReceived(context, requestContext.getLength());
  }
  requestContext.setProperty(
      SPAN_PROPERTY, Tracing.getTracer().withSpan(handler.getSpanFromContext(context)));
}