The Fabasoft app.telemetry JavaScript API was introduced in the Summer Release 2009 and allows you to instrument any JavaScript application with instrumentation points to see what's going on in complex web applications.
In order to use the JavaScript API in your web application, you only have to include the softwaretelemetry.js SDK file and use the predefined functions and constants.
All of the constants mentioned below are defined in the JavaScript API file softwaretelemetry.js on the global object called “apm”.
apm.version contains the version number of the used script.
Example: alert(apm.version) // => “17.2.7”
Flags are used to specify the type of an event and are passed as argument to every event call.
Name | Value | Description |
---|---|---|
apm.FLAG_NONE | 0 | normal event |
apm.FLAG_ENTER | 1 | indicates a starting point |
apm.FLAG_LEAVE | 2 | indicates an ending point |
apm.FLAG_WAIT | 4 | indicates a wait condition |
apm.FLAG_WARNING | 8 | mark event as warning |
apm.FLAG_ERROR | 16 | mark event as error |
apm.FLAG_PROCESS_INFO | 32 | force writing SessionInfo just before the event |
An event will only be logged if the event-level is lower or equal to the value selected in the session or log-definition.
Name | Value | Description |
---|---|---|
apm.EVENT_LEVEL_LOG | 0 | for events that should always be included and for logging parameters for the request overview |
apm.EVENT_LEVEL_NORMAL | 50 | for general events for normal recording sessions |
apm.EVENT_LEVEL_DETAIL | 60 | for detail level events for detailed session analysis |
apm.EVENT_LEVEL_DEBUG | 70 | event with debugging information - highest level of precision with huge data amount and performance impact |
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 Predefined Events.
All predefined events are declared and available as global constants on the base variable “apm”.
Error/Trace Events:
Use these standard events to mark error, warning or info conditions in your application:
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 global apm object.
Some global settings for the JavaScript SDK are configured globally on the environment object “apm.env”:
Name | Default Value | Description |
---|---|---|
apm.env.url | “web.telemetry” | The address to which the JavaScript API posts its data. Important: this URL cannot point to a different domain or host as browser security prohibits this! You can of course map a virtual directory to a different server using a load-balancer or similar methods. |
apm.env.active | true | With this Boolean value you can switch the JavaScript API on or off |
apm.env.flushtimeout | 5000 (= 5 sec) | Delay for first telemetry data cache flush. You can read the currently used flushtimeout (in ms) here, but you need to use apm.SetTimeout to change the timeout … see “Method SetTimeout (JavaScript)” |
apm.env.flushinterval | 60000 (= 1 min) | Telemetry data cache flush interval (in ms). You can read the currently used flushinterval (in ms) here, but you need to use apm.SetInterval to change the interval. … see “Method SetInterval (JavaScript)” |
apm.env.eventsperflush | 500 | Number of telemetry events sent with each cache flush. |
apm.env | 30000 | Resync module registration on changes after this timeout (ms). |
apm.env.reregistertimeout | 600000 (= 10 min) | Interval (in ms) when synchronizing full registration information with agent/server. |
apm.env.exceptioncallback | null | This callback is called (if set) when an exception occurred. For details see “Exception Callback (JavaScript)” |
apm.env.navigationtiming | true | Insert Navigation Timing data before the first call to CreateContext to add visibility into the loading process of the browser to start your application. You may want to disable this if your application expects to start up after the page finished loading. |
This callback is called (if set) when an exception occurred.
There are a number of cases when this can occur:
Syntax |
---|
apm.env.exceptioncallback = function(exobj, msg); |
Parameters:
Return Value:
The return value is ignored.
Remarks:
If apm.env.exceptioncallback is not set (null), the error message and a back trace will be logged to the JavaScript (Firebug)-Console (if available).
Usage Example |
---|
apm.env.exceptioncallback = function(exobj, msg) { alert("Exception:\nObject: " + exobj + "\nMsg: " + msg); } |
Besides setting the basic configuration variables (like apm.env.url) you can modify some parameters for your needs with the following setup functions described in the next sub chapters.
Call apm.SetTimeout to change the initial timeout (delay) after which new events are being sent to the Fabasoft app.telemetry WebAPI service.
Syntax |
---|
apm.setTimeout(timeout); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
You can read the currently used interval from apm.env.flushtimeout. Altering this value directly is not recommended.
Usage Example |
---|
// if you know that an action will take 2 seconds you might raise the apm.SetTimeout(3000); |
Call apm.SetInterval to change the interval in which the JavaScript API talks to the Fabasoft app.telemetry WebAPI service.
Syntax |
---|
apm.setInterval(interval); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
Usage Example |
---|
apm.SetInterval(3000); |
Call apm.Flush to trigger immediately sending events to the Fabasoft app.telemetry WebAPI service.
Syntax |
---|
apm.Flush(sendAllEvents); |
Parameters:
Return Value:
This function does not return any value.
Call this function once to provide information about the context of the application.
Syntax |
---|
apm.RegisterApplication(appname, appid, apptiername, apptierid); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
Usage Example |
---|
apm.RegisterApplication("Software-Telemetry", "Demo", "Browser", "browser"); |
Call RegisterApplicationValue to register additional static information about your application such as the version number.
Syntax |
---|
apm.RegisterApplicationValue(valueKey, valueName, value); |
Parameters:
Return Value:
This function does not return any value.
Call this function to register modules inside your application.
Syntax |
---|
apm.RegisterModule(modulename); |
Parameters:
Return Value:
Remarks:
Usage Example |
---|
var page = apm.RegisterModule("Page"); page.RegisterEvent(1, "ButtonClicked", "ArticleID"); var module2 = apm.RegisterModule("AJAX Status"); var xhrMod = apm.GetXMLHTTPModule(); |
Call RegisterEvent on a registered module instance object to provide information about every eventid used for event tracing.
Syntax |
---|
<module-instance>.RegisterEvent(id, name, param); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
If an event has more than one parameter you need to separate the parameterdescription with semicolons (;).
Usage Example |
---|
var module = apm.RegisterModule("AJAX Request"); module.RegisterEvent(4, "RequestResult", "status;status Text"); |
Call apm.RegisterFilterValue for each valid filter value.
Syntax |
---|
apm.RegisterFilterValue(value, description); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
apm.RegisterFilterValue("Article ID", "Description for `Article ID` filter."); |
Call APMCreateContext to create a new Software-Telemetry context. If the filter value matches a currently started session filter, logging is started for the current execution flow. Make sure to call APMReleaseContext when exiting the context.
Syntax |
---|
apm.CreateContext(contextid, filter); |
Parameters:
Return Value:
Remarks:
Usage Example |
---|
var contextid = apm.CreateContext(null, "filter1"); // ... proceed with application logic and fire events apm.ReleaseContext(contextid); |
Call APMReleaseContext to finish logging this request. Make sure to call apm.ReleaseContext for every request created with apm.CreateContext.
Syntax |
---|
apm.ReleaseContext(contextid); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
Usage Example |
---|
var contextid = apm.CreateContext(null, "filter"); |
Call apm.GetContext to get a context handle, which can be passed to another thread or process. This context information is used by the analysis components to track the control flow through the distributed environment.
The acquired context handle has to be submitted (either by transmitting over the network or in another way) to the thread/process being called which associates the calling thread with itself by passing the context to the apm.AttachContext-method.
Syntax |
---|
apm.GetContext(contextid); |
Parameters:
Return Value:
Remarks:
Usage Example |
---|
var contextid = apm.CreateContext(null, "AJAX"); // pass contextToken to another function or another host //another function can use the token to asynchronously do some work apm.ReleaseContext(contextid); |
Call apm.AttachContext to restore the context acquired through apm.GetContext in another thread, process or execution flow.
Syntax |
---|
apm.AttachContext(contextid, token); |
Parameters:
Return Value:
Remarks:
Usage Example |
---|
var contextid = apm.AttachContext(null, token); //proceed with application logic and fire events apm.ReleaseContext(contextid); |
Call apm.GetSyncMark to get a synchronization handle that can be passed to another thread or process to synchronize control flow.
Syntax |
---|
apm.GetSyncMark(contextid); |
Parameters:
Return Value:
Remarks:
Usage Example |
---|
var contextid = apm.CreateContext(null, "Test"); var token = apm.GetSyncMark(contextid); |
Call apm.SetSyncMark to pass a synchronization handle you got from apm.GetSyncMark for synchronizing the sequence of events.
Syntax |
---|
apm.SetSyncMark(contextid, token); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
Usage Example |
---|
// registration,... var context = apm.CreateContext(null, "Test"); // set the sync-mark we got from the web service (if any) // or an use the response header of an AJAX call token = xhr.getResponseHeader("x-apm-telemetry-syncmark"); if (token) { module.Event(context, g_idLoaded, apm.LEVEL_DETAIL, apm.FLAG_NONE, "page loaded"); //... apm.ReleaseContext(context); |
Call Event to log events with any number of parameters.
Syntax |
---|
<module-instance>.Event(contextid, id, level, flags, [params...]); |
Parameters:
Return Value:
This function does not return any value.
Remarks:
Usage Example |
---|
var module = apm.RegisterModule("AJAX Request"); var context = apm.CreateContext(null, "filter1"); module.Event(context, 7, apm.LEVEL_DEBUG, apm.FLAG_NONE, "param1", null, "param3", 4); apm.ReleaseContext(context); |
Call apm.SendXMLHttpRequest to do a fully instrumented XMLHttpRequest including passing x-apm-telemetry-context headers to the webserver and handling x-apm-telemetry-syncmark response headers for End-2-End instrumentation.
Syntax |
---|
apm.SendXMLHttpRequest(request, async, value, callback, context); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
apmCheckServices = function() { |
Call apm.Report 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 |
---|
apm.Report(contextid, filter, reportkey, description); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
var module = apm.RegisterModule("User Reaction"); |
Call apm.ReportValue to add a key/value pair to an existing report.
Syntax |
---|
apm.ReportValue(contextid, reportkey, key, value); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
Call apm.ReportContent to add content to an existing report.
Syntax |
---|
apm.ReportContent(reportkey, filename, value, encoding, mimetype); |
Parameters:
Return Value:
This function does not return any value.
Usage Example |
---|
var module = apm.RegisterModule("User Reaction"); apm.Report(context, "filter1", reportkey, "Application has been waiting for user input"); |
Remarks:
To allow applications to post random content, Fabasoft app.telemetry WebAPI supports posting content directly to the Fabasoft app.telemetry Web-API. Provide the reportkey and the filename as URL-parameters after the "?ReportContent" tag and the send the value as POST-data content.
Usage Example – ReportContent POST |
---|
var request = new XMLHttpRequest(); |
The JavaScript API provides a full-featured implementation of a report dialog to ask the user for feedback which is sent with the other report data. When used with modern web browsers also a web-based HTML5 browser screenshot is available.
Call apm.ReportDialog to show the end user a feedback dialog which will invoke the apm.Report call with the description entered by the user and if defined it will append additional metadata information and files to the same report session.
Syntax |
---|
apm.ReportDialog(contextid, filter, reportkey, description, parentNode, metadata, formOptions); |
Parameters:
_metadata object Syntax/Example |
---|
function previewCallback(filename, fileObj) { |
_formOptions object Syntax/Example |
---|
var formOptions = { |
Return Value:
This function does not return any value.
Remarks:
The application developer can customize the texts used in the dialog and optionally can define the path where the image file resources are located.
To customize the dialog settings just overwrite the default values in the apm.env.report API variables:
Name (apm.env.report. ...) | Default Value | Description |
---|---|---|
dialogtitle | “Application Feedback” | Title displayed at the top of the dialog (heading) |
dialogpoweredby | “powered by” | Powered by… text above logo |
poweredByLogo | <empty> | optionally set a custom poweredBy logo – keep empty to use the default app.telemetry logo (will be set as img-src attribute) |
poweredByLogoLink | <empty> | optionally define a custom link target for the powered-by logo (set as a-href attribute) – keep empty to use the default URL (http://www.apptelemetry.com) |
hidePoweredBy | false | could be set to true to fully hide the powered-by logo and text |
hideBackgroundImage | false | could be set to true to hide the background image tree to save some space on the left |
enableLogoLinkToHomepage | true | if true the Logo represents a hyperlink to www.apptelemetry.com otherwise there will be no link but only the logo |
dialogtext | “Let us know your feedback:” | Default label text for main feedback input box (shown above textarea). |
dialogtextminlength | 0 | Minimum number of characters the user has to enter to be able to submit the feedback (if not fulfilled the dialogtexttooshort-text is displayed). |
dialogtextmaxlength | 1000 | Maximum number of characters the user can enter in the text-field (textarea limited with maxlength-property) - if set to 0 the length is not limited (maxlength-property not set) |
dialogtexttooshort | “The feedback you entered is too short.” | Displayed error text when user tried to send the feedback but did not enter enough text (characters) into the textarea. |
dialogsubmittext | “Send” | Label text for send/submit button. |
dialogcanceltooltip | “Cancel” | Label text for cancel/close button. |
closeonescape | true | If true the dialog will be closed (cancelled) on pressing the escape key. |
reportingunavailable | “The feedback functionality is currently unavailable.” | Text shown when feedback functionality is not available (base URL not configured correctly or webAPI not reachable). |
imagepath (ignored) | null | The imagepath parameter is not used any longer. |
scripting | true | This setting allows you to disable any scripting field functions possibly used in additional form fields. |
Additional Customization Variables (for providing metadata content):
In order to use the automatic screenshot/softwareinfo integration of the Fabasoft web browser plugin the following conditions must be fulfilled:
Otherwise you can provide your own file attachments within the metadata files list including the callback functions for getting the content and previewing the file.
Available event callbacks: (default they are not defined - null)
Data Structure (apm.env.report.data) |
---|
apm.env.report.data = { contextid, filter, key, description, } |
Special parameter access:
Internal methods to control the dialog (should only be used in exceptional cases):
Since Winter Release 2012 the app.telemetry feedback dialog supports an HTML5 screenshot to be taken and submitted via the feedback dialog without any browser plugin/addon. This feature is supported in all modern web browsers which support the HTML5-canvas element native.
To customize if the HTML5 screenshot should be enabled for your website and to customize the display texts used for the HTML5 screenshot attachment inside the feedback dialog use the following properties of the apm.env.report data object:
Name (apm.env.report. ...) | Default Value | Description |
---|---|---|
enableHTML5Screenshot | true | Enable (true) / disable (false) support and automatic rendering of HTML5 screenshot on opening the feedback dialog |
HTML5ScreenshotPreview | “Preview” | display label for preview screenshot link |
HTML5ScreenshotLoading | “loading...” | display label for preview screenshot link during loading/rendering of screenshot |
HTML5ScreenshotLabel | “Web Browser Screenshot” | display label for HTML5 screenshot file attachment listing |
HTML5ScreenshotPreviewUnavailable | “N/A” | display label for preview screenshot link if no screenshot is available or loading/rendering failed |
HTML5ScreenshotClosePreviewTitle | “Close” | Button label for close button for preview window. |
HTML5ScreenshotLoadingTimeout | 30000 | timeout (in msec) after which the loading/rendering of the HTML5 screenshot will be cancelled |
Since version 2013 Summer Release the screenshot preview was redesigned and improved supporting the following new features:
These new features …
In order to customize the label and button texts of the new screenshot preview dialog use the following configuration parameters of the apm.env.report data object:
Name (apm.env.report. ...) | Default Value | Description |
---|---|---|
screenshotPreviewTitle | “Preview” | Displayed top title for the screenshot preview dialog. |
screenshotPreviewHelpText | “Select your desired screenshot part ...” | This is the help text displayed in the preview dialog to explain the crop/mark features and give the user other hints for using this preview dialog. |
screenshotPreviewCropButtonLabel | “Crop” | Button label for the “cut/crop” feature. |
screenshotPreviewMarkButtonLabel | “Mark” | Button label for the “mark” feature. |
screenshotPreviewBlackoutButtonLabel | “Redact” | Button label for the “redact” feature. |
screenshotPreviewCancelButtonLabel | “Cancel” | Button label for the “cancel/close” preview dialog. |
screenshotPreviewOkButtonLabel | “OK” | Button label for the “ok/apply” to accept modifications and close preview dialog. |
Usage Example |
---|
... |
Call apm.HasActiveContext to test, if a software-telemetry session is active for some logging level. This information should be used to avoid costly operations preparing parameters for events that are currently not logged.
Syntax |
---|
apm.HasActiveContext(contextid, level); |
Parameters:
Return Value:
Usage Example |
---|
var context = apm.CreateContext(null, "filter value"); |
Call apm.IsConnected to test, if the application has successfully registered to a Fabasoft app.telemetry agent/WebAPI. Your application must not make any assumptions based on the return value of this function as there are many reasons that may lead to a false being returned from this function even though the communication with the WebAPI be possible in general.
Syntax |
---|
apm.IsConnected(); |
Parameters:
This function does not take any arguments.
Return Value:
Remarks:
Usage Example |
---|
apm.RegisterApplication("Fabasoft app.telemetry", "", "Client", ""); |