Skip to content

Commit

Permalink
Consume sdk time method from EmbraceInternalInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed Oct 24, 2023
1 parent 92f623f commit 5db8dae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public EmbraceOkHttp3ApplicationInterceptor() {

@Override
public Response intercept(Chain chain) throws IOException {
long startTime = embrace.getSdkApi().getSdkCurrentTime();
long startTime = embrace.getInternalInterface().getSdkCurrentTime();
Request request = chain.request();
try {
// we are not interested in response, just proceed
Expand All @@ -62,7 +62,7 @@ public Response intercept(Chain chain) throws IOException {
urlString,
HttpMethod.fromString(request.method()),
startTime,
embrace.getSdkApi().getSdkCurrentTime(),
embrace.getInternalInterface().getSdkCurrentTime(),
causeName(e, UNKNOWN_EXCEPTION),
causeMessage(e, UNKNOWN_MESSAGE),
request.header(embrace.getTraceIdHeader()),
Expand All @@ -84,7 +84,7 @@ public Response intercept(Chain chain) throws IOException {
urlString,
HttpMethod.fromString(request.method()),
startTime,
embrace.getSdkApi().getSdkCurrentTime(),
embrace.getInternalInterface().getSdkCurrentTime(),
errorType != null ? errorType : UNKNOWN_EXCEPTION,
errorMessage != null ? errorMessage : UNKNOWN_MESSAGE,
request.header(embrace.getTraceIdHeader()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public Response intercept(Chain chain) throws IOException {
long preRequestClockOffset = sdkClockOffset();
boolean networkSpanForwardingEnabled = embrace.getInternalInterface().isNetworkSpanForwardingEnabled();


String traceparent = null;
if (networkSpanForwardingEnabled && originalRequest.header(TRACEPARENT_HEADER_NAME) == null) {
traceparent = embrace.generateW3cTraceparent();
Expand Down Expand Up @@ -260,6 +259,6 @@ private byte[] getRequestBody(final Request request) {
* determining client-side timestamps.
*/
private long sdkClockOffset() {
return embrace.getSdkApi().getSdkCurrentTime() - System.currentTimeMillis();
return embrace.getInternalInterface().getSdkCurrentTime() - System.currentTimeMillis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal class EmbraceOkHttp3InterceptorsTest {
every { mockInternalInterface.shouldCaptureNetworkBody(any(), "POST") } answers { true }
every { mockInternalInterface.shouldCaptureNetworkBody(any(), "GET") } answers { false }
every { mockInternalInterface.isNetworkSpanForwardingEnabled() } answers { isNetworkSpanForwardingEnabled }
every { mockInternalInterface.getSdkCurrentTime() } answers { System.currentTimeMillis() }
applicationInterceptor = EmbraceOkHttp3ApplicationInterceptor(mockEmbrace)
preNetworkInterceptorTestInterceptor = TestInspectionInterceptor(
beforeRequestSent = { request -> preNetworkInterceptorBeforeRequestSupplier.invoke(request) },
Expand Down Expand Up @@ -112,7 +113,6 @@ internal class EmbraceOkHttp3InterceptorsTest {
every { mockEmbrace.isStarted } answers { isSDKStarted }
every { mockEmbrace.recordNetworkRequest(capture(capturedEmbraceNetworkRequest)) } answers { }
every { mockEmbrace.generateW3cTraceparent() } answers { GENERATED_TRACEPARENT }
every { mockEmbrace.sdkApi.getSdkCurrentTime() } answers { System.currentTimeMillis() }
every { mockEmbrace.internalInterface } answers { mockInternalInterface }
}

Expand Down Expand Up @@ -188,7 +188,7 @@ internal class EmbraceOkHttp3InterceptorsTest {
server.enqueue(createBaseMockResponse())
runGetRequest()
verify(exactly = 0) { mockInternalInterface.isNetworkSpanForwardingEnabled() }
verify(exactly = 0) { mockEmbrace.internalInterface.shouldCaptureNetworkBody(any(), any()) }
verify(exactly = 0) { mockInternalInterface.shouldCaptureNetworkBody(any(), any()) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public EmbraceUrlConnectionOverride(@NonNull T connection, boolean enableWrapIoS
this.connection = connection;
this.enableWrapIoStreams = enableWrapIoStreams;
this.embrace = embrace;
this.createdTime = embrace.getSdkApi().getSdkCurrentTime();
this.createdTime = embrace.getInternalInterface().getSdkCurrentTime();
this.callId = UUID.randomUUID().toString();
}

Expand Down Expand Up @@ -358,7 +358,7 @@ public long getHeaderFieldLong(@NonNull String name, long defaultValue) {
@Override
@Nullable
public Map<String, List<String>> getHeaderFields() {
final long startTime = embrace.getSdkApi().getSdkCurrentTime();
final long startTime = embrace.getInternalInterface().getSdkCurrentTime();
cacheResponseData();
internalLogNetworkCall(startTime);
return headerFields.get();
Expand All @@ -371,7 +371,7 @@ private <R> R retrieveHeaderField(@Nullable String name,
if (name == null) {
return null;
}
long startTime = embrace.getSdkApi().getSdkCurrentTime();
long startTime = embrace.getInternalInterface().getSdkCurrentTime();

Check warning on line 374 in embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/network/http/EmbraceUrlConnectionOverride.java

View check run for this annotation

Codecov / codecov/patch

embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/network/http/EmbraceUrlConnectionOverride.java#L374

Added line #L374 was not covered by tests
if (shouldInterceptHeaderRetrieval(name)) {
// Strip the content encoding and length headers, as we transparently ungzip the content
return defaultValue;
Expand Down Expand Up @@ -473,7 +473,7 @@ public String getRequestProperty(@NonNull String key) {
@Override
public int getResponseCode() {
identifyTraceId();
long startTime = embrace.getSdkApi().getSdkCurrentTime();
long startTime = embrace.getInternalInterface().getSdkCurrentTime();
cacheResponseData();
internalLogNetworkCall(startTime);
return responseCode.get();
Expand All @@ -483,7 +483,7 @@ public int getResponseCode() {
@Nullable
public String getResponseMessage() throws IOException {
identifyTraceId();
long startTime = embrace.getSdkApi().getSdkCurrentTime();
long startTime = embrace.getInternalInterface().getSdkCurrentTime();

Check warning on line 486 in embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/network/http/EmbraceUrlConnectionOverride.java

View check run for this annotation

Codecov / codecov/patch

embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/network/http/EmbraceUrlConnectionOverride.java#L486

Added line #L486 was not covered by tests
String responseMsg = this.connection.getResponseMessage();
cacheResponseData();
internalLogNetworkCall(startTime);
Expand Down Expand Up @@ -548,7 +548,7 @@ public boolean usingProxy() {
* ignored.
*/
synchronized void internalLogNetworkCall(long startTime) {
internalLogNetworkCall(startTime, embrace.getSdkApi().getSdkCurrentTime(), false, null);
internalLogNetworkCall(startTime, embrace.getInternalInterface().getSdkCurrentTime(), false, null);
}

/**
Expand Down Expand Up @@ -792,7 +792,7 @@ public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
@Nullable
private InputStream getWrappedInputStream(InputStream connectionInputStream) {
identifyTraceId();
long startTime = embrace.getSdkApi().getSdkCurrentTime();
long startTime = embrace.getInternalInterface().getSdkCurrentTime();

InputStream in = null;
if (shouldUncompressGzip()) {
Expand Down

0 comments on commit 5db8dae

Please sign in to comment.