Skip to content

Commit

Permalink
Move methods internal to the SDK required by other modules to interna…
Browse files Browse the repository at this point in the history
…l interface
  • Loading branch information
bidetofevil committed Oct 20, 2023
1 parent 5039b7e commit 12e634f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void _onMessageReceived(@NonNull RemoteMessage message) {
private static void handleRemoteMessage(@NonNull RemoteMessage message) {
try {
//flag process is already running to avoid track warm startup
Embrace.getInstance().setProcessStartedByNotification();
Embrace.getInstance().getInternalInterface().setProcessStartedByNotification();

String messageId = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Response intercept(Chain chain) throws IOException {
contentLength = 0L;
}

boolean shouldCaptureNetworkData = embrace.shouldCaptureNetworkBody(request.url().toString(), request.method());
boolean shouldCaptureNetworkData = embrace.getInternalInterface().shouldCaptureNetworkBody(request.url().toString(), request.method());

if (shouldCaptureNetworkData &&
ENCODING_GZIP.equalsIgnoreCase(networkResponse.header(CONTENT_ENCODING_HEADER_NAME)) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ internal class EmbraceOkHttp3InterceptorsTest {
.header(requestHeaderName, requestHeaderValue)
capturedEmbraceNetworkRequest = slot()
every { mockEmbrace.isStarted } answers { isSDKStarted }
every { mockEmbrace.shouldCaptureNetworkBody(any(), "POST") } answers { true }
every { mockEmbrace.shouldCaptureNetworkBody(any(), "GET") } answers { false }
every { mockEmbrace.internalInterface?.shouldCaptureNetworkBody(any(), "POST") } answers { true }
every { mockEmbrace.internalInterface?.shouldCaptureNetworkBody(any(), "GET") } answers { false }
every { mockEmbrace.recordNetworkRequest(capture(capturedEmbraceNetworkRequest)) } answers { }
every { mockEmbrace.generateW3cTraceparent() } answers { GENERATED_TRACEPARENT }
every { mockSdkFacade.isNetworkSpanForwardingEnabled } answers { isNetworkSpanForwardingEnabled }
Expand Down Expand Up @@ -185,7 +185,7 @@ internal class EmbraceOkHttp3InterceptorsTest {
server.enqueue(createBaseMockResponse())
runGetRequest()
verify(exactly = 0) { mockSdkFacade.isNetworkSpanForwardingEnabled }
verify(exactly = 0) { mockEmbrace.shouldCaptureNetworkBody(any(), any()) }
verify(exactly = 0) { mockEmbrace.internalInterface?.shouldCaptureNetworkBody(any(), any()) }
}

@Test
Expand Down
5 changes: 2 additions & 3 deletions embrace-android-sdk/api/embrace-android-sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public final class io/embrace/android/embracesdk/Embrace : io/embrace/android/em
public fun getUnityInternalInterface ()Lio/embrace/android/embracesdk/UnityInternalInterface;
public fun isStarted ()Z
public fun isTracingAvailable ()Z
public fun logComposeTap (Landroid/util/Pair;Ljava/lang/String;)V
public fun logCustomStacktrace ([Ljava/lang/StackTraceElement;)V
public fun logCustomStacktrace ([Ljava/lang/StackTraceElement;Lio/embrace/android/embracesdk/Severity;)V
public fun logCustomStacktrace ([Ljava/lang/StackTraceElement;Lio/embrace/android/embracesdk/Severity;Ljava/util/Map;)V
Expand Down Expand Up @@ -80,12 +79,10 @@ public final class io/embrace/android/embracesdk/Embrace : io/embrace/android/em
public fun setAppId (Ljava/lang/String;)Z
public fun setDartVersion (Ljava/lang/String;)V
public fun setEmbraceFlutterSdkVersion (Ljava/lang/String;)V
public fun setProcessStartedByNotification ()V
public fun setUserAsPayer ()V
public fun setUserEmail (Ljava/lang/String;)V
public fun setUserIdentifier (Ljava/lang/String;)V
public fun setUsername (Ljava/lang/String;)V
public fun shouldCaptureNetworkBody (Ljava/lang/String;Ljava/lang/String;)Z
public fun start (Landroid/content/Context;)V
public fun start (Landroid/content/Context;Z)V
public fun start (Landroid/content/Context;ZLio/embrace/android/embracesdk/Embrace$AppFramework;)V
Expand Down Expand Up @@ -126,6 +123,8 @@ public abstract interface class io/embrace/android/embracesdk/EmbraceInternalInt
public abstract fun recordCompletedNetworkRequest (Ljava/lang/String;Ljava/lang/String;JJJJILjava/lang/String;Lio/embrace/android/embracesdk/network/http/NetworkCaptureData;)V
public abstract fun recordIncompleteNetworkRequest (Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/embrace/android/embracesdk/network/http/NetworkCaptureData;)V
public abstract fun recordIncompleteNetworkRequest (Ljava/lang/String;Ljava/lang/String;JJLjava/lang/Throwable;Ljava/lang/String;Lio/embrace/android/embracesdk/network/http/NetworkCaptureData;)V
public abstract fun setProcessStartedByNotification ()V
public abstract fun shouldCaptureNetworkBody (Ljava/lang/String;Ljava/lang/String;)Z
}

public final class io/embrace/android/embracesdk/EmbraceSamples {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,10 @@ public LastRunEndState getLastRunEndState() {
return impl.getLastRunEndState();
}

/**
* Logs a React Native Redux Action - this is not intended for public use.
*/
@Nullable
@InternalApi
public void logRnAction(@NonNull String name, long startTime, long endTime,
@NonNull Map<String, Object> properties, int bytesSent, @NonNull String output) {
if (verifyNonNullParameters("logRnAction", name, properties, output)) {
impl.logRnAction(name, startTime, endTime, properties, bytesSent, output);
}
public EmbraceInternalInterface getInternalInterface() {
return impl.getEmbraceInternalInterface();
}

/**
Expand All @@ -593,36 +588,12 @@ public void logInternalError(@NonNull Throwable error) {
impl.logInternalError(error);
}

/**
* Logs the fact that a particular view was entered.
* <p>
* If the previously logged view has the same name, a duplicate view breadcrumb will not be
* logged.
*
* @param screen the name of the view to log
*/
@InternalApi
public void logRnView(@NonNull String screen) {
impl.logRnView(screen);
}

@Nullable
@InternalApi
public ConfigService getConfigService() {
return impl.getConfigService();
}

@InternalApi
void installUnityThreadSampler() {
getImpl().installUnityThreadSampler();
}

@Nullable
@InternalApi
public EmbraceInternalInterface getInternalInterface() {
return impl.getEmbraceInternalInterface();
}

/**
* Gets the {@link ReactNativeInternalInterface} that should be used as the sole source of
* communication with the Android SDK for React Native.
Expand All @@ -633,6 +604,30 @@ public ReactNativeInternalInterface getReactNativeInternalInterface() {
return impl.getReactNativeInternalInterface();
}

/**
* Logs a React Native Redux Action - this is not intended for public use.
*/
@InternalApi
public void logRnAction(@NonNull String name, long startTime, long endTime,
@NonNull Map<String, Object> properties, int bytesSent, @NonNull String output) {
if (verifyNonNullParameters("logRnAction", name, properties, output)) {
impl.logRnAction(name, startTime, endTime, properties, bytesSent, output);
}
}

/**
* Logs the fact that a particular view was entered.
* <p>
* If the previously logged view has the same name, a duplicate view breadcrumb will not be
* logged.
*
* @param screen the name of the view to log
*/
@InternalApi
public void logRnView(@NonNull String screen) {
impl.logRnView(screen);
}

/**
* Gets the {@link UnityInternalInterface} that should be used as the sole source of
* communication with the Android SDK for Unity.
Expand All @@ -643,6 +638,11 @@ public UnityInternalInterface getUnityInternalInterface() {
return impl.getUnityInternalInterface();
}

@InternalApi
void installUnityThreadSampler() {
getImpl().installUnityThreadSampler();
}

/**
* Gets the {@link FlutterInternalInterface} that should be used as the sole source of
* communication with the Android SDK for Flutter.
Expand Down Expand Up @@ -702,41 +702,6 @@ public void sampleCurrentThreadDuringAnrs() {
impl.sampleCurrentThreadDuringAnrs();
}

/**
* Determine if a network call should be captured based on the network capture rules
*
* @param url the url of the network call
* @param method the method of the network call
* @return the network capture rule to apply or null
*/
@InternalApi
public boolean shouldCaptureNetworkBody(@NonNull String url, @NonNull String method) {
if (isStarted()) {
return impl.shouldCaptureNetworkCall(url, method);
} else {
internalEmbraceLogger.logSDKNotInitialized("Embrace SDK is not initialized yet, cannot check for capture rules.");
return false;
}
}

@InternalApi
public void setProcessStartedByNotification() {
impl.setProcessStartedByNotification();
}

/**
* Logs taps from Compose views
*
* @param point Position of the captured clicked
* @param elementName Name of the clicked element
*/
@InternalApi
public void logComposeTap(@NonNull Pair<Float, Float> point, @NonNull String elementName) {
if (isStarted()) {
impl.getEmbraceInternalInterface().logComposeTap(point, elementName);
}
}

private boolean verifyNonNullParameters(@NonNull String functionName, @NonNull Object... params) {
for (Object param : params) {
if (param == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1662,8 +1662,13 @@ private void onActivityReported() {
}
}

public boolean shouldCaptureNetworkCall(String url, String method) {
return !networkCaptureService.getNetworkCaptureRules(url, method).isEmpty();
public boolean shouldCaptureNetworkCall(@NonNull String url, @NonNull String method) {
if (isStarted() && networkCaptureService != null) {
return !networkCaptureService.getNetworkCaptureRules(url, method).isEmpty();
} else {
internalEmbraceLogger.logSDKNotInitialized("Embrace SDK is not initialized yet, cannot check for capture rules.");
return false;
}
}

public void setProcessStartedByNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ void recordAndDeduplicateNetworkRequest(@NonNull String callId,
* @param elementName the name of the element which was tapped
*/
void logComposeTap(@NonNull Pair<Float, Float> point, @NonNull String elementName);

boolean shouldCaptureNetworkBody(@NonNull String url, @NonNull String method);

void setProcessStartedByNotification();
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,17 @@ internal class EmbraceInternalInterfaceImpl(
) {
embraceImpl.recordAndDeduplicateNetworkRequest(callId, embraceNetworkRequest)
}

/**
* Determine if a network call should be captured based on the network capture rules
*
* @param url the url of the network call
* @param method the method of the network call
* @return the network capture rule to apply or null
*/
override fun shouldCaptureNetworkBody(url: String, method: String): Boolean = embraceImpl.shouldCaptureNetworkCall(url, method)

override fun setProcessStartedByNotification() {
embraceImpl.setProcessStartedByNotification()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ private boolean hasNetworkCaptureRules() {
String url = this.connection.getURL().toString();
String method = this.connection.getRequestMethod();

return embrace.shouldCaptureNetworkBody(url, method);
return embrace.getInternalInterface().shouldCaptureNetworkBody(url, method);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ internal class EmbraceUrlConnectionOverrideTest {
mockEmbrace = mockk(relaxed = true)
every { mockEmbrace.internalInterface } answers { mockInternalInterface }
shouldCaptureNetworkBody = false
every { mockEmbrace.shouldCaptureNetworkBody(any(), any()) } answers { shouldCaptureNetworkBody }
capturedCallId = mutableListOf()
capturedEmbraceNetworkRequest = slot()
remoteNetworkSpanForwardingConfig = NetworkSpanForwardingRemoteConfig(pctEnabled = 0f)
Expand All @@ -54,6 +53,7 @@ internal class EmbraceUrlConnectionOverrideTest {
)
)
mockInternalInterface = mockk(relaxed = true)
every { mockInternalInterface.shouldCaptureNetworkBody(any(), any()) } answers { shouldCaptureNetworkBody }
every {
mockInternalInterface.recordAndDeduplicateNetworkRequest(capture(capturedCallId), capture(capturedEmbraceNetworkRequest))
} answers { }
Expand Down

0 comments on commit 12e634f

Please sign in to comment.