Class HttpRequestEventData

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

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

    • HttpRequestEventData

      public HttpRequestEventData(String url, String requestMethod)
      Creates a new HTTP Request event configuration 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 HttpRequestEventData withDuration(long durationMilliseconds)
      Sets the request duration in milliseconds.
      Parameters:
      durationMilliseconds - the duration of the request in milliseconds
      Returns:
      this instance for chaining
    • withStatusCode

      public HttpRequestEventData 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 instance for chaining
    • withReasonPhrase

      public HttpRequestEventData 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 instance for chaining
    • withThrowable

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

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

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

      public HttpRequestEventData 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 instance for chaining
    • addEventProperty

      public HttpRequestEventData addEventProperty(String key, int value)
      Adds a user event property with an 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 instance for chaining
    • addEventProperty

      public HttpRequestEventData 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 instance for chaining
    • addEventProperty

      public HttpRequestEventData 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 instance for chaining
    • addEventProperty

      public HttpRequestEventData 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 instance for chaining
    • withTraceparentHeader

      public HttpRequestEventData withTraceparentHeader(String traceparentHeader)
      Adds a Traceparent header to the request event.

      The format must follow version "00" of the Traceparent Header specification:

      w3.org/TR/trace-context

      Example:

      
       00-00000000000000001234567890abcdef-1234567890abcdef-00
       
      Parameters:
      traceparentHeader - a string in the format: <version>-<trace-id>-<parent-id>-<flags>
      Returns:
      this instance for chaining