The Fabasoft app.telemetry Java API allows you to instrument any Java application with instrumentation points to see what's going on in complex applications.
In order to use the Software-Telemetry Java API effectively you should use the Eclipse IDE for development and set up an Eclipse Java project as described in the following chapter.
For your new Eclipse Java project you have to include the following Fabasoft app.telemetry SDK resources:
On the same server as your Java project is located, you have to have the Fabasoft app.telemetry agent installed, which includes the binary library “softwaretelemetry-java64.dll” and handles the native telemetry data processing.
A correct configured Eclipse project provides ContentAssist and Javadoc help for efficient development of an instrumented software solution.
The Java Software-Telemetry SDK is packaged all together into the Java package: com.apptelemetry.apm where the basic classes and the constants are defined.
All the constants are static members of the APM class and can be accessed in a static way.
Flags are used to specify the type of an event and are passed as argument to every event call. They are predefined by the API on the base class APM with the data type Byte and have the following possible values:
For more details about the flags and there meaning see the general chapter “Flags”.
An event will only be logged if the event-level is lower or equal to the value selected in the session or log-definition. The log levels are predefined by the API on the base class APM with the data type Byte and have the following possible values:
For more details about the log levels and there meaning see the general chapter “Log Level”.
To use a predefined module create a new APMModule object (by means of calling the constructor) with the predefined module name. This object will be used later to fire events for that module.
For a list of available standard modules with a set of predefined events see chapter “Standard Modules”.
Usage Example |
---|
APMModule mod1 = new APMModule(APM.MODULE_NAME_OS); APMModule mod2 = new APMModule(APM.MODULE_NAME_XMLHTTP); |
The SDK already provides a set of predefined events used for general purpose. For a full listing of all available predefined events see the generic chapter “
All predefined events are declared and available as global constants on the base class “APM”.
Error/Trace Events:
Use these standard events to mark error, warning or info conditions in your application:
View the language agnostic Application Properties section for an explanation of the properties listed below.
All predefined application property keys and names are available as public constants on the APM class.
View the language agnostic Application Values section for an explanation of the properties listed below.
All predefined application value keys and names are available as public constants on the APM class.
The APM class is the base class of the Software-Telemetry SDK. It contains all global defined constants as described in chapter “Constants (Java)”. Use the methods from the APM class in a static way (there is no new instance allocation required).
The APM class supports the following global static methods which do not require an application scope or status:
A detailed description of this class with all methods explained is described in chapter “APM Class and Methods (Java)”.
APMApplication is the base class for own application implementation and handles the request scope and reporting functions.
After creating an instance with the class constructor passing the application registration information, it stores the application handle inside and provides all context-specific functions for your application.
The APMApplication class supports the following instance/class methods which require an application scope and have to be called on your object instance of APMApplication:
A detailed description of this class with all methods explained is described in chapter “APMApplication Class and Methods (Java)”.
Note: At the end of your program lifecycle you should call the Unregister()-function to be sure that also the native library (JNI) objects are released (to prevent memory leaks).
APMModule is the base class for own module implementation and is used to fire instrumentation events.
After creating an instance with the class constructor passing the module name, it stores the module handle inside and provides all module-specific functions for your application.
The APMModule class supports the following instance/class methods which require a module scope and have to be called on your object instance of APMModule:
A detailed description of this class with all methods explained is described in chapter “APMModule Class and Methods (Java)”.
Note: At the end of your program lifecycle you should call the Unregister()-function to be sure that also the native library (JNI) objects are released (to prevent memory leaks).
APMParameter is used as data class for generic event parameters.
To define any parameters used in events you have to create a new APMParameter instance and add the typed parameters to that instance:
A detailed description of this class with all methods explained is described in chapter “APMParameter Class and Methods (Java)”.
The APMCompatibilityInfo class is a simple data structure providing the state and the message of the library compatibility.
The current APMCompatibilityInfo can be obtained using the public method call: APM.IsCompatible() which will return an instance of the class APMCompatibilityInfo (see “Method IsCompatible (Java)”).
Type Declaration |
---|
package com.apptelemetry.apm; public class APMCompatibilityInfo { public boolean compatible; } |
The APM class is the base class of the Software-Telemetry SDK. It contains all global defined constants as described in chapter “Constants (Java)”. Use the methods from the APM class in a static way (there is no new instance allocation required).
Remarks:
With version 2010 Fall Release the application-specific functions (CreateContext, ..., Report, ...) of the Java API where moved to the APMApplication class (see chapter “APMApplication Class and Methods (Java)”) and have to be called on an object instance of this class!
The API method IsConnected will tell you if the application (the one that is instrumented with the APM SDK) has successfully registered to an app.telemetry agent and is currently connected to the agent process.
Only when an application is successfully connected to an app.telemetry agent, Software-Telemetry data will be processed and sent to and collected by the app.telemetry server
Syntax |
---|
public static boolean IsConnected(); |
Parameters:
This function does not take any arguments.
Return Value:
Usage Example |
---|
public static void main(String[] args) { boolean apiConnected = APM.IsConnected(); System.out.println("Library connected via agent to server: " + apiConnected); } |
Call IsCompatible to check if the native library is compatible with the implementation in the current softwaretelemetry.jar archive.
Syntax |
---|
public static APMCompatibilityInfo IsCompatible(); |
Parameters:
This function does not take any arguments.
Return Value:
Remarks:
For details about the object structure of APMCompatibilityInfo see chapter “APMCompatibilityInfo (Java)”
Usage Example |
---|
public static void main(String args[]) { APMCompatibilityInfo ci = APM.IsCompatible(); if (!ci.compatible) { } else { } |
Call the DetachThread-method when processing of a particular request is suspended and will be resumed later in this or another thread in the same process. Pass the handle returned by this method to the AttachThread-method to resume processing (see “Method AttachThread (Java)”).
This functionality is in particular useful in queuing systems, where a large number of requests will be queued and processed by a small number of worker threads asynchronous to the initial request. Using the Detach-/AttachThread methods you can follow the request through the process and even measure the time spent in the queue, even if a different thread continues processing.
Syntax |
---|
public static long DetachThread() |
Parameters:
This function does not take any arguments.
Return Value:
Usage Example |
---|
public class Task { //... public void Initialize(/* ... */) app.CreateContext("filterstring"); } public void process() APM.AttachThread(tx); // process work app.ReleaseContext(); |
Remarks:
Be careful to use DetachThread and AttachThread in a balanced way. DetachThread will store the current state of the request in memory and AttachThread will remove the information from memory while restoring the request state. So calls to DetachThread lacking a continuation will leak memory and will leave the request in a "running" state. Multiple calls to AttachThread will not have an effect, because the request state is only available to the first call to AttachThread.
Call the AttachThread-method when processing of a particular request is resumed after being suspended in this or another thread of the same process. Pass the handle returned by DetachThread-method to restore the recorded state of the request.
For more details see “Method DetachThread (Java)”.
Syntax |
---|
public static void AttachThread(long transaction); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
The APMApplication class is the base class for your application registration, the context- and report-functions and the filter registration (callback or directly). It stores the application handle inside and provides all application-specific functions for your application to be called on your APMApplication object instance.
Your own application implementation may override the callback function EnumFilterValuesCallback (default implementation is empty) to provide the filters values via the callback function. Alternatively the filters may also be registered directly.
The application is registered when a new instance of the APMApplication class is being created.
Note: At the end of your program lifecycle you should call the Unregister()-function to be sure that also the native library (JNI) objects are released (to prevent memory leaks).
Syntax |
---|
public APMApplication(String appName, String appId, String appTierName, String appTierId); |
Parameters:
Usage Example |
---|
public static void main(String args[]) { APMApplication app = new APMApplication("Java Test-App", "1", "Tier", "1"); registerEvents(mod); app.CreateContext("MyFilter"); mod.Event(10, APM.EVENT_LEVEL_LOG, APM.FLAG_ENTER); app.ReleaseContext(); mod.Unregister(); } |
Call RegisterApplicationProperty to register additional application registration properties immediately after you call to the APMApplication class constructor to ensure proper operation.
Syntax |
---|
public void RegisterApplicationProperty(String propertyKey, String propertyName, String propertyValue); |
Parameters:
Remarks:
Application registration Properties cannot be changed after they have been set.
Syntax |
---|
public void RegisterApplicationValue(String valueKey, String valueName, String value); |
Parameters:
Remarks:
Application values may be changed at runtime but must not have a high change frequency and do not have any history of previous values.
Call Unregister at the end of your program to tell the Fabasoft app.telemetry agent that your program lifetime ends now.
The automatic unregister call via the object destructor may not work properly because the Java native library (JNI) also keeps a reference on the object which may prevent the destructor from run after the object is not used any longer in your application code.
The explicit call of Unregister will release any references to the APMApplication also in the Java native library (JNI).
Syntax |
---|
public void Unregister(); |
RegisterFilterValue registers application specific filter items, which may be used as filter strings in the CreateContext function. Registering the filter values helps the user selecting filters when starting Software-Telemetry sessions in the client interface.
There are two possibilities how to register the filter values for your application:
The APMApplication class is not abstract but provides an empty method body for the callback function EnumFilterValuesCallback.
This callback method will be invoked only if no application with same application name, application id and application tier has already registered filter values. Enumerate and register the filter values in the callback function. This mechanism is designed e.g. for web service farms, where the enumeration of the filters will register all users. So it is sufficient to register the filter values once on one web service instance.
Syntax |
---|
public void RegisterFilterValue(String filterValue, String filterDescription); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
You should register all filters that are available in your application so that the user can choose in the client interface from a list box.
Usage Example |
---|
// Extend the APMApplication API class with your own implementation class InstrumentedApp extends APMApplication { // own constructor invoking super constructor from base class public void EnumFilterValuesCallback() { } // InstrumentedApp |
Call CreateContext to start a new request in the Software-Telemetry context.
If the filter value matches a currently started session filter, logging is started for the current execution thread and the request will be associated with the session. You may call CreateContext more than once in one request in order to pass additional filter values. The request will start at the first CreateContext and will be finished by the first ReleaseContext. Make sure to call ReleaseContext (see “Method ReleaseContext (Java)”) when exiting the request.
A context can be regarded as a complete request that is traced through several involved threads or modules. And the full context request has a duration that spans the interval from CreateContext to ReleaseContext.
Syntax |
---|
public void CreateContext(String filtervalue); |
Parameters:
Return Value:
This function does not return any value.
See chapter “Application Properties” for more information on the app.telemetry request concept.
Usage Example |
---|
public static void main(String args[]) { |
Call ReleaseContext to indicate the end of the processing of one request. One ReleaseContext will close the request no matter how many CreateContext or AttachContext calls have been called.
Syntax |
---|
public void ReleaseContext(); |
Remarks:
If you don't call ReleaseContext the request keeps the running status until the request-timeout has been reached.
Usage Example |
---|
Call the GetContext-method to get a new context handle from the SDK.
This context handle is used to synchronize different threads/processes/modules - this helps you track the control flow through a distributed environment. The acquired context handle has to be submitted (either by transmitting over the network or in another way) to the other thread/process/module which has to call the AttachContext-method with the same context.
For more information see also “Passing Context” and “Method AttachContext (Java)”.
Syntax |
---|
public byte[] GetContext(); |
Parameters:
This function does not take any arguments.
Return Value:
Usage Example |
---|
import java.util.concurrent.locks.Lock; class InterfaceTestHelpers { static void registerEvents(APMModule module) { class InterfaceTestRunnable implements Runnable { public InterfaceTestRunnable(APMApplication app) { public void run(){ if (m_context == null) { } else { InterfaceTestHelpers.registerEvents(m_module); m_module.EventStr(101, APM.EVENT_LEVEL_DEBUG, APM.FLAG_NONE, "start of the request"); if (m_context == null) { } else { lock.unlock(); // sleep 3sec lock.lock(); m_application.SetSyncMark(m_syncMark); m_module.EventStr(101, APM.EVENT_LEVEL_DEBUG, APM.FLAG_NONE, "end of the request 1"); m_application.ReleaseContext(); } public class InterfaceTestJava { public static void main(String args[]) { // sleep 1sec // start 2 parallel application threads new Thread(app).start(); |
Call AttachContext to restore the context acquired through GetContext in another thread or process.
For more information see also “Passing Context” and “Method GetContext (Java)”.
Syntax |
---|
public void AttachContext(byte[] context); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method GetContext (Java)” |
Call the GetSyncMark-method to get a synchronization handle that can be passed to another thread/process/module to synchronize control flow.
The difference between a sync-marks and a context is:
For more information see also “Synchronizing Timeline with SyncMarks”.
Syntax |
---|
public byte[] GetSyncMark(); |
Parameters:
This function does not take any arguments.
Return Value:
Usage Example |
---|
See “Method GetContext (Java)” |
Call the SetSyncMark-method to pass and submit a synchronization handle that you got from the GetSyncMark-call to synchronize the sequence of events.
For more information see also “Synchronizing Timeline with SyncMarks”, “Method GetSyncMark (Java)” and “Method GetContext (Java)”.
Syntax |
---|
public void SetSyncMark(byte[] syncMark); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method GetContext (Java)” |
The API method HasActiveContext defined in the APMApplication class will tell you if there is currently a Software-Telemetry session for the given log level for the application (the one that is instrumented with the APM SDK) running.
This information should be used to avoid costly operations preparing parameters for events that are currently not logged.
Syntax |
---|
public boolean HasActiveContext(byte level); |
Parameters:
Return Value:
Remarks:
If the native Software-Telemetry library could not be loaded within your Java process a log statement will be sent to the Java logging facility with log level FINE and namespace com.apptelemetry.apm.APM.
Usage Example |
---|
public static void main(String[] args) { if (app.HasActiveContext(APM.EVENT_LEVEL_DETAIL) { module.EventStr(123, APM.EVENT_LEVEL_DETAIL, APM.FLAG_NONE, logmsg); // finish application logic and release context |
Call the Report-method from the APMApplication class to create a new feedback report.
The filter value will be matched to the description using the registered filter values.
Use the textual description of the feedback entered by the user or generated by the application to identify the report session later again.
Syntax |
---|
public void Report(String filtervalue, String reportkey, String description); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
public void generateReport(String username, String description, String reportkey) { app.Report(username, reportkey, description); app.ReportValue(reportkey, "username", username); // read file content into byte array and pass it to report function app.ReportContent(reportkey, "document.html", "text/html", data); |
Call ReportValue to add a key/value pair to an existing report.
For more information see "Method Report (Java)”.
Syntax |
---|
public void ReportValue(String reportkey, String key, String value); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See "Method Report (Java)” |
Call ReportContent to add content to an existing report.
For more information see "Method Report (Java)”.
Syntax |
---|
public void ReportContent(String reportkey, String filename, String mimeType, byte[] content); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See "Method Report (Java)” |
The APMModule-class represents a registered Module. You have to register a module to set telemetry points. You may register a module multiple times with the same name. Events of equally named modules will show up in the same column.
Note: At the end of your program lifecycle you should call the Unregister()-function to be sure that also the native library (JNI) objects are released (to prevent memory leaks).
The constructor registers the module with the given name directly on app.telemetry agent/server.
Syntax |
---|
public APMModule(string name); |
Call Unregister at the end of your program to tell the Fabasoft app.telemetry agent that your program lifetime ends now.
The automatic unregister call via the object destructor may not work properly because the Java native library (JNI) also keeps a reference on the object which may prevent the destructor from run after the object is not used any longer in your application code.
The explicit call of Unregister will release any references to the APMModule also in the Java native library (JNI).
Syntax |
---|
public void Unregister(); |
It is required and important to register the events used in your application in order to get the correct event names and parameter descriptions as provided. The RegisterEvent-method will tell the app.telemetry server a name for every event-ID and optionally parameter descriptions for the parameters used in the event calls.
Syntax |
---|
public void RegisterEvent(long eventid, String eventDescription, String parameterDescription); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
public class InstrumentedApplication { public void registerEvents(APMModule module) { public static void main(String[] args) { registerEvents(mod);// register all events // request and event calls |
Call the simple Event-method to log events without parameters.
Only the event-ID and the flags define the representation of the event that will be displayed with the registered event name for the used id.
This method is part of the APMModule class and has to be called on your own module implementation class.
Syntax |
---|
public void Event(long eventid, byte level, bytes flags); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
private void processData(String input) { // fire event with String parameter ... // ... process the data and do all the internal work ... // fire event with generic parameters ... // ... |
Call the EventStr-method to log events with a single textual (string) parameter.
In addition to the event-ID (with the registered event name) and the flags a single string parameter value will be logged.
For more information see “Method Event (Java)”.
Syntax |
---|
public void EventStr(long eventid, byte level, bytes flags, String param); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method Event (Java)” |
Call the EventParam-method to log events with a generic parameter structure - with any number and combination of textual (string) values and integer values (32- and 64-bit).
To use the EventParam-method you have to allocate a new APMParameter. With a few helper methods you can add values to this parameter object and finally you can use the parameter object in the event function to be logged. For details how to allocate and fill the APMParameter object see chapter “APMParameter Class and Methods (Java)”.
Syntax |
---|
public void EventParam(long eventid, byte level, byte flags, APMParameter param); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method Event (Java)” |
The APMParameter-class is an object structure for storing and managing parameter values that can be used for logging complex value structures with more than one or different type of values.
See also “Method EventParam (Java)”.
Call the APMParameter-constructor to allocate a new parameter object where you can add any number of textual (string) values and integer values (32- and 64-bit).
Syntax |
---|
public APMParameter(); |
Call the method AddInt32 on your APMParameter-instance to add a simple integer value (32-bit) to that object.
Syntax |
---|
public void AddInt32(int value); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method EventParam (Java)”. |
Call the method AddInt64 on your APMParameter-instance to add a simple integer value (64-bit) to that object.
Syntax |
---|
public void AddInt64(long value); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method EventParam (Java)”. |
Call the method AddString on your APMParameter-instance to add a textual (string) value to that object.
Syntax |
---|
public void AddString(String value); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
See “Method EventParam (Java)”. |