io.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature Java Examples

The following examples show how to use io.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature. 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: QuarkusSmallRyeTracingDynamicFeature.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public QuarkusSmallRyeTracingDynamicFeature() {
    Config config = ConfigProvider.getConfig();
    Optional<String> skipPattern = config.getOptionalValue("mp.opentracing.server.skip-pattern", String.class);
    Optional<String> operationNameProvider = config.getOptionalValue("mp.opentracing.server.operation-name-provider",
            String.class);

    ServerTracingDynamicFeature.Builder builder = new ServerTracingDynamicFeature.Builder(
            CDI.current().select(Tracer.class).get())
                    .withOperationNameProvider(OperationNameProvider.ClassNameOperationName.newBuilder())
                    .withTraceSerialization(false);
    if (skipPattern.isPresent()) {
        builder.withSkipPattern(skipPattern.get());
    }
    if (operationNameProvider.isPresent()) {
        if ("http-path".equalsIgnoreCase(operationNameProvider.get())) {
            builder.withOperationNameProvider(OperationNameProvider.WildcardOperationName.newBuilder());
        } else if (!"class-method".equalsIgnoreCase(operationNameProvider.get())) {
            logger.warn("Provided operation name does not match http-path or class-method. Using default class-method.");
        }
    }
    this.delegate = builder.build();
}
 
Example #2
Source File: AbstractParentSpanResolutionTest.java    From java-jaxrs with Apache License 2.0 6 votes vote down vote up
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new ClientTracingFeature.Builder(mockTracer).build());

    ServerTracingDynamicFeature.Builder builder = new ServerTracingDynamicFeature.Builder(mockTracer);
    if (shouldUseParentSpan()) {
        builder = builder.withJoinExistingActiveSpan(true);
    }
    ServerTracingDynamicFeature serverTracingFeature = builder.build();

    context.addFilter(new FilterHolder(new SpanFinishingFilter()),
            "/*", EnumSet.of(DispatcherType.REQUEST));

    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingFeature);
}
 
Example #3
Source File: AbstractJettyTest.java    From java-jaxrs with Apache License 2.0 6 votes vote down vote up
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingFeature =
        new ServerTracingDynamicFeature.Builder(mockTracer)
            .withOperationNameProvider(HTTPMethodOperationName.newBuilder())
            .withDecorators(Collections.singletonList(ServerSpanDecorator.STANDARD_TAGS))
            .withSkipPattern("/health")
        .build();
    // TODO clarify dispatcher types
    context.addFilter(new FilterHolder(new SpanFinishingFilter()), "/*",
        EnumSet.of(
            DispatcherType.REQUEST,
            // TODO CXF does not call AsyncListener#onComplete() without this (it calls only onStartAsync)
            DispatcherType.ASYNC));

    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingFeature);
}
 
Example #4
Source File: AbstractWildcardOperationNameTest.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingBuilder =
        new ServerTracingDynamicFeature.Builder(mockTracer)
            .withOperationNameProvider(WildcardOperationName.newBuilder())
        .build();
    context.addFilter(new FilterHolder(new SpanFinishingFilter()),
        "/*", EnumSet.of(DispatcherType.REQUEST));

    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
Example #5
Source File: AbstractClientTest.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    Tracer serverTracer = NoopTracerFactory.create();
    ServerTracingDynamicFeature serverTracingBuilder =
            new ServerTracingDynamicFeature.Builder(serverTracer)
                    .build();

    context.setAttribute(TRACER_ATTRIBUTE, serverTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, ClientBuilder.newClient());
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
Example #6
Source File: AbstractServerWithTraceNothingTest.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new ClientTracingFeature.Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingBuilder =
            new ServerTracingDynamicFeature.Builder(mockTracer)
                    .withTraceNothing() // This should only trace @Traced annotations, per documentation!
                    .build();
    context.addFilter(new FilterHolder(new SpanFinishingFilter()),
            "/*", EnumSet.of(DispatcherType.REQUEST));

    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
