public class WebRequestTiming extends Object
startWebRequestTiming and stopWebRequestTiming). Each timing event requires an associated tag, generated by
Dynatrace.getRequestTag() or DTXAction.getRequestTag().
Web request timing example:
// [1] Create an action for the web request
DTXAction webAction = Dynatrace.enterAction("yourActionName");
HttpURLConnection urlConnection = null;
WebRequestTiming timing = null;
try{
URL url = new URL("http://www.example.com");
urlConnection = (HttpURLConnection) url.openConnection();
// [2] Tag the web request automatically and receive a WebRequestTiming instance
timing = Dynatrace.getWebRequestTiming(urlConnection);
// [3] Call startWebRequestTiming() to begin the timing (and then handle the input stream from the connection)
timing.startWebRequestTiming();
InputStream input = new BufferedInputStream(urlConnection.getInputStream());
readStream(input);
// [4] Once we're done reading, we can stop the timing
timing.stopWebRequestTiming();
processData();
}
catch (Exception exception) {
// [5a] Finalize the timing when an error occurs
if(timing != null) {
timing.stopWebRequestTiming();
}
// [5b] Attach the exception to the action
webAction.reportError("Exception", e);
// user-defined exception handling
handleError(exception);
}
finally {
if(urlConnection != null) {
urlConnection.disconnect();
}
// [6] Lastly finalize the timing of the action in the finally block.
webAction.leaveAction();
}
| Modifier and Type | Method and Description |
|---|---|
boolean |
isFinalized()
Used to determine if the current object has been finalized.
|
void |
startWebRequestTiming()
Begin timing a web request event.
|
void |
stopWebRequestTiming()
Stop, finalize, and send a web request timing event.
|
void |
stopWebRequestTiming(String requestUrl,
int respCode,
String respPhrase)
Stop, finalize, and send a web request timing event.
|
void |
stopWebRequestTiming(URL requestUrl,
int respCode,
String respPhrase)
Stop, finalize, and send a web request timing event.
|
public void startWebRequestTiming()
You must call stopWebRequestTiming() to complete the timing.
public void stopWebRequestTiming(String requestUrl, int respCode, String respPhrase) throws MalformedURLException
startWebRequestTiming()respCode - Status code from responserespPhrase - Response phrase from responserequestUrl - The URL of the request as a stringMalformedURLException - if the requestUrl parameter is invalidpublic void stopWebRequestTiming(URL requestUrl, int respCode, String respPhrase)
startWebRequestTiming()respCode - Status code from responserespPhrase - Response phrase from responserequestUrl - The URL of the requestIllegalArgumentException - if requestUrl is nullpublic boolean isFinalized()
stopWebRequestTiming() finalizes the object and
prepares the data for the next sending interval.true if the object has been finalizedfalse if it has not been finalizedpublic void stopWebRequestTiming()
© 2021 Dynatrace LLC. All Rights Reserved