Search in sources :

Example 66 with Tracer

use of io.opentracing.Tracer in project carbon-apimgt by wso2.

the class LogTracer method getTracer.

@Override
public Tracer getTracer(String serviceName) {
    boolean logEnabled = Boolean.valueOf(configuration.getFirstProperty(TracingConstants.LOG_ENABLED));
    if (logEnabled) {
        Tracer tracer = NoopTracerFactory.create();
        Reporter reporter = new TracingReporter(LogFactory.getLog(TracingConstants.TRACER));
        Tracer tracerR = new TracerR(tracer, reporter, new ThreadLocalScopeManager());
        GlobalTracer.register(tracerR);
        return tracerR;
    }
    return null;
}
Also used : ThreadLocalScopeManager(io.opentracing.util.ThreadLocalScopeManager) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) Reporter(io.opentracing.contrib.reporter.Reporter) TracerR(io.opentracing.contrib.reporter.TracerR)

Example 67 with Tracer

use of io.opentracing.Tracer in project carbon-apimgt by wso2.

the class JaegerTracer method getTracer.

@Override
public Tracer getTracer(String serviceName) {
    String hostname = configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_HOST) != null ? configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_HOST) : TracingConstants.JAEGER_DEFAULT_HOST;
    int port = configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_PORT) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_PORT)) : TracingConstants.JAEGER_DEFAULT_PORT;
    String samplerType = configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_TYPE) != null ? configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_TYPE) : TracingConstants.DEFAULT_SAMPLER_TYPE;
    float samplerParam = configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_PARAM) != null ? Float.parseFloat(configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_PARAM)) : TracingConstants.DEFAULT_SAMPLER_PARAM;
    int reporterFlushInterval = configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_FLUSH_INTERVAL) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_FLUSH_INTERVAL)) : TracingConstants.DEFAULT_REPORTER_FLUSH_INTERVAL;
    int reporterBufferSize = configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_BUFFER_SIZE) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_BUFFER_SIZE)) : TracingConstants.DEFAULT_REPORTER_BUFFER_SIZE;
    boolean tracerLogEnabled = Boolean.parseBoolean(configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) != null ? configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) : TracingConstants.DEFAULT_TRACER_LOG_ENABLED);
    Configuration.SamplerConfiguration samplerConfig = new Configuration.SamplerConfiguration().withType(samplerType).withParam(samplerParam);
    Configuration.SenderConfiguration senderConfig = new Configuration.SenderConfiguration().withAgentHost(hostname).withAgentPort(port);
    Configuration.ReporterConfiguration reporterConfig = new Configuration.ReporterConfiguration().withLogSpans(true).withFlushInterval(reporterFlushInterval).withMaxQueueSize(reporterBufferSize).withSender(senderConfig);
    Tracer tracer = new Configuration(serviceName).withSampler(samplerConfig).withReporter(reporterConfig).getTracer();
    if (tracerLogEnabled) {
        Reporter reporter = new TracingReporter(LogFactory.getLog(TracingConstants.TRACER));
        Tracer tracerR = new TracerR(tracer, reporter, new ThreadLocalScopeManager());
        GlobalTracer.register(tracerR);
        return tracerR;
    } else {
        GlobalTracer.register(tracer);
        return tracer;
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) Configuration(io.jaegertracing.Configuration) ThreadLocalScopeManager(io.opentracing.util.ThreadLocalScopeManager) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) Reporter(io.opentracing.contrib.reporter.Reporter) TracerR(io.opentracing.contrib.reporter.TracerR)

Example 68 with Tracer

use of io.opentracing.Tracer in project wildfly by wildfly.

the class TracerDynamicFeature method configure.

@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    if (config == null) {
        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);
    Tracer tracer;
    Object tracerObject = servletContext.getAttribute(SMALLRYE_OPENTRACING_TRACER);
    if (tracerObject instanceof Tracer) {
        tracer = (Tracer) tracerObject;
    } else {
        // should never happen, but if it does, there's something really wrong
        // we log a warn-level message here then
        TracingLogger.ROOT_LOGGER.noTracerAvailable();
        return;
    }
    ServerTracingDynamicFeature.Builder builder = new ServerTracingDynamicFeature.Builder(tracer).withOperationNameProvider(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())) {
            TracingLogger.ROOT_LOGGER.wrongOperationNameProvider();
        }
    }
    ServerTracingDynamicFeature delegate = builder.build();
    delegate.configure(resourceInfo, context);
}
Also used : ServerTracingDynamicFeature(io.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature) Tracer(io.opentracing.Tracer)

Example 69 with Tracer

use of io.opentracing.Tracer in project wildfly by wildfly.

the class TracingDeploymentProcessor method injectTracer.