Example #7
Source File: AbstractClassOperationNameTest.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTracing(ServletContextHandler context) {
  client.register(new Builder(mockTracer).build());

  ServerTracingDynamicFeature serverTracingBuilder =
      new ServerTracingDynamicFeature.Builder(mockTracer)
          .withOperationNameProvider(ClassNameOperationName.newBuilder())
          .build();
  context.addFilter(new FilterHolder(new SpanFinishingFilter()),
      "/*", EnumSet.of(DispatcherType.REQUEST));

  context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
  context.setAttribute(CLIENT_ATTRIBUTE, client);
  context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
Example #8
Source File: InstrumentedRestApplication.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
public InstrumentedRestApplication(@Context ServletContext context) {
    this.serverTracingFeature = (ServerTracingDynamicFeature) context.getAttribute(
            AbstractJettyTest.SERVER_TRACING_FEATURE);
    this.client = (Client) context.getAttribute(AbstractJettyTest.CLIENT_ATTRIBUTE);
    this.tracer = (Tracer) context.getAttribute(AbstractJettyTest.TRACER_ATTRIBUTE);

    if (serverTracingFeature == null || client == null || tracer == null) {
        throw new IllegalArgumentException("Instrumented application is not initialized correctly. serverTracing:"
                + serverTracingFeature + ", clientTracing: " + client);
    }
}
 
Example #9
Source File: AbstractServerDefaultConfigurationTest.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingBuilder =
            new ServerTracingDynamicFeature.Builder(mockTracer)
                    .build();
    context.addFilter(new FilterHolder(new SpanFinishingFilter()),
        "/*", EnumSet.of(DispatcherType.REQUEST));

    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
Example #10
Source File: JerseyConfig.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Inject
public JerseyConfig(Tracer tracer) {
    Client client = ClientBuilder.newClient();
    client.register(new Builder(tracer).build());

    register(new ServerTracingDynamicFeature.Builder(tracer)
            .build());

    register(new TestHandler(tracer, client));
}
 
Example #11
Source File: EndpointConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public EndpointConfig(@Value("${info.app.version:unspecified}") String applicationVersion,
        @Value("${environment.structuredevent.rest.enabled:false}") Boolean auditEnabled,
        List<ExceptionMapper<?>> exceptionMappers, ServerTracingDynamicFeature serverTracingDynamicFeature,
        ClientTracingFeature clientTracingFeature) {

    this.applicationVersion = applicationVersion;
    this.auditEnabled = auditEnabled;
    this.exceptionMappers = exceptionMappers;
    registerEndpoints();
    registerExceptionMappers();
    registerSwagger();
    register(serverTracingDynamicFeature);
    register(clientTracingFeature);
}
 
Example #12
Source File: TracingConfiguration.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public ServerTracingDynamicFeature serverTracingDynamicFeature() {
    ServerTracingDynamicFeature.Builder serverTracingFeatureBuilder = new ServerTracingDynamicFeature.Builder(tracer);
    serverTracingFeatureBuilder.withTraceSerialization(false);
    serverTracingFeatureBuilder.withDecorators(List.of(new SpanDecorator()));
    return serverTracingFeatureBuilder.build();
}
 
Example #13
Source File: DiscoverableServerTracingFeature.java    From java-jaxrs with Apache License 2.0 4 votes vote down vote up
public DiscoverableServerTracingFeature() {
  this.tracingFeature = new ServerTracingDynamicFeature.Builder(GlobalTracer.get())
      .withTraceSerialization(false)
      .build();
}
 
Example #14
Source File: Driver.java    From batfish with Apache License 2.0 4 votes vote down vote up
private static void mainRunWorkService() {
  if (_mainSettings.getTracingEnable() && !GlobalTracer.isRegistered()) {
    initTracer();
  }

  String protocol = _mainSettings.getSslDisable() ? "http" : "https";
  String baseUrl = String.format("%s://%s", protocol, _mainSettings.getServiceBindHost());
  URI baseUri = UriBuilder.fromUri(baseUrl).port(_mainSettings.getServicePort()).build();
  _mainLogger.debug(String.format("Starting server at %s\n", baseUri));
  ResourceConfig rc = new ResourceConfig(Service.class).register(new JettisonFeature());
  if (_mainSettings.getTracingEnable()) {
    rc.register(ServerTracingDynamicFeature.class);
  }
  try {
    HttpServer server;
    if (_mainSettings.getSslDisable()) {
      server = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
    } else {
      server =
          CommonUtil.startSslServer(
              rc,
              baseUri,
              _mainSettings.getSslKeystoreFile(),
              _mainSettings.getSslKeystorePassword(),
              _mainSettings.getSslTrustAllCerts(),
              _mainSettings.getSslTruststoreFile(),
              _mainSettings.getSslTruststorePassword(),
              ConfigurationLocator.class,
              Driver.class);
    }
    int selectedListenPort = server.getListeners().iterator().next().getPort();
    if (_mainSettings.getCoordinatorRegister()) {
      // this function does not return until registration succeeds
      registerWithCoordinatorPersistent(selectedListenPort);
    }

    // sleep indefinitely, check for coordinator each time
    while (true) {
      Thread.sleep(COORDINATOR_CHECK_INTERVAL_MS);
      /*
       * every time we wake up, we check if the coordinator has polled us recently
       * if not, re-register the service. the coordinator might have died and come back.
       */
      if (_mainSettings.getCoordinatorRegister()
          && new Date().getTime() - _lastPollFromCoordinator.getTime()
              > COORDINATOR_POLL_TIMEOUT_MS) {
        // this function does not return until registration succeeds
        registerWithCoordinatorPersistent(selectedListenPort);
      }
    }
  } catch (ProcessingException e) {
    String msg = "FATAL ERROR: " + e.getMessage() + "\n";
    _mainLogger.error(msg);
    System.exit(1);
  } catch (Exception ex) {
    String stackTrace = Throwables.getStackTraceAsString(ex);
    _mainLogger.error(stackTrace);
    System.exit(1);
  }
}