-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from Microsoft/features/agent-automatic-addin…
…g-of-builtin-classes Way to add simple built in classes and MuleESB
- Loading branch information
Showing
6 changed files
with
289 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
...a/com/microsoft/applicationinsights/agent/internal/config/BuiltInInstrumentedClasses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* ApplicationInsights-Java | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* | ||
* MIT License | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
* software and associated documentation files (the ""Software""), to deal in the Software | ||
* without restriction, including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
* persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.microsoft.applicationinsights.agent.internal.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.microsoft.applicationinsights.agent.internal.agent.ClassInstrumentationData; | ||
import com.microsoft.applicationinsights.agent.internal.coresync.InstrumentedClassType; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.NodeList; | ||
|
||
/** | ||
* This class lets us add classes that will be a part of the 'BuiltIn' section in the AI-Agent.xml. | ||
* | ||
* This BuiltIn secion declares the classes and methods that the agent will instrument automatically. | ||
* | ||
* To add a new class you need to declare the XML tag for that class, which can be used by the user to | ||
* either disable it, or change the threshold in which telemetries are sent for its instrumented methods. | ||
* | ||
* To add a new class you can do one of the following: | ||
* | ||
* <code> | ||
* // Start define new class | ||
* builtInInstrumentedClasses.put( | ||
* // The XML tag in AI-Agent.xml (in the 'BuiltIn' section) | ||
* "NewClassLogicalName", | ||
* | ||
* new BuiltInInstrumentedClass( | ||
* // Full class name | ||
* "an.example.of.full.class.path.to.RelevantClass", | ||
* | ||
* // All methods to instrument | ||
* "method1", "method2")); | ||
* | ||
* </code> | ||
* | ||
* or (no method define, all methods will be instrumented) | ||
* <code> | ||
* // Start define new class | ||
* builtInInstrumentedClasses.put( | ||
* // The XML tag in AI-Agent.xml (in the 'BuiltIn' section) | ||
* "NewClassLogicalName", | ||
* | ||
* new BuiltInInstrumentedClass( | ||
* // Full class name | ||
* "an.example.of.full.class.path.to.RelevantClass")); | ||
* | ||
* </code> | ||
* | ||
* or (set threshold in MS. Methods that will pass this threshold will be reported) | ||
* <code> | ||
* // Start define new class | ||
* builtInInstrumentedClasses.put( | ||
* // The XML tag in AI-Agent.xml (in the 'BuiltIn' section) | ||
* "NewClassLogicalName", | ||
* | ||
* new BuiltInInstrumentedClass( | ||
* // Full class name | ||
* "an.example.of.full.class.path.to.RelevantClass", 100L)); | ||
* | ||
* </code> | ||
* | ||
* To disable the class from being instrumented you now need to go to the AI-Agent.xml and: | ||
* | ||
* <code> | ||
* <BuiltIn> | ||
* | ||
* <NewClassLogicalName enabled="false"/> | ||
* | ||
* </BuiltIn> | ||
* </code> | ||
* | ||
* To change the class threshold: | ||
* | ||
* <code> | ||
* <BuiltIn> | ||
* | ||
* <NewClassLogicalName thresholdInMS="10001"/> | ||
* | ||
* </BuiltIn> | ||
* </code> | ||
* | ||
* Created by gupele on 8/2/2016. | ||
*/ | ||
final class BuiltInInstrumentedClasses { | ||
|
||
public static class BuiltInInstrumentedClass { | ||
private final String className; | ||
private final long thresholdInMS; | ||
private ArrayList<String> methods; | ||
|
||
public BuiltInInstrumentedClass(String className) { | ||
this(className, 0, null); | ||
} | ||
|
||
public BuiltInInstrumentedClass(String className, long thresholdInMS) { | ||
this(className, thresholdInMS, null); | ||
} | ||
|
||
public BuiltInInstrumentedClass(String className, String... methods) { | ||
this(className, 0, methods); | ||
} | ||
|
||
public BuiltInInstrumentedClass(String className, long thresholdInMS, String... methods) { | ||
this.className = className.replace(".", "/"); | ||
this.thresholdInMS = thresholdInMS; | ||
this.methods = new ArrayList<String>(); | ||
if (methods != null) { | ||
for (String method : methods){ | ||
this.methods.add(method); | ||
} | ||
} | ||
} | ||
|
||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
public List<String> getMethods() { | ||
return methods; | ||
} | ||
|
||
public long getThresholdInMS() { | ||
return thresholdInMS; | ||
} | ||
} | ||
|
||
// Add the needed built in classes and methods | ||
private static final Map<String, BuiltInInstrumentedClass> builtInInstrumentedClasses; | ||
static | ||
{ | ||
builtInInstrumentedClasses = new HashMap<String, BuiltInInstrumentedClass>(); | ||
|
||
// Mule ESB 3.3.0 | ||
builtInInstrumentedClasses.put( | ||
// The XML tag in AI-Agent.xml (in the 'BuiltIn' section) | ||
"MuleESB", | ||
|
||
new BuiltInInstrumentedClass( | ||
// Full class name | ||
"org.mule.module.client.MuleClient", | ||
|
||
// All methods to instrument | ||
"dispatch", "send", "sendAsync", "sendDirect", "sendDirectAsync", "request")); | ||
} | ||
|
||
public Map<String, BuiltInInstrumentedClass> getBuiltInInstrumentedClasses() { | ||
return builtInInstrumentedClasses; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...icrosoft/applicationinsights/agent/internal/config/BuiltInInstrumentedClassesBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* ApplicationInsights-Java | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* | ||
* MIT License | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
* software and associated documentation files (the ""Software""), to deal in the Software | ||
* without restriction, including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
* persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.microsoft.applicationinsights.agent.internal.config; | ||
|
||
import com.microsoft.applicationinsights.agent.internal.agent.ClassInstrumentationData; | ||
import com.microsoft.applicationinsights.agent.internal.coresync.InstrumentedClassType; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.NodeList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by gupele on 9/5/2016. | ||
*/ | ||
public class BuiltInInstrumentedClassesBuilder { | ||
private static final String THRESHOLD_ATTRIBUTE = "Threshold"; | ||
|
||
/** | ||
* The method will go through the classes defined in {@link BuiltInInstrumentedClasses} | ||
* and will try to add them and the methods that are define for them to the instrumentation classes | ||
* @param builtInConfigurationBuilder - The builder that will later build the reflection of the configuration | ||
* @param builtInElement - The built in element where built in instrumentation is declared | ||
*/ | ||
public static void setSimpleBuiltInClasses(AgentBuiltInConfigurationBuilder builtInConfigurationBuilder, Element builtInElement) { | ||
List<ClassInstrumentationData> classes = new ArrayList<ClassInstrumentationData>(); | ||
Map<String, BuiltInInstrumentedClasses.BuiltInInstrumentedClass> classicBuiltIns = new BuiltInInstrumentedClasses().getBuiltInInstrumentedClasses(); | ||
for (Map.Entry<String, BuiltInInstrumentedClasses.BuiltInInstrumentedClass> toInstrument : classicBuiltIns.entrySet()) { | ||
NodeList nodes = builtInElement.getElementsByTagName(toInstrument.getKey()); | ||
boolean isEnabled = XmlParserUtils.getEnabled(XmlParserUtils.getFirst(nodes), toInstrument.getKey()); | ||
if (!isEnabled) { | ||
continue; | ||
} | ||
|
||
BuiltInInstrumentedClasses.BuiltInInstrumentedClass classPredefinedData = toInstrument.getValue(); | ||
|
||
Element builtInTagElement = XmlParserUtils.getFirst(nodes); | ||
long threshold = XmlParserUtils.getLongAttribute(builtInTagElement, toInstrument.getKey(), THRESHOLD_ATTRIBUTE, classPredefinedData.getThresholdInMS()); | ||
ClassInstrumentationData data = new ClassInstrumentationData(classPredefinedData.getClassName(), InstrumentedClassType.OTHER); | ||
data.setThresholdInMS(threshold); | ||
|
||
List<String> methods = classPredefinedData.getMethods(); | ||
if (methods == null) { | ||
data.addAllMethods(false, true); | ||
} else { | ||
for (String method : methods) { | ||
data.addMethod(method, "", false, true, threshold); | ||
} | ||
} | ||
|
||
classes.add(data); | ||
} | ||
builtInConfigurationBuilder.setSimpleBuiltInClasses(classes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters