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;
}
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;
}
}
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);
}
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());
}
}
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));
}
Aggregations