AgentEndUserMonitoringConfig endUserMonitoringConfig = configurationStorage.getEndUserMonitoringConfig(); String base = endUserMonitoringConfig.getScriptBaseUrl(); beaconURLRegEx = Pattern.compile(Pattern.quote(base + JSAgentModule.BEACON_SUB_PATH), Pattern.CASE_INSENSITIVE); scriptSrcURL.append(base).append(JSAgentModule.JAVASCRIPT_URL_PREFIX); scriptSrcURL.append(JSAgentModule.JS_AGENT_REVISION).append('_'); scriptSrcURL.append(configurationStorage.getEndUserMonitoringConfig().getActiveModules()); scriptSrcURL.append(".js"); scriptTags.setSetting("relevancyThreshold", String.valueOf(endUserMonitoringConfig.getRelevancyThreshold())); scriptTags.setSetting("allowListenerInstrumentation", String.valueOf(endUserMonitoringConfig.isListenerInstrumentationAllowed()));
/** * Configuration initialization. Automatically called by spring. * * @param config * the configuration */ @Required @Autowired public void setConfiguration(IConfigurationStorage config) { if (config != null) { try { useMinifedAgent = config.getEndUserMonitoringConfig().isAgentMinificationEnabled(); } catch (StorageException e) { // NOPMD // fallback to normal agent useMinifedAgent = false; } } else { useMinifedAgent = false; } }
return false; } else if (!this.eumConfig.equals(other.eumConfig)) { return false;
@Test public void eumConfig() throws Exception { EndUserMonitoringConfig config = mock(EndUserMonitoringConfig.class); when(config.isEumEnabled()).thenReturn(true); String url = "/base/url"; when(config.getScriptBaseUrl()).thenReturn(url); String modules = "12a"; when(config.getActiveModules()).thenReturn(modules); when(config.isListenerInstrumentationAllowed()).thenReturn(false); when(config.isAgentMinificationEnabled()).thenReturn(false); when(environment.getEumConfig()).thenReturn(config); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, 0); AgentEndUserMonitoringConfig eumConfig = agentConfiguration.getEumConfig(); assertThat(eumConfig.isEnabled(), is(true)); assertThat(eumConfig.getActiveModules(), is(modules)); assertThat(eumConfig.getScriptBaseUrl(), is(url)); assertThat(eumConfig.isListenerInstrumentationAllowed(), is(false)); assertThat(eumConfig.isAgentMinificationEnabled(), is(false)); }
@Test public void testScriptInterception() throws IOException { hook = new EUMInstrumentationHook(linker, tracer, dataHandler, config, agentBuilder); String scriptUrl = eumConfig.getScriptBaseUrl() + JSAgentModule.JAVASCRIPT_URL_PREFIX + "32488_" + eumConfig.getActiveModules() + ".JS"; when(dummyRequest.getRequestURI()).thenReturn(scriptUrl); StringWriter response = new StringWriter(); PrintWriter pw = new PrintWriter(response); when(dummyResponse.getWriter()).thenReturn(pw); boolean intercepted = null != hook.beforeBody(METHOD_ID, dummyServlet, new Object[] { dummyRequest, dummyResponse }, ssc); assertThat(intercepted, equalTo(true)); assertThat(response.toString(), equalTo(AGENT_CODE)); }
@Test public void testOtherRequestsInterception() throws IOException { hook = new EUMInstrumentationHook(linker, tracer, dataHandler, config, agentBuilder); String requestUrl = eumConfig.getScriptBaseUrl() + "dontinterceptme"; when(dummyRequest.getRequestURI()).thenReturn(requestUrl); boolean intercepted = null != hook.beforeBody(METHOD_ID, dummyServlet, new Object[] { dummyRequest, dummyResponse }, ssc); assertThat(intercepted, equalTo(false)); verify(dummyResponse, never()).getWriter(); verify(dummyResponse, never()).getOutputStream(); }
/** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + (this.classCacheExistsOnCmr ? 1231 : 1237); result = (prime * result) + ((this.configurationInfo == null) ? 0 : this.configurationInfo.hashCode()); result = (prime * result) + ((this.disruptorStrategyConfig == null) ? 0 : this.disruptorStrategyConfig.hashCode()); result = (prime * result) + ((this.eumConfig == null) ? 0 : this.eumConfig.hashCode()); result = (prime * result) + ((this.exceptionSensorTypeConfig == null) ? 0 : this.exceptionSensorTypeConfig.hashCode()); result = (prime * result) + ((this.excludeClassesPatterns == null) ? 0 : this.excludeClassesPatterns.hashCode()); result = (prime * result) + ((this.initialInstrumentationResults == null) ? 0 : this.initialInstrumentationResults.hashCode()); result = (prime * result) + ((this.jmxSensorTypeConfig == null) ? 0 : this.jmxSensorTypeConfig.hashCode()); result = (prime * result) + ((this.methodSensorTypeConfigs == null) ? 0 : this.methodSensorTypeConfigs.hashCode()); result = (prime * result) + (int) (this.platformId ^ (this.platformId >>> 32)); result = (prime * result) + ((this.platformSensorTypeConfigs == null) ? 0 : this.platformSensorTypeConfigs.hashCode()); result = (prime * result) + ((this.retransformationStrategy == null) ? 0 : this.retransformationStrategy.hashCode()); result = (prime * result) + ((this.specialMethodSensorTypeConfigs == null) ? 0 : this.specialMethodSensorTypeConfigs.hashCode()); return result; }
agentConfiguration.setEumConfig(new AgentEndUserMonitoringConfig(eumConf.isEumEnabled(), eumConf.getScriptBaseUrl(), eumConf.getActiveModules(), eumConf.getRelevancyThreshold(), eumConf.isListenerInstrumentationAllowed(), eumConf.isAgentMinificationEnabled()));
@Test public void testBeaconInterception() throws IOException { hook = new EUMInstrumentationHook(linker, tracer, dataHandler, config, agentBuilder); String beaconUrl = eumConfig.getScriptBaseUrl() + JSAgentModule.BEACON_SUB_PATH; when(dummyRequest.getRequestURI()).thenReturn(beaconUrl); when(dummyRequest.getReader()).thenReturn(new BufferedReader(new StringReader(FAKE_BEACON))); boolean intercepted = null != hook.beforeBody(METHOD_ID, dummyServlet, new Object[] { dummyRequest, dummyResponse }, ssc); assertThat(intercepted, equalTo(true)); verify(this.dataHandler).insertBeacon(FAKE_BEACON); }