@@ -107,8 +107,19 @@ private static void start(Instrumentation instrumentation, File agentJarFile) th
107107
108108 Properties properties = new Properties ();
109109 properties .put ("additional.bootstrap.package.prefixes" , "com.microsoft.applicationinsights.agent.bootstrap" );
110- properties .put ("experimental.log.capture.threshold" , getThreshold (config , "WARN" ));
111- properties .put ("micrometer.step.millis" , Integer .toString (getReportingIntervalMillis (config , 60000 )));
110+ properties .put ("experimental.log.capture.threshold" , getLoggingThreshold (config , "WARN" ));
111+ properties .put ("micrometer.step.millis" , Integer .toString (getMicrometerReportingIntervalMillis (config , 60000 )));
112+ if (!isInstrumentationEnabled (config , "micrometer" )) {
113+ properties .put ("ota.integration.micrometer.enabled" , "false" );
114+ }
115+ if (!isInstrumentationEnabled (config , "jdbc" )) {
116+ properties .put ("ota.integration.jdbc.enabled" , "false" );
117+ }
118+ if (!isInstrumentationEnabled (config , "logging" )) {
119+ properties .put ("ota.integration.log4j.enabled" , "false" );
120+ properties .put ("ota.integration.java-util-logging.enabled" , "false" );
121+ properties .put ("ota.integration.logback.enabled" , "false" );
122+ }
112123 properties .put ("experimental.controller-and-view.spans.enabled" , "false" );
113124 properties .put ("http.server.error.statuses" , "400-599" );
114125 ConfigOverride .set (properties );
@@ -198,7 +209,7 @@ private static boolean hasConnectionStringOrInstrumentationKey(InstrumentationSe
198209 || !Strings .isNullOrEmpty (System .getenv ("APPINSIGHTS_INSTRUMENTATIONKEY" ));
199210 }
200211
201- private static String getThreshold (InstrumentationSettings config , String defaultValue ) {
212+ private static String getLoggingThreshold (InstrumentationSettings config , String defaultValue ) {
202213 Map <String , Object > logging = config .preview .instrumentation .get ("logging" );
203214 if (logging == null ) {
204215 return defaultValue ;
@@ -218,20 +229,36 @@ private static String getThreshold(InstrumentationSettings config, String defaul
218229 return threshold ;
219230 }
220231
221- private static int getReportingIntervalMillis (InstrumentationSettings config , int defaultValue ) {
232+ private static boolean isInstrumentationEnabled (InstrumentationSettings config , String instrumentationName ) {
233+ Map <String , Object > properties = config .preview .instrumentation .get (instrumentationName );
234+ if (properties == null ) {
235+ return true ;
236+ }
237+ Object value = properties .get ("enabled" );
238+ if (value == null ) {
239+ return true ;
240+ }
241+ if (!(value instanceof Boolean )) {
242+ startupLogger .warn ("{} enabled must be a boolean, but found: {}" , instrumentationName , value .getClass ());
243+ return true ;
244+ }
245+ return (Boolean ) value ;
246+ }
247+
248+ private static int getMicrometerReportingIntervalMillis (InstrumentationSettings config , int defaultValue ) {
222249 Map <String , Object > micrometer = config .preview .instrumentation .get ("micrometer" );
223250 if (micrometer == null ) {
224251 return defaultValue ;
225252 }
226- Object reportingIntervalMillisObj = micrometer .get ("reportingIntervalMillis" );
227- if (reportingIntervalMillisObj == null ) {
253+ Object value = micrometer .get ("reportingIntervalMillis" );
254+ if (value == null ) {
228255 return defaultValue ;
229256 }
230- if (!(reportingIntervalMillisObj instanceof Number )) {
231- startupLogger .warn ("micrometer reportingIntervalMillis must be a number, but found: {}" , reportingIntervalMillisObj .getClass ());
257+ if (!(value instanceof Number )) {
258+ startupLogger .warn ("micrometer reportingIntervalMillis must be a number, but found: {}" , value .getClass ());
232259 return defaultValue ;
233260 }
234- return ((Number ) reportingIntervalMillisObj ).intValue ();
261+ return ((Number ) value ).intValue ();
235262 }
236263
237264 private static ApplicationInsightsXmlConfiguration buildXmlConfiguration (InstrumentationSettings config ) {
0 commit comments