Skip to content

Commit

Permalink
Remove the screen name from the span name for lifecycle spans. (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwatson authored Aug 13, 2021
1 parent bb2a635 commit 4dc046a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

public class FirstFragment extends Fragment {

Expand Down Expand Up @@ -120,9 +121,11 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) {

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
int responseCode = response.code();
httpResponse.postValue("" + responseCode);
workflow.end();
try (ResponseBody body = response.body()) {
int responseCode = response.code();
httpResponse.postValue("" + responseCode);
workflow.end();
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public TrackableTracer startSpanIfNoneInProgress(String action) {
if (span != null) {
return this;
}
startSpan(trackableName + " " + action);
startSpan(action);
return this;
}

Expand All @@ -76,7 +76,7 @@ public TrackableTracer startTrackableCreation() {
Span span = startSpan(APP_START_SPAN_NAME);
span.setAttribute(START_TYPE_KEY, initialAppActivity.get() == null ? "cold" : "warm");
} else {
startSpan(trackableName + " Created");
startSpan("Created");
}
return this;
}
Expand All @@ -93,7 +93,7 @@ public TrackableTracer initiateRestartSpanIfNecessary(boolean multiActivityApp)
Span span = startSpan(APP_START_SPAN_NAME);
span.setAttribute(START_TYPE_KEY, "hot");
} else {
startSpan(trackableName + " Restarted");
startSpan("Restarted");
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package com.splunk.rum;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.Activity;

import org.junit.Before;
Expand All @@ -29,11 +34,6 @@
import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
import io.opentelemetry.sdk.trace.data.SpanData;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class NamedTrackableTracerTest {
@Rule
public OpenTelemetryRule otelTesting = OpenTelemetryRule.create();
Expand All @@ -51,7 +51,7 @@ public void restart_nonInitialActivity() {
trackableTracer.initiateRestartSpanIfNecessary(false);
trackableTracer.endActiveSpan();
SpanData span = getSingleSpan();
assertEquals("Activity Restarted", span.getName());
assertEquals("Restarted", span.getName());
assertNull(span.getAttributes().get(NamedTrackableTracer.START_TYPE_KEY));
}

Expand All @@ -71,7 +71,7 @@ public void restart_initialActivity_multiActivityApp() {
trackableTracer.initiateRestartSpanIfNecessary(true);
trackableTracer.endActiveSpan();
SpanData span = getSingleSpan();
assertEquals("Activity Restarted", span.getName());
assertEquals("Restarted", span.getName());
assertNull(span.getAttributes().get(NamedTrackableTracer.START_TYPE_KEY));
}

Expand All @@ -81,7 +81,7 @@ public void create_nonInitialActivity() {
trackableTracer.startTrackableCreation();
trackableTracer.endActiveSpan();
SpanData span = getSingleSpan();
assertEquals("Activity Created", span.getName());
assertEquals("Created", span.getName());
assertNull(span.getAttributes().get(NamedTrackableTracer.START_TYPE_KEY));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

package com.splunk.rum;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.Activity;

import org.junit.Before;
Expand All @@ -30,12 +36,6 @@
import io.opentelemetry.sdk.trace.data.EventData;
import io.opentelemetry.sdk.trace.data.SpanData;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class Pre29ActivityLifecycleCallbacksTest {
@Rule
public OpenTelemetryRule otelTesting = OpenTelemetryRule.create();
Expand Down Expand Up @@ -156,7 +156,7 @@ public void activityResumed() {

SpanData span = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Resumed", span.getName());
assertEquals("Resumed", span.getName());
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, span.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -183,7 +183,7 @@ public void activityDestroyedFromStopped() {

SpanData span = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Destroyed", span.getName());
assertEquals("Destroyed", span.getName());
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, span.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -210,7 +210,7 @@ public void activityDestroyedFromPaused() {

SpanData stoppedSpan = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Stopped", stoppedSpan.getName());
assertEquals("Stopped", stoppedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, stoppedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -223,7 +223,7 @@ public void activityDestroyedFromPaused() {

SpanData destroyedSpan = spans.get(1);

assertEquals(activity.getClass().getSimpleName() + " Destroyed", destroyedSpan.getName());
assertEquals("Destroyed", destroyedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals("ui", destroyedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -250,7 +250,7 @@ public void activityStoppedFromRunning() {

SpanData stoppedSpan = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Paused", stoppedSpan.getName());
assertEquals("Paused", stoppedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, stoppedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -263,7 +263,7 @@ public void activityStoppedFromRunning() {

SpanData destroyedSpan = spans.get(1);

assertEquals(activity.getClass().getSimpleName() + " Stopped", destroyedSpan.getName());
assertEquals("Stopped", destroyedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals("ui", destroyedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

package com.splunk.rum;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import androidx.fragment.app.Fragment;

import org.junit.Before;
Expand All @@ -30,13 +37,6 @@
import io.opentelemetry.sdk.trace.data.EventData;
import io.opentelemetry.sdk.trace.data.SpanData;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RumFragmentLifecycleCallbacksTest {
@Rule
public OpenTelemetryRule otelTesting = OpenTelemetryRule.create();
Expand All @@ -60,7 +60,7 @@ public void fragmentCreation() {

SpanData spanData = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " Created", spanData.getName());
assertEquals("Created", spanData.getName());
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, spanData.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down Expand Up @@ -90,7 +90,7 @@ public void fragmentRestored() {

SpanData spanData = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " Restored", spanData.getName());
assertEquals("Restored", spanData.getName());
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, spanData.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -115,7 +115,7 @@ public void fragmentResumed() {

SpanData spanData = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " Resumed", spanData.getName());
assertEquals("Resumed", spanData.getName());
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, spanData.getAttributes().get(SplunkRum.COMPONENT_KEY));
assertNull(spanData.getAttributes().get(SplunkRum.LAST_SCREEN_NAME_KEY));
Expand All @@ -137,7 +137,7 @@ public void fragmentPaused() {

SpanData spanData = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " Paused", spanData.getName());
assertEquals("Paused", spanData.getName());
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), spanData.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, spanData.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -161,7 +161,7 @@ public void fragmentDetachedFromActive() {

SpanData pauseSpan = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " Paused", pauseSpan.getName());
assertEquals("Paused", pauseSpan.getName());
assertEquals(fragment.getClass().getSimpleName(), pauseSpan.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), pauseSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, pauseSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -174,7 +174,7 @@ public void fragmentDetachedFromActive() {

SpanData destroyViewSpan = spans.get(1);

assertEquals(fragment.getClass().getSimpleName() + " ViewDestroyed", destroyViewSpan.getName());
assertEquals("ViewDestroyed", destroyViewSpan.getName());
assertEquals(fragment.getClass().getSimpleName(), destroyViewSpan.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), destroyViewSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, destroyViewSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -186,7 +186,7 @@ public void fragmentDetachedFromActive() {

SpanData detachSpan = spans.get(2);

assertEquals(fragment.getClass().getSimpleName() + " Destroyed", detachSpan.getName());
assertEquals("Destroyed", detachSpan.getName());
assertNotNull(detachSpan.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, detachSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
assertNull(detachSpan.getAttributes().get(SplunkRum.LAST_SCREEN_NAME_KEY));
Expand All @@ -209,7 +209,7 @@ public void fragmentDestroyedFromStopped() {

SpanData span = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " ViewDestroyed", span.getName());
assertEquals("ViewDestroyed", span.getName());
assertEquals(fragment.getClass().getSimpleName(), span.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), span.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, span.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -232,7 +232,7 @@ public void fragmentDetachedFromStopped() {

SpanData destroyViewSpan = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " ViewDestroyed", destroyViewSpan.getName());
assertEquals("ViewDestroyed", destroyViewSpan.getName());
assertEquals(fragment.getClass().getSimpleName(), destroyViewSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), destroyViewSpan.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, destroyViewSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -244,7 +244,7 @@ public void fragmentDetachedFromStopped() {

SpanData detachSpan = spans.get(1);

assertEquals(fragment.getClass().getSimpleName() + " Destroyed", detachSpan.getName());
assertEquals("Destroyed", detachSpan.getName());
assertEquals(fragment.getClass().getSimpleName(), detachSpan.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, detachSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
assertNull(detachSpan.getAttributes().get(SplunkRum.LAST_SCREEN_NAME_KEY));
Expand All @@ -267,7 +267,7 @@ public void fragmentDetached() {

SpanData detachSpan = spans.get(0);

assertEquals(fragment.getClass().getSimpleName() + " Detached", detachSpan.getName());
assertEquals("Detached", detachSpan.getName());
assertEquals(fragment.getClass().getSimpleName(), detachSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(fragment.getClass().getSimpleName(), detachSpan.getAttributes().get(NamedTrackableTracer.FRAGMENT_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, detachSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

package com.splunk.rum;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.Activity;

import org.junit.Before;
Expand All @@ -30,12 +36,6 @@
import io.opentelemetry.sdk.trace.data.EventData;
import io.opentelemetry.sdk.trace.data.SpanData;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RumLifecycleCallbacksTest {
@Rule
public OpenTelemetryRule otelTesting = OpenTelemetryRule.create();
Expand Down Expand Up @@ -176,7 +176,7 @@ public void activityResumed() {

SpanData span = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Resumed", span.getName());
assertEquals("Resumed", span.getName());
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, span.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down Expand Up @@ -205,7 +205,7 @@ public void activityDestroyedFromStopped() {

SpanData span = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Destroyed", span.getName());
assertEquals("Destroyed", span.getName());
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), span.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, span.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down Expand Up @@ -234,7 +234,7 @@ public void activityDestroyedFromPaused() {

SpanData stoppedSpan = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Stopped", stoppedSpan.getName());
assertEquals("Stopped", stoppedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, stoppedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -249,7 +249,7 @@ public void activityDestroyedFromPaused() {

SpanData destroyedSpan = spans.get(1);

assertEquals(activity.getClass().getSimpleName() + " Destroyed", destroyedSpan.getName());
assertEquals("Destroyed", destroyedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals("ui", destroyedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down Expand Up @@ -278,7 +278,7 @@ public void activityStoppedFromRunning() {

SpanData stoppedSpan = spans.get(0);

assertEquals(activity.getClass().getSimpleName() + " Paused", stoppedSpan.getName());
assertEquals("Paused", stoppedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), stoppedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals(SplunkRum.COMPONENT_UI, stoppedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand All @@ -293,7 +293,7 @@ public void activityStoppedFromRunning() {

SpanData destroyedSpan = spans.get(1);

assertEquals(activity.getClass().getSimpleName() + " Stopped", destroyedSpan.getName());
assertEquals("Stopped", destroyedSpan.getName());
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(NamedTrackableTracer.ACTIVITY_NAME_KEY));
assertEquals(activity.getClass().getSimpleName(), destroyedSpan.getAttributes().get(SplunkRum.SCREEN_NAME_KEY));
assertEquals("ui", destroyedSpan.getAttributes().get(SplunkRum.COMPONENT_KEY));
Expand Down

0 comments on commit 4dc046a

Please sign in to comment.