Class Dynatrace
- java.lang.Object
-
- com.dynatrace.android.agent.Dynatrace
-
public class Dynatrace extends Object
OneAgent SDK for Android.
-
-
Constructor Summary
Constructors Constructor Description Dynatrace()
Returns theDynatrace
object
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
applyUserPrivacyOptions(UserPrivacyOptions userPrivacyOptions)
Creates a new session with the specified privacy settings and stores the privacy settings for future sessions.static void
endVisit()
Can be called to end the current visit and start a new visit.static DTXAction
enterAction(String actionName)
Enters aDTXAction
with a specified name.static DTXAction
enterAction(String actionName, DTXAction parentAction)
Enters aDTXAction
with a specified name and a parent action.static void
flushEvents()
Call this function to flush all collected events immediately.static boolean
getCaptureStatus()
Get the current data capture state.static DataCollectionLevel
getDataCollectionLevel()
Deprecated.As of version 8.191, replaced bygetUserPrivacyOptions()
static String
getRequestTag()
Returns the Dynatrace request tag which has to be set manually as HTTP header.static String
getRequestTagHeader()
Returns the Dynatrace request tag header name.static UserPrivacyOptions
getUserPrivacyOptions()
Returns the previously specified privacy settings from the user.static WebRequestTiming
getWebRequestTiming(String tag)
This represents a network timing instance for reporting the time elapsed between two user-defined events.static WebRequestTiming
getWebRequestTiming(HttpURLConnection connection)
This represents a network timing instance for reporting the time elapsed between two user-defined events.static void
identifyUser(String userId)
The current visit/session will be tagged with the provided user id.static void
identifyUser(String userId, DTXAction parentAction)
Deprecated.As of version 8.215, useidentifyUser(String)
insteadstatic void
instrumentWebView(WebView webView)
Instruments the givenWebView
to allow communication between the RUM JavaScript tag and OneAgent for Android.static boolean
isCrashReportingOptedIn()
Deprecated.As of version 8.191, replaced bygetUserPrivacyOptions()
static void
modifyUserAction(UserActionModifier modifier)
Allows to modify the currently pending user action.static void
reportError(String errorName, int errorCode)
Reports an error with a specified name and error code.static void
reportError(String errorName, Throwable throwable)
Reports an error with a specified name and aThrowable
.static void
restoreCookies()
Restores the Dynatrace cookies for the specified domains.static void
sendBizEvent(String type, JSONObject attributes)
Send a Business Event.static void
setBeaconHeaders(Map<String,String> headers)
Puts a set of http headers on every agent http request.static void
setCrashReportingOptedIn(boolean confirmed)
Deprecated.As of version 8.191, replaced byapplyUserPrivacyOptions(UserPrivacyOptions)
static void
setDataCollectionLevel(DataCollectionLevel dataCollectionLevel)
Deprecated.As of version 8.191, replaced byapplyUserPrivacyOptions(UserPrivacyOptions)
static void
setGpsLocation(Location location)
Sets a given GPS location.static void
shutdown()
Shuts down the mobile agent.static void
startup(Activity activity, com.dynatrace.android.agent.conf.Configuration configuration)
Initializing the mobile agent for capturing and reporting data.static void
startup(Application application, com.dynatrace.android.agent.conf.Configuration configuration)
Initializing the mobile agent for capturing and reporting data.static void
startup(Context context, com.dynatrace.android.agent.conf.Configuration configuration)
Deprecated.As of version 8.231, usestartup(Application, Configuration)
orstartup(Activity, Configuration)
insteadstatic void
tagRequest(HttpURLConnection conn)
Deprecated.As of version 8.255, insteadmanually obtain the request tag
and theheader key
and add them to the HTTP headers ofHttpURLConnection
.
-
-
-
Constructor Detail
-
Dynatrace
public Dynatrace() throws RuntimeException
Returns theDynatrace
object- Throws:
RuntimeException
-
-
Method Detail
-
startup
public static void startup(Application application, com.dynatrace.android.agent.conf.Configuration configuration)
Initializing the mobile agent for capturing and reporting data.This method must be called in the
Application.onCreate()
method.- Parameters:
application
- Android application contextconfiguration
- configuration object created by theDynatraceConfigurationBuilder
- Since:
- 8.231
- See Also:
startup(Activity, Configuration)
-
startup
public static void startup(Activity activity, com.dynatrace.android.agent.conf.Configuration configuration)
Initializing the mobile agent for capturing and reporting data.This method should be used, when the agent is not immediately started in the application startup phase.
- Parameters:
activity
- instance of the currently active activityconfiguration
- configuration object created by theDynatraceConfigurationBuilder
- Since:
- 8.231
- See Also:
startup(Application, Configuration)
-
startup
@Deprecated public static void startup(Context context, com.dynatrace.android.agent.conf.Configuration configuration)
Deprecated.As of version 8.231, usestartup(Application, Configuration)
orstartup(Activity, Configuration)
insteadInitializing the mobile agent for capturing and reporting data.It is recommended that this method is invoked as early as possible in your application startup sequence.
- Parameters:
context
- Android application contextconfiguration
- configuration object created by theDynatraceConfigurationBuilder
-
shutdown
public static void shutdown()
Shuts down the mobile agent.All data capturing stops. The mobile agent also attempts to flush the data for up to 5 seconds. This is done in a background thread.
-
getCaptureStatus
public static boolean getCaptureStatus()
Get the current data capture state.- Returns:
- true, if data is captured
-
setGpsLocation
public static void setGpsLocation(Location location)
Sets a given GPS location.The location is then reported along with other captured data.
- Parameters:
location
- to be saved
-
getRequestTagHeader
public static String getRequestTagHeader()
Returns the Dynatrace request tag header name.This header is used together with the tag generated by
getRequestTag()
and placed as HTTP header onto a web request.- Returns:
- the request tag header name
-
getRequestTag
public static String getRequestTag()
Returns the Dynatrace request tag which has to be set manually as HTTP header.The header key can be obtained with the method
getRequestTagHeader()
. If there is an open action in the current thread at the time the request is tagged, the web request is assigned (by the mobile agent) to the open action.- Returns:
- the request tag value or an empty string, if the mobile agent is not active
- See Also:
getRequestTagHeader()
,DTXAction.getRequestTag()
-
tagRequest
@Deprecated public static void tagRequest(HttpURLConnection conn)
Deprecated.As of version 8.255, insteadmanually obtain the request tag
and theheader key
and add them to the HTTP headers ofHttpURLConnection
.Places a Dynatrace request tag on aHttpURLConnection
web request.This tag is evaluated by the corresponding web server agent. The Dynatrace server will link the server-side PurePath data with this mobile user action.
Since there is no explicit action, the web request is correlated to an action according to the following rule:
- If there is an open action in the current thread at the time the request is tagged, the web request is assigned (by the mobile agent) to the open action.
- If there is no open action in the current thread, the web request is assigned (by the Dynatrace Server) to an action that calls its leaveAction() method in the same thread where the tagging is done. The tagging time must fall between the action enter and leave times.
- If neither of the preceding cases apply, the web request is not assigned to any action. In this case the server-side PurePath data is not linked to the mobile user action (but it can be identified as mobile traffic in the transaction flow).
- Parameters:
conn
- the request tag will be added as header to this connection- See Also:
DTXAction.tagRequest(HttpURLConnection)
-
enterAction
public static DTXAction enterAction(String actionName)
Enters aDTXAction
with a specified name.If the given
actionName
isnull
or an empty string, no reporting will happen on that action.
The generated action can be used to report the time elapsed betweenenterAction(java.lang.String)
andDTXAction.leaveAction()
. Also other event types (DTXAction.reportEvent(java.lang.String)
,DTXAction.reportValue(java.lang.String, int)
andDTXAction.reportError(java.lang.String, int)
) can be reported within the context of this action object, thus creating a series of events within an action scope.- Parameters:
actionName
- name of the action- Returns:
- A non null action instance to work with
- See Also:
enterAction(String, DTXAction)
-
enterAction
public static DTXAction enterAction(String actionName, DTXAction parentAction)
Enters aDTXAction
with a specified name and a parent action.If the given
actionName
isnull
or an empty string, no reporting will happen on that action.
The generated action can be used to report the time elapsed betweenenterAction(java.lang.String)
andDTXAction.leaveAction()
. Also other event types (DTXAction.reportEvent(java.lang.String)
,DTXAction.reportValue(java.lang.String, int)
andDTXAction.reportError(java.lang.String, int)
) can be reported within the context of this action object, thus creating a series of events within an action scope.- Parameters:
actionName
- name of the actionparentAction
- a parent action- Returns:
- A non null action instance to work with
- See Also:
enterAction(String)
-
endVisit
public static void endVisit()
Can be called to end the current visit and start a new visit.All current actions are closed and sent to the server.
-
reportError
public static void reportError(String errorName, int errorCode)
Reports an error with a specified name and error code.If given
errorName
isnull
or an empty String then no event is reported to the system. The error is reported as root action.- Parameters:
errorName
- name of this errorerrorCode
- numeric error code of this error- See Also:
DTXAction.reportError(String, int)
-
reportError
public static void reportError(String errorName, Throwable throwable)
Reports an error with a specified name and aThrowable
.If given
errorName
isnull
or an empty string then no event is reported to the system. The error is reported as root action.- Parameters:
errorName
- name of this errorthrowable
-Throwable
causing this error- See Also:
DTXAction.reportError(String, Throwable)
-
flushEvents
public static void flushEvents()
Call this function to flush all collected events immediately.To reduce network chatter, the collected events are usually sent in packages where the oldest event has an age of up to 2 minutes (the default; the maximum age can be configured). Using this function, you can force sending of all collected events regardless of their age.
-
setBeaconHeaders
public static void setBeaconHeaders(Map<String,String> headers)
Puts a set of http headers on every agent http request.For example: adding an
Authorization
header. It also triggers the agent to reconnect to the beacon endpoint with the new headers. To clear the previous headers, call the method with a null or empty value.- Parameters:
headers
- a set of http headers- See Also:
ConfigurationBuilder.withCommunicationProblemListener(CommunicationProblemListener)
-
getWebRequestTiming
public static WebRequestTiming getWebRequestTiming(String tag)
This represents a network timing instance for reporting the time elapsed between two user-defined events.You must call
WebRequestTiming.startWebRequestTiming()
to start andWebRequestTiming.stopWebRequestTiming(URL, int, String)
orWebRequestTiming.stopWebRequestTiming(String, int, String)
to complete the timing.- Parameters:
tag
- the tag generated bygetRequestTag()
- Returns:
- a non-null WebRequestTiming instance
-
getWebRequestTiming
public static WebRequestTiming getWebRequestTiming(HttpURLConnection connection)
This represents a network timing instance for reporting the time elapsed between two user-defined events.You must call
WebRequestTiming.startWebRequestTiming()
to start andWebRequestTiming.stopWebRequestTiming()
to complete the timing.- Parameters:
connection
- a non-null HttpURLConnection instance- Returns:
- a non-null WebRequestTiming instance
-
identifyUser
public static void identifyUser(String userId)
The current visit/session will be tagged with the provided user id.The value will not be stored and has to be renewed for every new session.
- Parameters:
userId
- a unique id that allows you to identify the current user. If userId is null or empty, then the user tag will be removed from the session.
-
identifyUser
@Deprecated public static void identifyUser(String userId, DTXAction parentAction)
Deprecated.As of version 8.215, useidentifyUser(String)
insteadThe current visit/session will be tagged with the provided user id.The value will not be stored and has to be renewed on every agent startup.
- Parameters:
userId
- a unique id that allows you to identify the current user. If userId is null or empty, then the user tag will be removed from the session.parentAction
- The parent action for the user identify event
-
getUserPrivacyOptions
public static UserPrivacyOptions getUserPrivacyOptions()
Returns the previously specified privacy settings from the user.- Returns:
- the previously specified privacy settings from the user
- Since:
- 8.191
- See Also:
ConfigurationBuilder.withUserOptIn(boolean)
-
applyUserPrivacyOptions
public static void applyUserPrivacyOptions(UserPrivacyOptions userPrivacyOptions)
Creates a new session with the specified privacy settings and stores the privacy settings for future sessions.This method can only be used, when user opt-in feature is enabled. This method call has no effect if the given privacy settings are identical to the previously specified privacy settings.
- Parameters:
userPrivacyOptions
- the new privacy settings from the user- Since:
- 8.191
- See Also:
ConfigurationBuilder.withUserOptIn(boolean)
-
isCrashReportingOptedIn
@Deprecated public static boolean isCrashReportingOptedIn()
Deprecated.As of version 8.191, replaced bygetUserPrivacyOptions()
Returns the current privacy setting for crash reporting.This method will always return true, when the user opt-in feature is not used.
- Returns:
- current privacy setting for crash reporting
- Throws:
IllegalStateException
- if the agent is not started
-
setCrashReportingOptedIn
@Deprecated public static void setCrashReportingOptedIn(boolean confirmed)
Deprecated.As of version 8.191, replaced byapplyUserPrivacyOptions(UserPrivacyOptions)
Allows the user to activate/deactivate crash reporting and stores the users decisions for future sessions.This method can only be used, when the agent is started
with the user opt-in feature
. To use this feature properly, you also have toactivate the crash reporting feature
.- Parameters:
confirmed
- true, if crash reporting is confirmed by the user- Throws:
IllegalStateException
- if the agent is not started- See Also:
ConfigurationBuilder.withCrashReporting(boolean)
-
getDataCollectionLevel
@Deprecated public static DataCollectionLevel getDataCollectionLevel()
Deprecated.As of version 8.191, replaced bygetUserPrivacyOptions()
Returns the current data collection level.This method will always return
DataCollectionLevel.USER_BEHAVIOR
, when the user opt-in feature is not used.- Returns:
- current data collection level
- Throws:
IllegalStateException
- if the agent is not started
-
setDataCollectionLevel
@Deprecated public static void setDataCollectionLevel(DataCollectionLevel dataCollectionLevel)
Deprecated.As of version 8.191, replaced byapplyUserPrivacyOptions(UserPrivacyOptions)
Allows the user to set the data collection level and stores the users decisions for future sessions.This method can only be used, when the agent is started
with the user opt-in feature
. When the user changes the data collection level a new session will be started.- Parameters:
dataCollectionLevel
- new data collection level- Throws:
IllegalStateException
- if the agent is not started
-
modifyUserAction
public static void modifyUserAction(UserActionModifier modifier)
Allows to modify the currently pending user action.If there is no user action pending or if it is already closed upon modification, no modification takes place.
- Parameters:
modifier
- modifications that should be applied to the newly created user action- Since:
- 8.189
-
instrumentWebView
public static void instrumentWebView(WebView webView)
Instruments the givenWebView
to allow communication between the RUM JavaScript tag and OneAgent for Android.For hybrid apps with the RUM JavaScript tag inside a
WebView
, it is required to execute this method for everyWebView
that contains the RUM JavaScript tag. Without this method call it can't be ensured that the monitoring data will be combined into same session.- Parameters:
webView
- the web view that should be instrumented- Since:
- 8.191
- See Also:
ConfigurationBuilder.withHybridMonitoring(boolean)
-
restoreCookies
public static void restoreCookies()
Restores the Dynatrace cookies for the specified domains.For hybrid apps with web view instrumentation you have to ensure that the Dynatrace cookies are not deleted. You must call this method, when you delete all cookies via
CookieManager.removeAllCookies(ValueCallback)
andCookieManager.removeSessionCookies(ValueCallback)
. Without the cookies it is not possible to combine the data from the RUM JavaScript tag and OneAgent for Android into one session.
-
sendBizEvent
public static void sendBizEvent(String type, JSONObject attributes)
Send a Business Event.With sendBizEvent, you can report a business event. These standalone events are being sent detached from user actions or sessions. The 'dt' key, as well as all 'dt.' prefixed keys are considered reserved by Dynatrace and will be stripped from the passed in attributes.
Note: Business events are only supported on Dynatrace SaaS deployments currently.
- Parameters:
type
- event type that is neither null or emptyattributes
- a non null JSON object- Since:
- 8.243
-
-