Package com.dynatrace.agent.api
Class HttpRequestEventData
java.lang.Object
com.dynatrace.agent.api.HttpRequestEventData
Holds the configuration for an HTTP Request event to be sent via the
Dynatrace#sendHttpRequestEvent.
Configure the event by specifying the required request/response information (URL, method, status code, duration,
etc.) and optional user event properties. User event properties must have keys prefixed with
"event_properties." or it will be dropped.
OneAgent will verify the reported monitoring data based on the Semantic Dictionary. Invalid fields will be removed and invalid events will be dropped.
Example (Kotlin):
Dynatrace.sendHttpRequestEvent(
HttpRequestEventData("https://example.com", "GET")
.withDuration(250)
.withStatusCode(200)
.withReasonPhrase("OK")
.withBytesSent(1024)
.addEventProperty("event_properties.userId", "12345")
)
- Since:
- 8.323
-
Constructor Summary
ConstructorsConstructorDescriptionHttpRequestEventData(String url, String requestMethod) Creates a new HTTP Request event configuration to be sent via theDynatrace#sendHttpRequestEvent. -
Method Summary
Modifier and TypeMethodDescriptionaddEventProperty(String key, boolean value) Adds a user event property with aBooleanvalue.addEventProperty(String key, double value) Adds a user event property with aDoublevalue.addEventProperty(String key, int value) Adds a user event property with anIntegervalue.addEventProperty(String key, long value) Adds a user event property with aLongvalue.addEventProperty(String key, String value) Adds a user event property with aStringvalue.withBytesReceived(int bytesReceived) Sets the number of encoded/compressed bytes received for the request.withBytesSent(int bytesSent) Sets the number of encoded/compressed bytes sent for the request.withDuration(long durationMilliseconds) Sets the request duration in milliseconds.withReasonPhrase(String reasonPhrase) Sets the reason phrase of the HTTP response.withStatusCode(int statusCode) Sets the HTTP response status code.withThrowable(Throwable throwable) Attaches aThrowableerror to the HTTP Request event that describes the (client-side) failure which is responsible for terminating the HTTP communication.withTraceparentHeader(String traceparentHeader) Adds a Traceparent header to the request event.
-
Constructor Details
-
HttpRequestEventData
Creates a new HTTP Request event configuration to be sent via theDynatrace#sendHttpRequestEvent.- Parameters:
url- the full request URL. Must be well-formed and use thehttporhttpsprotocolrequestMethod- the HTTP request method (GET,POST, etc.)
-
-
Method Details
-
withDuration
Sets the request duration in milliseconds.- Parameters:
durationMilliseconds- the duration of the request in milliseconds- Returns:
- this instance for chaining
-
withStatusCode
Sets the HTTP response status code.- Parameters:
statusCode- the HTTP status code. Negative values fall back to the default value of 0- Returns:
- this instance for chaining
-
withReasonPhrase
Sets the reason phrase of the HTTP response.- Parameters:
reasonPhrase- the HTTP reason phrase. Can be an empty string. Will be truncated to 5000 characters if too long- Returns:
- this instance for chaining
-
withThrowable
Attaches aThrowableerror to the HTTP Request event that describes the (client-side) failure which is responsible for terminating the HTTP communication.- Parameters:
throwable- the exception to attach- Returns:
- this instance for chaining
-
withBytesSent
Sets the number of encoded/compressed bytes sent for the request.- Parameters:
bytesSent- number of bytes sent- Returns:
- this instance for chaining
-
withBytesReceived
Sets the number of encoded/compressed bytes received for the request.- Parameters:
bytesReceived- number of bytes received- Returns:
- this instance for chaining
-
addEventProperty
Adds a user event property with aStringvalue.- Parameters:
key- name of the event property. Has to start with "event_properties." or it will be droppedvalue- property value- Returns:
- this instance for chaining
-
addEventProperty
Adds a user event property with anIntegervalue.- Parameters:
key- name of the event property. Has to start with "event_properties." or it will be droppedvalue- property value- Returns:
- this instance for chaining
-
addEventProperty
Adds a user event property with aLongvalue.- Parameters:
key- name of the event property. Has to start with "event_properties." or it will be droppedvalue- property value- Returns:
- this instance for chaining
-
addEventProperty
Adds a user event property with aDoublevalue.Note:
Double.NaN,Double.POSITIVE_INFINITYorDouble.NEGATIVE_INFINITYare not allowed and will be dropped- Parameters:
key- name of the event property. Has to start with "event_properties." or it will be droppedvalue- property value- Returns:
- this instance for chaining
-
addEventProperty
Adds a user event property with aBooleanvalue.- Parameters:
key- name of the event property. Has to start with "event_properties." or it will be droppedvalue- property value- Returns:
- this instance for chaining
-
withTraceparentHeader
Adds a Traceparent header to the request event.The format must follow version "00" of the Traceparent Header specification:
w3.org/TR/trace-contextExample:
00-00000000000000001234567890abcdef-1234567890abcdef-00- Parameters:
traceparentHeader- a string in the format:<version>-<trace-id>-<parent-id>-<flags>- Returns:
- this instance for chaining
-