public interface HttpRequestTracker
If the SDK does not automatically discover your HTTP requests, use this class to explicitly report them.
Note that most users will not need to use this class; check the documentation for the list of HTTP API that are automatically discovered.
Suppose that you have a method like this for making HTTP requests:
public byte[] sendRequest(URL url) throws HttpException { try { // implementation omitted return responseBody; } catch (UnderlyingException e) { throw new HttpException(e); } }
Here’s how you would augment this method to report requests to the SDK:
public byte[] sendRequest(URL url) throws HttpException { HttpRequestTracker tracker = Instrumentation.beginHttpRequest(url); try { // implementation omitted tracker.withResponseCode(theResponseCode) .withResponseHeaderFields(theResponseHeaderFields) .reportDone(); return responseBody; } catch (UnderlyingException e) { tracker.withException(e) .reportDone(); throw new HttpException(e); } }
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getError()
Gets the error message associated with this request.
|
java.lang.Exception |
getException()
Gets the exception associated with this request.
|
java.lang.String |
getInstrumentationSource()
Gets the instrumentation source, as set by
withInstrumentationSource(String) . |
java.lang.Long |
getRequestContentLength()
Gets the request content length, as set by
withRequestContentLength(Long) |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getRequestHeaderFields()
Returns the request header fields associated with this request.
|
int |
getResponseCode()
Gets the HTTP status code associated with this request.
|
java.lang.Long |
getResponseContentLength()
Gets the response content length, as set by
withResponseContentLength(Long) |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaderFields()
Returns the response header fields associated with this request.
|
java.lang.Throwable |
getThrowable()
Gets the throwable associated with this request.
|
java.net.URL |
getURL()
Gets the URL associated with this request.
|
void |
reportDone()
Stops tracking an HTTP request.
|
HttpRequestTracker |
withError(java.lang.String error)
Indicates that this request encountered an error.
|
HttpRequestTracker |
withException(java.lang.Exception e)
Deprecated.
Use
withThrowable(Throwable) instead. If both an exception and a throwable are specified, the exception is ignored. |
HttpRequestTracker |
withInstrumentationSource(java.lang.String instrumentationSource)
Sets a string to be used to identify the source of the instrumentation that generated this tracker.
|
HttpRequestTracker |
withRequestContentLength(java.lang.Long length)
Sets the request content length associated with this request.
|
HttpRequestTracker |
withRequestHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestHeaderFields)
Sets the request headers associated with this request.
|
HttpRequestTracker |
withResponseCode(int responseCode)
Sets the HTTP response code associated with this request.
|
HttpRequestTracker |
withResponseContentLength(java.lang.Long length)
Sets the response content length associated with this request.
|
HttpRequestTracker |
withResponseHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields)
Sets the response headers associated with this request.
|
HttpRequestTracker |
withStatusLine(java.lang.String statusLine)
Sets the HTTP status line associated with this request.
|
HttpRequestTracker |
withThrowable(java.lang.Throwable e)
Indicates that this request encountered an error.
|
HttpRequestTracker |
withURL(java.net.URL url)
Sets the URL associated with this request.
|
java.lang.Exception getException()
Gets the exception associated with this request.
@Deprecated HttpRequestTracker withException(java.lang.Exception e)
withThrowable(Throwable)
instead. If both an exception and a throwable are specified, the exception is ignored.Indicates that this request encountered an error.
This method is dominant over withError(String)
. If both a string and an exception are specified, the string is ignored.
e
- An exception describing the error.withThrowable(Throwable)
,
withError(String)
java.lang.Throwable getThrowable()
Gets the throwable associated with this request.
HttpRequestTracker withThrowable(java.lang.Throwable e)
Indicates that this request encountered an error.
This method is preferred over withError(String)
. If both a string and a throwable are specified, the string is ignored.
e
- A throwable describing the error.withError(String)
java.lang.String getError()
Gets the error message associated with this request.
HttpRequestTracker withError(java.lang.String error)
Indicates that this request encountered an error.
error
- A string describing the error.withThrowable(Throwable)
java.net.URL getURL()
Gets the URL associated with this request.
HttpRequestTracker withURL(java.net.URL url)
Sets the URL associated with this request.
url
- The URL for this request.int getResponseCode()
Gets the HTTP status code associated with this request.
java.lang.NullPointerException
- if withResponseCode(int)
has never been called to set the value.HttpRequestTracker withResponseCode(int responseCode)
Sets the HTTP response code associated with this request.
If a response was received, this method must be called, or the request will not be reported.
responseCode
- The status code of the response.HttpRequestTracker withStatusLine(java.lang.String statusLine)
Sets the HTTP status line associated with this request.
This is optional
statusLine
- java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaderFields()
Returns the response header fields associated with this request.
HttpRequestTracker withResponseHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields)
Sets the response headers associated with this request.
responseHeaderFields
- The headers of the response.java.lang.Long getResponseContentLength()
Gets the response content length, as set by withResponseContentLength(Long)
HttpRequestTracker withResponseContentLength(java.lang.Long length)
Sets the response content length associated with this request.
Note: This will override any content length header found in the Response Headers
length
- the content length of the responsejava.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestHeaderFields()
Returns the request header fields associated with this request.
HttpRequestTracker withRequestHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestHeaderFields)
Sets the request headers associated with this request.
requestHeaderFields
- The headers of the request.java.lang.Long getRequestContentLength()
Gets the request content length, as set by withRequestContentLength(Long)
HttpRequestTracker withRequestContentLength(java.lang.Long length)
Sets the request content length associated with this request.
Note: This will override any content length header found in the Request Headers
length
- the content length of the requestjava.lang.String getInstrumentationSource()
Gets the instrumentation source, as set by withInstrumentationSource(String)
.
The default value is "Manual HttpTracker".
HttpRequestTracker withInstrumentationSource(java.lang.String instrumentationSource)
Sets a string to be used to identify the source of the instrumentation that generated this tracker.
By default, it is set to "Manual HttpTracker". You should not have to modify this.
instrumentationSource
- void reportDone()
Stops tracking an HTTP request.
Immediately after receiving a response or an error, set the appropriate fields and call this method to report the outcome of the HTTP request. You should not continue to use this object after calling this method – if you need to track another request, obtain a new instance.