Dynatrace supports custom events to track user interactions, business metrics, and application-specific signals. Events can also be enriched before they are sent by applying event modifiers.
Custom events are reported using Dynatrace.sendEvent(...) with optional duration and event properties.
// Simple eventDynatrace.sendEvent(new EventData());// Event with duration (in milliseconds)Dynatrace.sendEvent(new EventData().withDuration(150));
Custom properties provide context for reported events. Property keys must be prefixed with event_properties..
Dynatrace.sendEvent(new EventData().withDuration(250).addEventProperty("event_properties.checkout_step", "payment_confirmed").addEventProperty("event_properties.cart_value", 149.99).addEventProperty("event_properties.item_count", 3));
event_properties..Valid examples:
event_properties.purchase_state.event_properties.cart.total_value.event_properties.step_1_status.Event modifiers intercept events before they are sent. They can be used to add common properties, redact sensitive information, or filter events.
On Android, modifiers operate on a JSONObject representation of the event.
EventModifier modifier = (JSONObject event) -> {// Add build variant context to all eventsevent.put("event_properties.build_type", BuildConfig.BUILD_TYPE);event.put("event_properties.flavor", BuildConfig.FLAVOR);return event;};Dynatrace.addEventModifier(modifier);
Returning null discards an event.
EventModifier modifier = (JSONObject event) -> {// Events happening on the com.example.MainActivity activity will be dropped.if ("com.example.MainActivity".equals(event.optString("view.detected_name"))) {return null;}return event;};Dynatrace.addEventModifier(modifier);
EventModifier modifier = (JSONObject event) -> {// Redact user IDs from URLsString url = event.optString("url.full", null);if (url != null) {String redactedUrl = Pattern.compile("/users/\\\\w+/").matcher(url).replaceAll("/users/{id}/");event.put("url.full", redactedUrl);}return event;};Dynatrace.addEventModifier(modifier);
// Store the modifier when adding itEventModifier modifier = (JSONObject event) -> {event.put("event_properties.custom", "value");return event;};Dynatrace.addEventModifier(modifier);// Remove when no longer neededDynatrace.removeEventModifier(modifier);
Event modifiers have restrictions on which fields can be modified to ensure data integrity.
The following fields can be modified or added:
event_properties.*—custom event properties.url.full—complete request URL.exception.stack_trace—exception stack traces.All other fields are read-only and can't be modified. The original values are preserved.
The following example shows how to enrich only specific event types. It adds context to HTTP events (for API segmentation) and to error events (for faster triage).
public void setupConditionalEnrichment(final String apiClientName) {EventModifier modifier = (JSONObject event) -> {// Add context only for HTTP eventsif (event.optBoolean("characteristics.has_request")) {event.put("event_properties.api_client", apiClientName);event.put("event_properties.api_kind", "backend");}// Add context only for error eventsif (event.optBoolean("characteristics.has_error")) {event.put("event_properties.triage_owner", "mobile");event.put("event_properties.triage_severity", "error");}return event;};Dynatrace.addEventModifier(modifier);}