Package com.dynatrace.agent.api
Class HttpRequestEventBuilder
java.lang.Object
com.dynatrace.agent.api.HttpRequestEventBuilder
Builder for creating an HTTP Request event to be sent via the
Dynatrace#sendHttpRequestEvent.
This builder is used to construct an HTTP Request event by providing 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." —
any property without this prefix 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(
HttpRequestEventBuilder("https://example.com", "GET")
.withDuration(250)
.withStatusCode(200)
.withReasonPhrase("OK")
.withBytesSent(1024)
.addEventProperty("event_properties.userId", "12345")
)
- Since:
- 8.323
-
Constructor Summary
ConstructorsConstructorDescriptionHttpRequestEventBuilder(String url, String requestMethod) Builder for creating an HTTP Request event 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 aIntegervalue.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 response for terminated the HTTP communication..
-
Constructor Details
-
HttpRequestEventBuilder
Builder for creating an HTTP Request event 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.Negative values will cause the event to be dropped.
- Parameters:
durationMilliseconds- the duration of the request in milliseconds- Returns:
- this builder 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 builder 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 builder instance for chaining
-
withThrowable
Attaches aThrowableerror to the HTTP Request event that describes the (client-side) failure which is response for terminated the HTTP communication..- Parameters:
throwable- the exception to attach- Returns:
- this builder instance for chaining
-
withBytesSent
Sets the number of encoded/compressed bytes sent for the request.- Parameters:
bytesSent- number of bytes sent- Returns:
- this builder instance for chaining
-
withBytesReceived
Sets the number of encoded/compressed bytes received for the request.- Parameters:
bytesReceived- number of bytes received- Returns:
- this builder instance for chaining
-
addEventProperty
Adds a user event property with aStringvalue.- Parameters:
key- name of the event property. Has to start withevent_properties.or it will be droppedvalue- property value- Returns:
- this builder instance for chaining
-
addEventProperty
Adds a user event property with aIntegervalue.- Parameters:
key- name of the event property. Has to start withevent_properties.or it will be droppedvalue- property value- Returns:
- this builder instance for chaining
-
addEventProperty
Adds a user event property with aLongvalue.- Parameters:
key- name of the event property. Has to start withevent_properties.or it will be droppedvalue- property value- Returns:
- this builder 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 withevent_properties.or it will be droppedvalue- property value- Returns:
- this builder instance for chaining
-
addEventProperty
Adds a user event property with aBooleanvalue.- Parameters:
key- name of the event property. Has to start withevent_properties.or it will be droppedvalue- property value- Returns:
- this builder instance for chaining
-