private void injectTracer(DeploymentPhaseContext deploymentPhaseContext, CapabilityServiceSupport support) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = deploymentPhaseContext.getDeploymentUnit();
    Tracer tracer = null;
    ClassLoader initialCl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ModuleClassLoader moduleCL = module.getClassLoader();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(moduleCL);
        // Looking for GlobalTracer
        Class globalTracerClass = moduleCL.loadClass("io.opentracing.util.GlobalTracer");
        boolean isRegistered = (Boolean) globalTracerClass.getMethod("isRegistered").invoke(null);
        if (isRegistered) {
            TracingLogger.ROOT_LOGGER.alreadyRegistered();
            tracer = (Tracer) globalTracerClass.getMethod("get").invoke(null);
        } else {
            Class tracerResolverClass = moduleCL.loadClass("io.opentracing.contrib.tracerresolver.TracerResolver");
            tracer = (Tracer) tracerResolverClass.getMethod("resolveTracer").invoke(null);
        }
    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        ROOT_LOGGER.errorResolvingTracer(ex);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(initialCl);
    }
    // an application has the option to provide a TracerFactory
    String tracerConfigurationName = null;
    String serviceName = getServiceName(deploymentUnit);
    if (null == tracer) {
        if (null == serviceName || serviceName.isEmpty()) {
            // this should really not happen, as this is set by the deployment processor
            TracingLogger.ROOT_LOGGER.noServiceName();
            tracer = NoopTracerFactory.create();
        } else {
            tracerConfigurationName = getTracerConfiguration(deploymentPhaseContext);
            if (tracerConfigurationName != null) {
                if (!support.hasCapability(tracerConfigurationName)) {
                    throw new DeploymentUnitProcessingException(ROOT_LOGGER.deploymentRequiresCapability(deploymentUnit.getName(), tracerConfigurationName));
                }
                deploymentPhaseContext.getServiceTarget().addDependency(ServiceName.parse(tracerConfigurationName));
            }
            tracer = WildFlyTracerFactory.getTracer(tracerConfigurationName, serviceName);
        }
    }
    TracingCDIExtension.registerApplicationTracer(moduleCL, tracer);
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(SMALLRYE_OPENTRACING_SERVICE_NAME, serviceName));
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(SMALLRYE_OPENTRACING_TRACER, tracer));
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(SMALLRYE_OPENTRACING_TRACER_MANAGED, true));
    deploymentUnit.putAttachment(ATTACHMENT_KEY, tracer);
    TracingLogger.ROOT_LOGGER.registeringTracer(tracer.getClass().getName());
    addJaxRsIntegration(deploymentUnit);
    TracingLogger.ROOT_LOGGER.initializing(tracer.toString());
    DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    if (serviceName != null) {
        if (tracerConfigurationName == null) {
            deploymentResourceSupport.getDeploymentSubsystemModel(SubsystemExtension.SUBSYSTEM_NAME).get(TRACER_CONFIGURATION_NAME).set("io.opentracing.Tracer");
            deploymentResourceSupport.getDeploymentSubsystemModel(SubsystemExtension.SUBSYSTEM_NAME).get(TRACER_CONFIGURATION).set(WildFlyTracerFactory.getModel(null, serviceName));
        } else {
            deploymentResourceSupport.getDeploymentSubsystemModel(SubsystemExtension.SUBSYSTEM_NAME).get(TRACER_CONFIGURATION_NAME).set(tracerConfigurationName);
            deploymentResourceSupport.getDeploymentSubsystemModel(SubsystemExtension.SUBSYSTEM_NAME).get(TRACER_CONFIGURATION).set(WildFlyTracerFactory.getModel(tracerConfigurationName, serviceName));
        }
    } else {
        deploymentResourceSupport.getDeploymentSubsystemModel(SubsystemExtension.SUBSYSTEM_NAME).get(TRACER_CONFIGURATION_NAME).set(tracer.getClass().getName());
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) Tracer(io.opentracing.Tracer) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 70 with Tracer

use of io.opentracing.Tracer in project wildfly by wildfly.

the class WildFlyClientTracingRegistrarProvider method configure.

@Override
public ClientBuilder configure(ClientBuilder clientBuilder, ExecutorService executorService) {
    Tracer tracer = CDI.current().select(Tracer.class).get();
    ResteasyClientBuilder resteasyClientBuilder = (ResteasyClientBuilder) clientBuilder;
    return resteasyClientBuilder.executorService(new TracedExecutorService(executorService, tracer)).register(new SmallRyeClientTracingFeature(tracer));
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) SmallRyeClientTracingFeature(io.smallrye.opentracing.SmallRyeClientTracingFeature) Tracer(io.opentracing.Tracer) TracedExecutorService(io.opentracing.contrib.concurrent.TracedExecutorService)

Aggregations

Tracer (io.opentracing.Tracer)104 Span (io.opentracing.Span)49 SpanContext (io.opentracing.SpanContext)30 Map (java.util.Map)21 Vertx (io.vertx.core.Vertx)19 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 Test (org.junit.jupiter.api.Test)19 Future (io.vertx.core.Future)18 Buffer (io.vertx.core.buffer.Buffer)16 HttpURLConnection (java.net.HttpURLConnection)14 EventBus (io.vertx.core.eventbus.EventBus)13 JsonObject (io.vertx.core.json.JsonObject)12 Objects (java.util.Objects)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tags (io.opentracing.tag.Tags)9 Scope (io.opentracing.Scope)8 GlobalTracer (io.opentracing.util.GlobalTracer)8