Dynatrace allows you to send custom events to track business metrics or application-specific data. You can also enrich all events with additional context using event modifiers.
Event and session properties must be configured before they can be used. Incoming event and session properties that are not configured are dropped during event ingest. Read more about configuring custom events and session properties.
Use SendEvent() to report custom events with properties. Property keys must be prefixed with event_properties..
using Dynatrace.MAUI;double value = 149.99;var event = new EventData().AddEventProperty("event_properties.checkout_step": "payment_confirmed").AddEventProperty("event_properties.cart_value", value).AddEventProperty("event_properties.item_count", 3);Agent.Instance.SendEvent(event);
event_properties..Valid examples:
event_properties.checkout_stepevent_properties.cart.total_valueevent_properties.user_tierEvent modifiers allow you to intercept and modify all events before they are sent to Dynatrace. Use them to add common properties, redact sensitive information, or filter events.
using Dynatrace.MAUI;class MyModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Add custom fields to production eventsfields["event_properties.app_build"] = "1.2.3";fields["event_properties.environment"] = "production";return fields;}}...Agent.Instance.AddEventModifier(new MyModifier(event));
Return null to discard an event:
using Dynatrace.MAUI;class MyModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Discard events from test usersif (fields["event_properties.is_test_user"] == true){return null; // Discard event}return fields;}}...Agent.Instance.AddEventModifier(new MyModifier(event));
using Dynatrace.MAUI;class MyModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Redact email addresses from custom propertiesif (fields.ContainsKey("event_properties.user_email")){fields["event_properties.user_email"] = "[REDACTED]";}return fields;}}...Agent.Instance.AddEventModifier(new MyModifier(event));
using Dynatrace.MAUI;// Remove the modifier when no longer neededAgent.Instance.RemoveEventModifier(MyModifier);
event_properties. / session_properties. prefix)._, and dot ..Event modifiers have restrictions on which fields can be modified to ensure data integrity.
The following fields can be modified:
event_properties.*—custom event properties.session_properties.*—session properties (only on session property events).url.full—the complete request URL.exception.stack_trace—exception stack traces.Most standard Dynatrace fields cannot be modified, including:
start_timehttp.request.methodhttp.response.status_codespan.idtrace.idAttempting to modify read-only fields will have no effect. The original values will be preserved.
using Dynatrace.MAUI;class FeatureFlagModifier : IEventModifier{var featureFlags = new Dictionary<string, object>{{ "checkout_v2", true },{ "new_payment_flow", false },{ "enhanced_search", true }}public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){foreach (var entry in fields){fields[$"event_properties.ff_{entry.Key}"] = entry.Value;}return fields;}}...Agent.Instance.AddEventModifier(new FeatureFlagModifier(event));
using Dynatrace.MAUI;class EnrichmentModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Add experiment tracking to checkout eventsif (fields.ContainsKey("event_properties.checkout_step")){fields["event_properties.experiment_id"] = "checkout_flow_v2";fields["event_properties.variant"] = "treatment_a";}return fields;}}...Agent.Instance.AddEventModifier(new EnrichmentModifier(event));