use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class Agent method continuePremain.
/**
* Called by the "real" premain() in the BootstrapAgent.
*/
@SuppressWarnings("unused")
public static void continuePremain(String agentArgs, Instrumentation inst, long startTime) {
final LifecycleObserver lifecycleObserver = LifecycleObserver.createLifecycleObserver(agentArgs);
if (!lifecycleObserver.isAgentSafe()) {
return;
}
// This *MUST* be done first thing in the premain
addMixinInterfacesToBootstrap(inst);
if (ServiceFactory.getServiceManager() != null) {
LOG.warning("New Relic Agent is already running! Check if more than one -javaagent switch is used on the command line.");
lifecycleObserver.agentAlreadyRunning();
return;
}
String enabled = System.getProperty(AGENT_ENABLED_PROPERTY);
if (enabled != null && !Boolean.parseBoolean(enabled)) {
LOG.warning("New Relic Agent is disabled by a system property.");
return;
}
String jvmName = System.getProperty("java.vm.name");
if (jvmName.contains("Oracle JRockit")) {
String msg = MessageFormat.format("New Relic Agent {0} does not support the Oracle JRockit JVM (\"{1}\").", Agent.getVersion(), jvmName);
LOG.warning(msg);
}
if (!tryToInitializeServiceManager(inst)) {
return;
}
try {
ServiceManager serviceManager = ServiceFactory.getServiceManager();
// The following method will immediately configure the log so that the rest of our initialization sequence
// is written to the newrelic_agent.log rather than to the console. Configuring the log also applies the
// log_level setting from the newrelic.yml so debugging levels become available here, if so configured.
serviceManager.start();
lifecycleObserver.serviceManagerStarted(serviceManager);
LOG.info(MessageFormat.format("New Relic Agent v{0} has started", Agent.getVersion()));
if (System.getProperty("newrelic.bootstrap_classpath") != null) {
// This is an obsolete system property that caused the entire Agent to be loaded on the bootstrap.
LOG.info("The \"newrelic.bootstrap_classpath\" property is no longer used. Please remove it from your configuration.");
}
LOG.info("Agent class loader: " + AgentBridge.getAgent().getClass().getClassLoader());
logAnyFilesFoundInEndorsedDirs();
if (serviceManager.getConfigService().getDefaultAgentConfig().isStartupTimingEnabled()) {
recordPremainTime(serviceManager.getStatsService(), startTime);
}
recordAgentVersion(serviceManager.getStatsService());
} catch (Throwable t) {
// There's no way to gracefully pull the agent out due to our bytecode modification and class structure changes (pointcuts).
// We're likely to throw an exception into the user's app if we try to continue.
String msg = "Unable to start New Relic Agent. Please remove -javaagent from your startup arguments and contact New Relic support.";
try {
LOG.log(Level.SEVERE, t, msg);
} catch (Throwable t2) {
}
System.err.println(msg);
if (t instanceof NoClassDefFoundError) {
String version = System.getProperty("java.version");
if (version.startsWith("9") || version.startsWith("10")) {
String message = "We currently do not support Java 9 or 10 in modular mode. If you are running with " + "it and want to use the agent, use command line flag '--add-modules' to add appropriate modules";
System.err.println(message);
} else if (version.startsWith("11") || version.startsWith("12")) {
String message = "Applications that previously relied on the command line flag '--add-modules' will no longer work with Java EE " + "dependencies. You must add all Java EE dependencies to your build file manually, and then remove the --add-modules flag for them.";
System.err.println(message);
}
}
t.printStackTrace();
System.exit(1);
}
lifecycleObserver.agentStarted();
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testPointcutGroupDisabled.
@Test
public void testPointcutGroupDisabled() {
Map<String, Object> configuration = new HashMap<>();
configuration.put("class_transformer:my_pointcut_group:enabled", true);
configuration.put("class_transformer:instrumentation_default:enabled", false);
configuration.put("app_name", "Unit Test");
configuration = buildConfigMap(configuration);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
PointCutConfiguration pointCutConfiguration = new PointCutConfiguration("PointcutClassName", "my_pointcut_group", true, agentConfig.getClassTransformerConfig());
assertTrue(pointCutConfiguration.isEnabled());
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testSpringPointcutEnabledDefaultDisabled.
@Test
public void testSpringPointcutEnabledDefaultDisabled() {
Map<String, Object> configuration = new HashMap<>();
configuration.put("class_transformer:instrumentation_default:enabled", false);
configuration.put("enable_spring_tracing", true);
configuration.put("app_name", "Unit Test");
configuration = buildConfigMap(configuration);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
assertTrue(springPointCut.isEnabled());
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testSpringPointcutEnabled.
@Test
public void testSpringPointcutEnabled() {
Map<String, Object> configuration = new HashMap<>();
configuration.put("lite_mode", true);
configuration.put("class_transformer:instrumentation_default:enabled", true);
configuration.put("enable_spring_tracing", true);
configuration.put("app_name", "Unit Test");
configuration = buildConfigMap(configuration);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
assertTrue(springPointCut.isEnabled());
}
use of com.newrelic.agent.service.ServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testSpringPointcutDisabled.
@Test
public void testSpringPointcutDisabled() {
Map<String, Object> classTransformerMap = new HashMap<>();
Map<String, Object> defaultInstrumentationSettings = new HashMap<>();
defaultInstrumentationSettings.put("enabled", false);
classTransformerMap.put(ClassTransformerConfigImpl.DEFAULT_INSTRUMENTATION, defaultInstrumentationSettings);
Map<String, Object> configSettings = new HashMap<>();
configSettings.put(AgentConfigImpl.CLASS_TRANSFORMER, classTransformerMap);
configSettings.put(AgentConfigImpl.APP_NAME, "Unit Test");
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configSettings);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
assertFalse(springPointCut.isEnabled());
}
Aggregations