Class SessionImpl
- java.lang.Object
-
- com.dynatrace.openkit.core.objects.OpenKitComposite
-
- com.dynatrace.openkit.core.objects.SessionImpl
-
- All Implemented Interfaces:
Session,OpenKitObject,java.io.Closeable,java.lang.AutoCloseable
public class SessionImpl extends OpenKitComposite implements Session
Actual implementation of theSessioninterface.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_NEW_SESSION_REQUESTSThe maximum number of "new session requests" to send per session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanSendNewSessionRequest()Indicates whether new session requests can be sent or not.voidclearCapturedData()Clears data that has been captured so far.voidclose()voiddecreaseNumRemainingSessionRequests()Decreases the number of remaining new session requests.voiddisableCapture()Disables capturing for this session.voidenableCapture()Enables capturing for this session.voidend()Ends this Session and marks it as ready for immediate sending.voidend(boolean sendSessionEndEvent)RootActionenterAction(java.lang.String actionName)Enters an Action with a specified name in this Session.longgetSplitByEventsGracePeriodEndTimeInMillis()Returns the time when the session is to be ended (after it was not possible to end the session after splitting events e.g.SessionStategetState()voididentifyUser(java.lang.String userTag)Tags a session with the provideduserTag.voidinitializeServerConfiguration(ServerConfiguration initialServerConfig)Initializes theBeaconwith the givenServerConfigurationbooleanisDataSendingAllowed()Indicates whether sending data for this session is allowed or not.booleanisEmpty()Test if this Session is empty or not.voidreportCarrier(java.lang.String carrier)Reports the name of the cellular network carrier.voidreportConnectionType(ConnectionType connectionType)Reports the type of connection with which the device is connected to the network.voidreportCrash(java.lang.String errorName, java.lang.String reason, java.lang.String stacktrace)Reports a crash with a specified error name, crash reason and a stacktrace.voidreportCrash(java.lang.Throwable throwable)Reports a crash with error name, crash reason and stacktrace determined from givenThrowable.voidreportNetworkTechnology(java.lang.String technology)Reports the network technology in use (e.g.StatusResponsesendBeacon(HTTPClientProvider clientProvider, AdditionalQueryParameters additionalParameters)Sends the current beacon state.voidsendBizEvent(java.lang.String type, java.util.Map<java.lang.String,JSONValue> attributes)Send a Business Event With sendBizEvent, you can report a business event.voidsetSplitByEventsGracePeriodEndTimeInMillis(long endTime)Sets the end time when the session is to be actually ended after a session split by event count.java.lang.StringtoString()WebRequestTracertraceWebRequest(java.lang.String url)Allows tracing and timing of a web request handled by any 3rd party HTTP Client (e.g.WebRequestTracertraceWebRequest(java.net.URLConnection connection)Traces a web request - which is provided as a URLConnection - and allows adding timing information to this request.booleantryEnd()Tries to end the current session by checking if there are no more child objects (actions / web request tracers) open.voidupdateServerConfiguration(ServerConfiguration serverConfiguration)Update theBeaconwith the givenServerConfiguration-
Methods inherited from class com.dynatrace.openkit.core.objects.OpenKitComposite
getActionID
-
-
-
-
Field Detail
-
MAX_NEW_SESSION_REQUESTS
public static final int MAX_NEW_SESSION_REQUESTS
The maximum number of "new session requests" to send per session.- See Also:
- Constant Field Values
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
enterAction
public RootAction enterAction(java.lang.String actionName)
Description copied from interface:SessionEnters an Action with a specified name in this Session.If the given
actionNameisnullor an empty string, no reporting will happen on thatRootAction.- Specified by:
enterActionin interfaceSession- Parameters:
actionName- name of the Action- Returns:
- Action instance to work with
-
identifyUser
public void identifyUser(java.lang.String userTag)
Description copied from interface:SessionTags a session with the provideduserTag.If the given
userTagisnullor an empty string, this is equivalent to logging off the user.The last non-empty
userTagis re-applied to split sessions. Details are described in https://github.com/Dynatrace/openkit-java/blob/main/docs/internals.md#identify-users-on-split-sessions.- Specified by:
identifyUserin interfaceSession- Parameters:
userTag- id of the user ornull/""to simulate a log off.
-
reportCrash
public void reportCrash(java.lang.String errorName, java.lang.String reason, java.lang.String stacktrace)Description copied from interface:SessionReports a crash with a specified error name, crash reason and a stacktrace.If the given
errorNameisnullor an empty string, no crash report will be sent to the server. If thereasonis longer than 1000 characters, it is truncated to this value. If thestacktraceis longer than 128.000 characters, it is truncated according to the last line break.- Specified by:
reportCrashin interfaceSession- Parameters:
errorName- name of the error leading to the crash (e.g. Exception class)reason- reason or description of that errorstacktrace- stacktrace leading to that crash
-
reportCrash
public void reportCrash(java.lang.Throwable throwable)
Description copied from interface:SessionReports a crash with error name, crash reason and stacktrace determined from givenThrowable.This method is offered as convenience method for
Session.reportCrash(Throwable).- Specified by:
reportCrashin interfaceSession- Parameters:
throwable- TheThrowablecausing the crash.
-
reportNetworkTechnology
public void reportNetworkTechnology(java.lang.String technology)
Description copied from interface:SessionReports the network technology in use (e.g. 2G, 3G, 802.11x, offline, ...) Usenullto clear the value again and it will no longer be sent with the next beacon.- Specified by:
reportNetworkTechnologyin interfaceSession- Parameters:
technology- the used network technology
-
reportConnectionType
public void reportConnectionType(ConnectionType connectionType)
Description copied from interface:SessionReports the type of connection with which the device is connected to the network. Usenullto clear the value again and it will no longer be sent with the next beacon.- Specified by:
reportConnectionTypein interfaceSession- Parameters:
connectionType- the type of connection
-
reportCarrier
public void reportCarrier(java.lang.String carrier)
Description copied from interface:SessionReports the name of the cellular network carrier. Usenullto clear the value again and it will no longer be sent with the next beacon.The given value will be truncated to 250 characters.
- Specified by:
reportCarrierin interfaceSession- Parameters:
carrier- the cellular network carrier
-
traceWebRequest
public WebRequestTracer traceWebRequest(java.net.URLConnection connection)
Description copied from interface:SessionTraces a web request - which is provided as a URLConnection - and allows adding timing information to this request. If the web request is continued on a server-side Agent (e.g. Java, .NET, ...) this Session will be correlated to the resulting server-side PurePath.- Specified by:
traceWebRequestin interfaceSession- Parameters:
connection- the URLConnection of the HTTP request to be tagged and timed- Returns:
- a WebRequestTracer which allows adding timing information
-
traceWebRequest
public WebRequestTracer traceWebRequest(java.lang.String url)
Description copied from interface:SessionAllows tracing and timing of a web request handled by any 3rd party HTTP Client (e.g. Apache, Google, Jetty, ...). In this case the Dynatrace HTTP header (OpenKitConstants.WEBREQUEST_TAG_HEADER) has to be set manually to the tag value of this WebRequestTracer.
If the web request is continued on a server-side Agent (e.g. Java, .NET, ...) this Session will be correlated to the resulting server-side PurePath.- Specified by:
traceWebRequestin interfaceSession- Parameters:
url- the URL of the web request to be tagged and timed- Returns:
- a WebRequestTracer which allows getting the tag value and adding timing information
-
sendBizEvent
public void sendBizEvent(java.lang.String type, java.util.Map<java.lang.String,JSONValue> attributes)Description copied from interface:SessionSend a Business Event With sendBizEvent, you can report a business event. These standalone events are being sent detached from user actions or sessions. Note: 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.- Specified by:
sendBizEventin interfaceSession- Parameters:
type- Mandatory event typeattributes- Must be a valid JSON object. The resulting event will be populated with the 'attributes'-parameter and enriched with additional properties. Therefore, even empty objects are valid.
-
end
public void end()
Description copied from interface:SessionEnds this Session and marks it as ready for immediate sending.
-
end
public void end(boolean sendSessionEndEvent)
-
tryEnd
public boolean tryEnd()
Tries to end the current session by checking if there are no more child objects (actions / web request tracers) open. In case no more child objects are open the session is ended otherwise it is kept open.- Returns:
trueif the session was successfully ended (or was already ended before).falsein case there are / were still open child objects (actions / web request tracers).
-
setSplitByEventsGracePeriodEndTimeInMillis
public void setSplitByEventsGracePeriodEndTimeInMillis(long endTime)
Sets the end time when the session is to be actually ended after a session split by event count. It might occur that a session is not yet ready to be finished (e.g. open actions, tracers) when the session split happens. In this case the session is kept open and closed at a later time. The given end time is the point in time at which the session will be closed forcefully by theSessionWatchdogthread.- Parameters:
endTime- the time when the session is to be closed for good.
-
getSplitByEventsGracePeriodEndTimeInMillis
public long getSplitByEventsGracePeriodEndTimeInMillis()
Returns the time when the session is to be ended (after it was not possible to end the session after splitting events e.g. due to actions still being open). The returned time already includes a grace period.
-
sendBeacon
public StatusResponse sendBeacon(HTTPClientProvider clientProvider, AdditionalQueryParameters additionalParameters)
Sends the current beacon state.- Parameters:
clientProvider- Provider class providing the client for data transmission.additionalParameters- additional parameters that will be appended to the beacon request (can benull).- Returns:
- Response from client.
-
clearCapturedData
public void clearCapturedData()
Clears data that has been captured so far.This is called, when capturing is turned off to avoid having too much data.
-
isEmpty
public boolean isEmpty()
Test if this Session is empty or not.A session is considered to be empty, if it does not contain any action or event data.
- Returns:
trueif the session is empty,falseotherwise.
-
initializeServerConfiguration
public void initializeServerConfiguration(ServerConfiguration initialServerConfig)
Initializes theBeaconwith the givenServerConfiguration
-
updateServerConfiguration
public void updateServerConfiguration(ServerConfiguration serverConfiguration)
Update theBeaconwith the givenServerConfiguration
-
getState
public SessionState getState()
-
isDataSendingAllowed
public boolean isDataSendingAllowed()
Indicates whether sending data for this session is allowed or not.
-
enableCapture
public void enableCapture()
Enables capturing for this session.Will implicitly also set the
session statetoconfigured.
-
disableCapture
public void disableCapture()
Disables capturing for this session.Will implicitly also set the
session statetoconfigured.
-
canSendNewSessionRequest
public boolean canSendNewSessionRequest()
Indicates whether new session requests can be sent or not.This is directly related to
decreaseNumRemainingSessionRequests().
-
decreaseNumRemainingSessionRequests
public void decreaseNumRemainingSessionRequests()
Decreases the number of remaining new session requests.In case no more new session requests remain,
canSendNewSessionRequest()will returnfalse
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-