HttpMetric
class HttpMetric
Metric used to collect data for network requests/responses. A new object must be used for every request/response. This class is not thread safe.
Summary
Constants |
|
|---|---|
const Int |
Maximum allowed length of the Key of the |
const Int |
Maximum allowed length of the Value of the |
const Int |
Maximum allowed number of attributes allowed in a trace. |
const Int |
MAX_TRACE_NAME_LENGTH = 100Maximum allowed length of the name of the |
Public functions |
|
|---|---|
String? |
getAttribute(attribute: String)Returns the value of an attribute. |
(Mutable)Map<String!, String!> |
Returns the map of all the attributes added to this HttpMetric. |
Unit |
putAttribute(attribute: String, value: String)Sets a String value for the specified attribute. |
Unit |
removeAttribute(attribute: String)Removes an already added attribute from the HttpMetric. |
Unit |
setHttpResponseCode(responseCode: Int)Sets the httpResponse code of the request |
Unit |
setRequestPayloadSize(bytes: Long)Sets the size of the request payload |
Unit |
setResponseContentType(contentType: String?)Content type of the response such as text/html, application/json, etc... |
Unit |
setResponsePayloadSize(bytes: Long)Sets the size of the response payload |
Unit |
start()Marks the start time of the request |
Unit |
stop()Marks the end time of the response and queues the network request metric on the device for transmission. |
Extension functions |
|
|---|---|
inline Unit |
HttpMetric.trace(block: HttpMetric.() -> Unit)Measures the time it takes to run the |
Constants
MAX_ATTRIBUTE_KEY_LENGTH
const val MAX_ATTRIBUTE_KEY_LENGTH = 40: Int
Maximum allowed length of the Key of the Trace attribute
MAX_ATTRIBUTE_VALUE_LENGTH
const val MAX_ATTRIBUTE_VALUE_LENGTH = 100: Int
Maximum allowed length of the Value of the Trace attribute
MAX_TRACE_CUSTOM_ATTRIBUTES
const val MAX_TRACE_CUSTOM_ATTRIBUTES = 5: Int
Maximum allowed number of attributes allowed in a trace.
MAX_TRACE_NAME_LENGTH
const val MAX_TRACE_NAME_LENGTH = 100: Int
Maximum allowed length of the name of the Trace
Public functions
getAttribute
fun getAttribute(attribute: String): String?
Returns the value of an attribute.
| Parameters | |
|---|---|
attribute: String |
name of the attribute to fetch the value for |
| Returns | |
|---|---|
String? |
The value of the attribute if it exists or null otherwise. |
getAttributes
fun getAttributes(): (Mutable)Map<String!, String!>
Returns the map of all the attributes added to this HttpMetric.
putAttribute
fun putAttribute(attribute: String, value: String): Unit
Sets a String value for the specified attribute. Updates the value of the attribute if the attribute already exists. If the HttpMetric has been stopped, this method returns without adding the attribute. The maximum number of attributes that can be added to a HttpMetric are MAX_TRACE_CUSTOM_ATTRIBUTES.
removeAttribute
fun removeAttribute(attribute: String): Unit
Removes an already added attribute from the HttpMetric. If the HttpMetric has already been stopped, this method returns without removing the attribute.
| Parameters | |
|---|---|
attribute: String |
name of the attribute to be removed from the running Traces. |
setHttpResponseCode
fun setHttpResponseCode(responseCode: Int): Unit
Sets the httpResponse code of the request
| Parameters | |
|---|---|
responseCode: Int |
valid values are greater than 0. Invalid usage will be logged. |
setRequestPayloadSize
fun setRequestPayloadSize(bytes: Long): Unit
Sets the size of the request payload
| Parameters | |
|---|---|
bytes: Long |
valid values are greater than or equal to 0. Invalid usage will be logged. |
setResponseContentType
fun setResponseContentType(contentType: String?): Unit
Content type of the response such as text/html, application/json, etc...
| Parameters | |
|---|---|
contentType: String? |
valid string of MIME type. Invalid usage will be logged. |
setResponsePayloadSize
fun setResponsePayloadSize(bytes: Long): Unit
Sets the size of the response payload
| Parameters | |
|---|---|
bytes: Long |
valid values are greater than or equal to 0. Invalid usage will be logged. |
Extension functions
trace
inline fun HttpMetric.trace(block: HttpMetric.() -> Unit): Unit
Measures the time it takes to run the block wrapped by calls to start and stop using HttpMetric.