The Instrumentation component of the WebLogic Diagnostic Framework (WLDF) provides a mechanism for adding diagnostic code to BEA WebLogic Server® instances and the applications running on them. The key features provided by WLDF Instrumentation are:
WLDF provides a library of predefined diagnostic monitors and actions. You can also create application-scoped custom monitors, where you control the locations where diagnostic code is inserted in the application.
Instrumentation is described in the following sections:
This section introduces instrumentation concepts and terminology.
You can provide instrumentation services at the system level (servers and clusters) and at the application level. Many concepts, services, configuration options, and implementation features are the same for both. However, there are differences, and they are discussed throughout this documentation. The term “server-scoped instrumentation” refers to instrumentation configuration and features specific to WebLogic Server instances and clusters. “Application-scoped instrumentation” refers to configuration and features specific to applications deployed on WebLogic servers. The scope is built in to each monitor; you cannot modify a monitor’s scope.
Server-scoped instrumentation for a server or cluster is configured and deployed as part of a diagnostic module, an XML configuration file located in the DOMAIN_NAME
/config/diagnostics
directory, and linked from config.xml
.
Application-scoped instrumentation is also configured and deployed as a diagnostics module, in this case an XML configuration file named weblogic-diagnostics.xml
which is packaged with the application archive in the ARCHIVE_PATH
/META-INF
directory for the deployed application.
Instrumentation code is inserted into (or “woven” into) server and application code at precise locations. The following terms are used to describe these locations:
<pointcut>
. Pointcuts are described in Defining Pointcuts for Custom Monitors.<location-type>
.Note: | You cannot use WLDF diagnostic monitors with classes that have AspectJ aspects woven into the code. |
A diagnostic monitor is categorized by its scope and its type. The scope is either server-scoped or application-scoped. The type is determined by the monitor’s pointcut, diagnostic location, and actions. For example, Servlet_Around_Service
is an application-scoped delegating monitor, which can be used to trigger diagnostic actions at the entry to and at the exit of certain servlet and JSP methods.
There are three types of instrumentation diagnostic monitors:
The only standard server-scoped monitor is the DyeInjection
monitor, which you can use to create diagnostic context and to configure dye injection at the server level. For more information, see Configuring the DyeInjection Monitor to Manage Diagnostic Contexts.
The only standard application-scoped monitor is HttpSessionDebug
, which you can use to inspect an HTTP Session
object.
A delegating monitor by itself is incomplete. In order for a delegating monitor to perform any useful work, you must assign at least one action to the monitor.
Not all actions are compatible with all monitors. When you configure a delegating monitor from the Administration Console, you can choose only those actions that are appropriate for the selected monitor. If you are using WLST or editing a descriptor file manually, you must make sure that the actions are compatible with the monitors. Validation is performed when the XML file is loaded at deployment time.
See WLDF Instrumentation Library, for a list of the delegating monitors and actions provided by the WLDF Instrumentation Library.
You assign a name to a custom monitor, define the pointcut and the diagnostics location the monitor will use, and then assign actions from the set of predefined diagnostic actions. The <pointcut>
and <location type>
elements are mandatory for a custom monitor.
Table 10-1 summarizes the differences among the types of monitors.
You can restrict when a diagnostic action is triggered by setting a dye mask on a monitor. This mask determines which dye flags in the diagnostic context trigger actions. See <wldf-instrumentation-monitor> XML Elements for information on setting a dye mask for a monitor.
Note: | Diagnostic context, dye injection, and dye filtering are described in Configuring the DyeInjection Monitor to Manage Diagnostic Contexts. |
Diagnostic actions execute diagnostic code that is appropriate for the associated delegating or custom monitor (standard monitors have predefined actions). In order for a delegating or custom monitor to perform any useful work, you must configure at least one action for the monitor.
The WLDF diagnostics library provides the following actions, which you can attach to a monitor by including the action’s name in an <action>
element of the DIAG_MODULE
.xml
configuration file:
Actions must be correctly matched with monitors. For example, the TraceElapsedTime
action is compatible with a delegating or custom monitor whose diagnostic location type is around
. See WLDF Instrumentation Library. for more information.
Instrumentation is configured as part of a diagnostics descriptor, an XML configuration file, whose name and location depend on whether you are implementing system-level (server-scoped) or application-level (application-scoped) instrumentation:
DOMAIN_NAME
/config/diagnostics
This directory can contain multiple system-level diagnostic descriptor files. Filenames are arbitrary but must be terminated with.xml
(myDiag.xml
is a valid filename). Each file can contain configuration information for one or more of the deployable diagnostic components: Harvester, Instrumentation, or Watch and Notification. An <instrumentation>
section in a descriptor file can configure one or more diagnostic monitors. Server-scoped instrumentation can be enabled, disabled, and reconfigured without restarting the server.
Only one WLDF system resource (and hence one system-level diagnostics descriptor file) can be active at a time for a server (or cluster). The active descriptor is linked and targeted from the following configuration file:
DOMAIN_NAME
/config/config.xml
For more information about configuring diagnostic system modules, see Configuring Diagnostic System Modules. For general information about the creation, content, and parsing of configuration files in WebLogic Server, see Understanding Domain Configuration.
META-INF/weblogic-diagnostics.xml
Because instrumentation is the only diagnostics component that is deployable to applications, this descriptor can contain only instrumentation configuration information.
Note: | For instrumentation to be available for an application, instrumentation must be enabled on the server to which the application is deployed. (Server-scoped instrumentation is enabled and disabled in the <instrumentation> element of the diagnostics descriptor for the server.) |
You can enable and disable diagnostic monitors without redeploying an application. However, you may have to redeploy the application after modifying other instrumentation features, for example defining pointcuts or adding or removing monitors. Whether you have to redeploy depends on how you configure the instrumentation and how you deploy the application. There are three options:
For more information about these choices, see Using Deployment Plans for Dynamically Controlling Instrumentation Configuration.
For more information about deploying and modifying diagnostic application modules, see Deploying WLDF Application Modules.
The diagnostics XML schema is located at:
http://www.bea.com/ns/weblogic/90/diagnostics.xsd
See WebLogic Server Diagnostics Configuration Schema Reference for documentation.
Each diagnostics descriptor file must begin with the following lines:
<wldf-resource xmlns="http://www.bea.com/ns/weblogic/90/diagnostics"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
For an overview of WLDF resource configuration, see Understanding WLDF Configuration.
This section provides descriptor fragments and tables that summarize information about the XML elements used to configure instrumentation and the instrumentation diagnostic monitors.
<instrumentation>
element.<wldf-instrumentation-monitor>
element.
Table 10-2 describes the <instrumentation>
elements in the DIAG_MODULE
.xml
file. The following configuration fragment illustrates the use of those elements:
<wldf-resource>
<name>MyDiagnosticModule</name>
<instrumentation>
<enabled>true</enabled>
<!-- The following <include> element would apply only to an
application-scoped Instrumentation descriptor -->
<include>foo.bar.com.*</include>
<!-- <wldf-instrumentation-monitor> elements to define diagnostic
monitors for this diagnostic module -->
</instrumentation>
<!-- Other elements to configure this diagnostic module -->
</wldf-resource>
If
true , instrumentation is enabled. If false , no instrumented code will be inserted in classes in this instrumentation scope, and all diagnostic monitors within this scope are disabled. The default value is false .
You must enable instrumentation at the server level to enable instrumentation for the server and for any applications deployed to it. You must further enable instrumentation at the application level to enable instrumentation for the application (that is, in addition to enabling the server-scoped instrumentation).
|
|||||
An optional element specifying the list of classes where instrumented code can be inserted. Wildcards (
* ) are supported. You can specify multiple <include> elements. If specified, a class must satisfy an <include> pattern for it to be instrumented.
Applies only to application-scoped instrumentation. Any specified
<include> or <exclude> patterns are applied to the application scope as a whole.
As classes are loaded, they must pass an include/exclude pattern check before any instrumentation code is inserted. Even if a class passes the include/exclude pattern checks, whether or not it is instrumented depends on the diagnostic monitors included in the configuration descriptor. An application-scoped delegating monitor from the library has its own predefined classes and pointcuts. A custom monitor specifies its own pointcut expression. Therefore a class can pass the include/exclude checks and still not be instrumented.
|
|||||
Diagnostic monitors are defined in <wldf-instrumentation-monitor> elements, which are children of the <instrumentation>
element in a DIAG_MODULE
.xml
descriptor for server-scoped instrumentation or the META-INF/weblogic-diagnostics.xml
descriptor for application-scoped instrumentation.
The following fragment shows the configuration for a delegating monitor and a custom monitor in an application. (You could modify this fragment for server-scoped instrumentation by replacing the application-scoped monitors with server-scoped monitors.)
<instrumentation>
<enabled>true</enabled>
<wldf-instrumentation-monitor>
<name>Servlet_Before_Service</name>
<enabled>true</enabled>
<dye-mask>USER1</dye-mask>
<dye-filtering-enabled>true</dye-filtering-enabled>
<action>TraceAction</action>
</wldf-instrumentation-monitor>
<wldf-instrumentation-monitor>
<name>MyCustomMonitor</name>
<enabled>true</enabled>
<action>TraceAction</action>
<location-type>before</location-type>
<pointcut>call( * com.foo.bar.* get*(...));</pointcut>
</wldf-instrumentation-monitor>
</instrumentation>
Note that the Servlet_Before_Service
monitor sets a dye mask and enables dye filtering. This will be useful only if instrumentation is enabled at the server level and the DyeInjection
monitor is enabled and properly configured. See Configuring the DyeInjection Monitor to Manage Diagnostic Contexts, for information about configuring the DyeInjection
monitor.
Table 10-3 describes the <wldf-instrumentation-monitor>
elements.
The name of the monitor. For standard and delegating monitors, use the names of the predefined monitors in WLDF Instrumentation Library. For custom monitors, an arbitrary string that identifies the monitor. The name for a custom monitor must be unique; that is, it cannot duplicate the name of any monitor in the library.
|
|||||
An optional element, which applies to delegating and custom monitors. If you do not specify at least one action, the monitor will not generate any information. You can specify multiple
<action> elements. An action must be compatible with the monitor type. For the list of predefined actions for use by delegating and custom monitors, see WLDF Instrumentation Library.
|
|||||
An optional element. If dye filtering is enabled, the dye mask, when compared with the values in the diagnostic context, determines whether actions are taken. See Configuring the DyeInjection Monitor to Manage Diagnostic Contexts, for information about dyes and dye filtering.
|
|||||
An optional element. A pointcut element contains an expression that defines joinpoints where diagnostic code will be inserted.
Applies only to custom monitors; standard and delegating monitors have predefined pointcuts. A custom monitor must define a location type and a pointcut.
Pointcut syntax is documented in Defining Pointcuts for Custom Monitors
|
|||||
An optional element specifying the list of classes where instrumented code can be inserted. Wildcards (
* ) are supported. You can specify multiple <include> elements. If specified, a class must satisfy an <include> pattern for it to be instrumented.
Applies only to application-scoped instrumentation. Any specified
<include> or <exclude> patterns are applied only to the monitor defined in the parent <wldf-instrumentation-monitor> element.
As classes are loaded, they must pass an include/exclude pattern check before any instrumentation code is inserted. Even if a class passes the include/exclude pattern checks, whether or not it is instrumented depends on the diagnostic monitors included in the configuration descriptor. An application-scoped delegating monitor from the library has its own predefined classes and pointcuts. A custom monitor specifies its own pointcut expression. Therefore a class can pass the include/exclude checks and still not be instrumented.
|
|||||
Additional information on <dye-filtering-enabled>
and <dye-mask>
follows:
DyeInjection
monitor is enabled and configured for a server or a cluster, you can use dye filtering in downstream delegating and custom monitors to inspect the dyes injected into a request’s diagnostic context by that DyeInjection
monitor.DyeInjection
monitor determines which bits are set in the 64-bit dye vector associated with a diagnostic context. When the <dye-filtering-enabled>
attribute is enabled for a monitor, its diagnostic activity is suppressed if the dye vector in a request’s diagnostic context does not match the monitor’s configured dye mask. If the dye vector matches the dye mask (a bitwise AND
), the application can execute its diagnostic actions:(dye_vector & dye_mask == dye_mask)
Thus, the dye filtering mechanism allows monitors to take diagnostic actions only for specific requests, without slowing down other requests. See Configuring the DyeInjection Monitor to Manage Diagnostic Contexts, for detailed information on diagnostic contexts and dye vectors.
Table 10-4 summarizes which <wldf-instrumentation-monitor>
elements apply to which monitors.
X1
|
|||
1Currently used only by the |
To enable instrumentation at the server level, and to configure server-scoped monitors, perform the following steps:
You can have multiple DIAG_MODULE
.xml
diagnostic descriptor files in a domain, but for each server (or cluster) you can deploy only one diagnostic descriptor file at a time. One reason for creating more than one file is to give yourself flexibility. You could have, for example, five diagnostic descriptor files in the
DOMAIN_NAME
/config/diagnostics
directory. Each file contains a different instrumentation (and perhaps Harvester and Watch and Notification) configuration. You then deploy a file to a server based on which monitors you want active for specific situations.
DIAG_MODULE
.xml
file (recommended), for delegating monitors, the console displays only actions that are compatible with the monitor. If you create a configuration file with an editor or with the WebLogic Scripting Tool (WLST), you must correctly match actions to monitors.
Listing 10-1 contains a sample server-scoped instrumentation configuration file which enables instrumentation, and configures the DyeInjection
standard monitor and the Connector_Before_Work
delegating monitor. A single <instrumentation>
element contains all instrumentation configuration for the module. Each diagnostic monitor is defined in a separate <wldf-instrumentation-monitor>
element.
<wldf-resource xmlns="http://www.bea.com/ns/weblogic/90/diagnostics"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90/diagnostics.xsd">
<instrumentation>
<enabled>true</enabled>
<wldf-instrumentation-monitor>
<name>DyeInjection</name>
<description>Inject USER1 and ADDR1 dyes
</description>
<enabled>true</enabled>
<properties>USER1=weblogic
ADDR1=127.0.0.1</properties>
</wldf-instrumentation-monitor>
<wldf-instrumentation-monitor>
<name>Connector_Before_Work</name>
<enabled>true</enabled>
<action>TraceAction</action>
<dye-filtering-enabled>true</dye-filtering-enabled>
<dye-mask>USER1</dye-mask>
</wldf-instrumentation-monitor>
</instrumentation>
</wldf-resource>
At the application level, WLDF instrumentation is configured as a deployable module, which is then deployed as part of the application.
The following sections provide information you need to configure application-scoped instrumentation:
Instrumenting an application is similar to instrumenting at the system level, but with the following differences:
DyeInjection
. The only application-scoped standard monitor is HttpSessionDebug
. For more information, see the entry for HttpSessionDebug
in Diagnostic Monitor Library.
weblogic-diagnostics.xml
descriptor file. You create a META-INF/weblogic-diagnostics.xml
file, configure the instrumentation, and put the file in the application’s archive. When the archive is deployed, the instrumentation is automatically inserted when the application is loaded.The XML descriptors for application-scoped instrumentation are defined in the same way as for server-scoped instrumentation. You can configure instrumentation for an application solely by using the delegating monitors and diagnostic actions available in the WLDF Instrumentation Library. You can also create your own custom monitors; however, the diagnostic actions that you attach to these monitors must be taken from the WLDF Instrumentation Library.
Table 10-5 compares the function and scope of system and application modules.
To implement a diagnostic monitor for an application, perform the following steps:
META-INF/weblogic-diagnostics.xml
descriptor file for the application:<instrumentation>
element: <enabled>true</enabled>
See Creating a Descriptor File for a Delegating Monitor and Creating a Descriptor File for a Custom Monitor for samples of well-formed descriptor files.
See Defining Pointcuts for Custom Monitors for information on creating a pointcut expression.
The following is an example of a well-formed META-INF/weblogic-diagnostics.xml
file for an application-scoped delegating monitor:
<wldf-resource xmlns="http://www.bea.com/ns/weblogic/90/diagnostics"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90/diagnostics.xsd">
<instrumentation>
<enabled>true</enabled>
<wldf-instrumentation-monitor>
<name>Servlet_Before_Service</name>
<enabled>true</enabled>
<dye-mask>USER1</dye-mask>
<dye-filtering-enabled>true</dye-filtering-enabled>
<action>TraceAction</action>
</wldf-instrumentation-monitor>
</instrumentation>
</wldf-resource>
The Servlet_Before_Service
monitor is an application-scoped monitor selected from the WLDF monitor library. It is hardcoded with a pointcut that sets joinpoints at method entry for several servlet or JSP methods. Because the application enables dye filtering and sets the USER1
flag in its dye mask, the TraceAction
action will be invoked only when the dye vector in the diagnostic context passed to the application also has its USER1
flag set. (The dye vector is set at the system level via the DyeInjection
monitor.) Therefore, the Servlet_Before_Service
monitor in this application is essentially quiescent until it inspects a dye vector and finds the USER1
flag set. This filtering reduces the amount of diagnostic data generated, and ensures that the generated data is of interest to the administrator.
The following is an example of a well-formed META-INF/weblogic-diagnostics.xml
file for a custom monitor.
<wldf-resource xmlns="http://www.bea.com/ns/weblogic/90/diagnostics"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90/diagnostics.xsd">
<instrumentation>
<enabled>true</enabled>
<wldf-instrumentation-monitor>
<name>MyCustomMonitor</name>
<enabled>true</enabled>
<action>TraceAction</action>
<location-type>before</location-type>
<pointcut>call( * com.foo.bar.* get* (...));</pointcut>
</wldf-instrumentation-monitor>
</instrumentation>
</wldf-resource>
The <name>
for a custom monitor is an arbitrary string chosen by the developer. Because this monitor is custom, it has no predefined locations when actions should be invoked; the descriptor file must define the location type and pointcut expression. In this example, the TraceAction
action will be invoked before (<location-type>before</location-type
) any methods defined by the pointcut expression is invoked. Table 10-6 shows how the pointcut expression from Listing 10-2 is parsed. (Note the use of wildcards.)
This pointcut expression matches all get*()
methods in all classes in package com.foo.bar
and its subpackages. The methods can return values of any type, including void
, and can have any number of arguments of any type. Instrumentation code will be inserted before these methods, and, just before those methods are called, the TraceAction
action will be invoked.
See Defining Pointcuts for Custom Monitors
for a description of the grammar used to define pointcuts.
Custom monitors provide more flexibility than delegating monitors because you create pointcut expressions to control where diagnostics actions are invoked. As with delegating monitors, you must select actions from the action library.
A joinpoint is specific, well-defined location in a program. A pointcut is an expression that specifies a set of joinpoints. This section describes how you define expressions for pointcuts using the following pointcut syntax.
You can specify two types of pointcuts for custom monitors:
The syntax for defining a pointcut expression is as follows:
<pointcut> ::= [(] <joinpoint> [ <conditional> <joinpoint> ] [)]
<joinpoint> ::= [(] <execution-joinpoint> | <call-joinpoint>
<execution-pointcut> ::= execution ( <access-type> <joinpoint-signature> )
<callsite-pointcut> ::= call ( <joinpoint-signature> )
<joinpoint-signature> ::= <method-signature>
<method-signature> ::= <return-type> <class-type>.<method-name>
( <parameter-list> )
<return-type> ::= <class-type> | <primitive-type>
<parameter-list> ::= <parameter-type> [, <parameter-type>] *
<parameter-type> ::= <class-type> | <primitive-type> | <elipsis>
<class-type> ::= [<use-class-hierarchy>] ? <class-or-interface-name-pattern>
<conditional> ::= AND [NOT] | OR [NOT] | NOT
<use-class-hierarchy> ::= '+'
<elipsis> ::= '...'
*
) can be used in class types and method names. ...
) in the argument list signifies a variable number of arguments of any types beyond the argument. +
(plus sign) prefix to a class type identifies all subclasses, subinterfaces or concrete classes implementing the specified class/interface pattern.
For example, the following pointcut matches method executions of all public initialized methods in all classes in package com.foo.bar
and its subpackages. The initialized methods may return values of any type, including void
, and may have any number of arguments of any types.
execution(public * com.foo.bar.* initialize(...))
The following pointcut matches the method calls (callsites) on all classes that directly or indirectly implement the com.foo.bar.MyInterface
interface (or a subclass, if it happens to be a class). The method names must start with get
, be public, and return an int
value. The method must accept exactly one argument of type java.lang.String
:
call(int +com.foo.bar.MyInterface get*(java.lang.String))
The following example shows how to use boolean operators to build a pointcut expression tree:
call(void com.foo.bar.* set*(java.lang.String)) OR
call( * com.foo.bar.* get*())
The following example illustrates how the previous expression tree would be rendered as a <pointcut>
element in a configuration file:
<pointcut>call(void com.foo.bar.* set*(java.lang.String)) OR
call( * com.foo.bar.* get*())</pointcut>