Class HttpRequestEventBuilder

java.lang.Object
com.dynatrace.agent.api.HttpRequestEventBuilder

public class HttpRequestEventBuilder extends Object
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 Details

    • HttpRequestEventBuilder

      public HttpRequestEventBuilder(String url, String requestMethod)
      Builder for creating an HTTP Request event to be sent via the Dynatrace#sendHttpRequestEvent.
      Parameters:
      url - the full request URL. Must be well-formed and use the http or https protocol
      requestMethod - the HTTP request method (GET, POST, etc.)
  • Method Details

    • withDuration

      public HttpRequestEventBuilder withDuration(long durationMilliseconds)
      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

      public HttpRequestEventBuilder withStatusCode(int statusCode)
      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

      public HttpRequestEventBuilder withReasonPhrase(String reasonPhrase)
      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

      public HttpRequestEventBuilder withThrowable(Throwable throwable)
      Attaches a Throwable error 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

      public HttpRequestEventBuilder withBytesSent(int bytesSent)
      Sets the number of encoded/compressed bytes sent for the request.
      Parameters:
      bytesSent - number of bytes sent
      Returns:
      this builder instance for chaining
    • withBytesReceived

      public HttpRequestEventBuilder withBytesReceived(int bytesReceived)
      Sets the number of encoded/compressed bytes received for the request.
      Parameters:
      bytesReceived - number of bytes received
      Returns:
      this builder instance for chaining
    • addEventProperty

      public HttpRequestEventBuilder addEventProperty(String key, String value)
      Adds a user event property with a String value.
      Parameters:
      key - name of the event property. Has to start with event_properties. or it will be dropped
      value - property value
      Returns:
      this builder instance for chaining
    • addEventProperty

      public HttpRequestEventBuilder addEventProperty(String key, int value)
      Adds a user event property with a Integer value.
      Parameters:
      key - name of the event property. Has to start with event_properties. or it will be dropped
      value - property value
      Returns:
      this builder instance for chaining
    • addEventProperty

      public HttpRequestEventBuilder addEventProperty(String key, long value)
      Adds a user event property with a Long value.
      Parameters:
      key - name of the event property. Has to start with event_properties. or it will be dropped
      value - property value
      Returns:
      this builder instance for chaining
    • addEventProperty

      public HttpRequestEventBuilder addEventProperty(String key, double value)
      Adds a user event property with a Double value.

      Note: Double.NaN, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY are not allowed and will be dropped

      Parameters:
      key - name of the event property. Has to start with event_properties. or it will be dropped
      value - property value
      Returns:
      this builder instance for chaining
    • addEventProperty

      public HttpRequestEventBuilder addEventProperty(String key, boolean value)
      Adds a user event property with a Boolean value.
      Parameters:
      key - name of the event property. Has to start with event_properties. or it will be dropped
      value - property value
      Returns:
      this builder instance for chaining