Skip to content

Commit

Permalink
Pull request #240: RUM-8121 event.name removed from biz events
Browse files Browse the repository at this point in the history
Merge in OP/openkit-java from feature/RUM-8121-openkit-java-bizevents-remove-auto-enrichment-of-event.name to main

* commit '2f0e84451f6eb8e3080fd4963e6e8ec8f1a85a55':
  RUM-8121 event.name removed from biz events

GitOrigin-RevId: 795605cf276ae77e8cb2c2ed6c227ab2b883dd07
  • Loading branch information
TheHighriser authored and openkitdt committed Nov 18, 2022
1 parent 0b85122 commit bddb090
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 71 deletions.
8 changes: 1 addition & 7 deletions src/main/java/com/dynatrace/openkit/protocol/Beacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ private void generateSendEventPayload(EventPayloadBuilder builder) {
.addNonOverridableAttribute(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(configuration.getOpenKitConfiguration().getPercentEncodedApplicationID()))
.addNonOverridableAttribute(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(deviceID)))
.addNonOverridableAttribute(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(getSessionNumber())))
.addNonOverridableAttribute("dt.rum.schema_version", JSONStringValue.fromString("1.0"))
.addNonOverridableAttribute("dt.rum.schema_version", JSONStringValue.fromString("1.1"))
.addOverridableAttribute(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(configuration.getOpenKitConfiguration().getApplicationVersion()))
.addOverridableAttribute(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(configuration.getOpenKitConfiguration().getOperatingSystem()))
.addOverridableAttribute(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(configuration.getOpenKitConfiguration().getManufacturer()))
Expand Down Expand Up @@ -909,12 +909,6 @@ public void sendBizEvent(String type, Map<String, JSONValue> attributes) {

builder.addNonOverridableAttribute(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString(EVENT_KIND_BIZ));

if (attributes != null && attributes.containsKey("event.name")) {
builder.addNonOverridableAttribute("event.name", attributes.get("event.name"));
} else {
builder.addNonOverridableAttribute("event.name", JSONStringValue.fromString(type));
}

sendEventPayload(builder);
}

Expand Down
77 changes: 13 additions & 64 deletions src/test/java/com/dynatrace/openkit/protocol/BeaconTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1305,15 +1305,14 @@ public void sendValidBizEvent() {
actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(62));

// then
Expand All @@ -1329,50 +1328,6 @@ public void sendValidBizEvent() {
);
}

@Test
public void sendBizEventWithNameInAttributes(){
// given
final Beacon target = createBeacon().build();
String appVersion = "1111";
when(mockOpenKitConfiguration.getApplicationVersion()).thenReturn(appVersion);
String eventType = "SomeType";

HashMap<String, JSONValue> attributes = new HashMap<>();
attributes.put("event.name", JSONStringValue.fromString("Test"));

// when
target.sendBizEvent(eventType, attributes);

HashMap<String, JSONValue> actualAttributes = new HashMap<>();
actualAttributes.put("event.type", JSONStringValue.fromString(eventType));

actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString("Test"));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(45));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
String expectedEventData =
"et=98&" + // event type
"pl=" + encodedPayload // event payload
;
verify(mockBeaconCache, times(1)).addEventData(
eq(new BeaconKey(SESSION_ID, SESSION_SEQ_NO)), // beacon key
eq(0L), // event timestamp
argThat(new EventPayloadMatcher(expectedEventData))
);
}

@Test
public void sendBizEventWithEventProviderInAttributes(){
// given
Expand All @@ -1392,7 +1347,6 @@ public void sendBizEventWithEventProviderInAttributes(){

actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString("Test"));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
Expand All @@ -1401,7 +1355,7 @@ public void sendBizEventWithEventProviderInAttributes(){
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(49));

// then
Expand Down Expand Up @@ -1438,15 +1392,14 @@ public void sendBizEventWithTypeAndDtTypeInAttributes(){
actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(45));

// then
Expand Down Expand Up @@ -1487,15 +1440,14 @@ public void sendBizEventWithDtRumSchemaVersionInAttributes(){
actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(56));

// then
Expand Down Expand Up @@ -1535,15 +1487,14 @@ public void sendBizEventWithDtRumCustomAttributeSizeInAttributes(){
actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down Expand Up @@ -1604,15 +1555,14 @@ public void sendBizEventWithEmptyPayload() {
actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(25));

// then
Expand Down Expand Up @@ -1646,15 +1596,14 @@ public void sendBizEventWithNullPayload() {
actualAttributes.put(EventPayloadAttributes.TIMESTAMP, JSONNumberValue.fromLong(0));
actualAttributes.put(EventPayloadAttributes.EVENT_KIND, JSONStringValue.fromString("BIZ_EVENT"));
actualAttributes.put(EventPayloadAttributes.EVENT_PROVIDER, JSONStringValue.fromString(APP_ID));
actualAttributes.put("event.name", JSONStringValue.fromString(eventType));
actualAttributes.put(EVENT_PAYLOAD_APPLICATION_ID, JSONStringValue.fromString(APP_ID));
actualAttributes.put(EVENT_PAYLOAD_INSTANCE_ID, JSONStringValue.fromString(String.valueOf(DEVICE_ID)));
actualAttributes.put(EVENT_PAYLOAD_SESSION_ID, JSONStringValue.fromString(String.valueOf(SESSION_ID)));
actualAttributes.put(EventPayloadAttributes.APP_VERSION, JSONStringValue.fromString(appVersion));
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));
actualAttributes.put("dt.rum.custom_attributes_size", JSONNumberValue.fromLong(25));

// then
Expand Down Expand Up @@ -1770,7 +1719,7 @@ public void sendValidEvent() {
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down Expand Up @@ -1814,7 +1763,7 @@ public void sendEventWithDtType() {
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down Expand Up @@ -1859,7 +1808,7 @@ public void sendEventWithEventProviderInAttributes() {
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down Expand Up @@ -1901,7 +1850,7 @@ public void sendEventWithDtRumSchemaInAttributes() {
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down Expand Up @@ -1973,7 +1922,7 @@ public void sendEventWithEmptyPayload() {
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down Expand Up @@ -2013,7 +1962,7 @@ public void sendEventWithNullPayload() {
actualAttributes.put(EventPayloadAttributes.OS_NAME, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MANUFACTURER, JSONStringValue.fromString(""));
actualAttributes.put(EventPayloadAttributes.DEVICE_MODEL_IDENTIFIER, JSONStringValue.fromString(""));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.0"));
actualAttributes.put("dt.rum.schema_version", JSONStringValue.fromString("1.1"));

// then
String encodedPayload = PercentEncoder.encode(JSONObjectValue.fromMap(actualAttributes).toString(), Beacon.CHARSET, Beacon.RESERVED_CHARACTERS);
Expand Down

0 comments on commit bddb090

Please sign in to comment.