Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert api interfaces to kotlin #858

Merged
merged 9 commits into from
May 20, 2024
Next Next commit
refactor: convert api interfaces to kotlin
  • Loading branch information
fractalwrench committed May 20, 2024
commit bf74efd1ab8ac639f4bb036e334e717ab96a083b
20 changes: 10 additions & 10 deletions embrace-android-sdk/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
<issue
id="EmbracePublicApiPackageRule"
message="Don&apos;t put classes in the io.embrace.android.embracesdk package unless they&apos;re part of the public API. Please move the new class to an appropriate package or (if you&apos;re adding to the public API) suppress this error via the lint baseline file."
errorLine1="interface EmbraceAndroidApi extends EmbraceApi {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
errorLine1="internal interface EmbraceAndroidApi : EmbraceApi {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/embrace/android/embracesdk/EmbraceAndroidApi.java"
line="13"
column="11"/>
file="src/main/java/io/embrace/android/embracesdk/EmbraceAndroidApi.kt"
line="11"
column="20"/>
</issue>

<issue
id="EmbracePublicApiPackageRule"
message="Don&apos;t put classes in the io.embrace.android.embracesdk package unless they&apos;re part of the public API. Please move the new class to an appropriate package or (if you&apos;re adding to the public API) suppress this error via the lint baseline file."
errorLine1="interface EmbraceApi extends LogsApi, MomentsApi, NetworkRequestApi, SessionApi, UserApi, TracingApi {"
errorLine2=" ~~~~~~~~~~">
errorLine1="internal interface EmbraceApi : LogsApi, MomentsApi, NetworkRequestApi, SessionApi, UserApi, TracingApi {"
errorLine2=" ~~~~~~~~~~">
<location
file="src/main/java/io/embrace/android/embracesdk/EmbraceApi.java"
line="17"
column="11"/>
file="src/main/java/io/embrace/android/embracesdk/EmbraceApi.kt"
line="14"
column="20"/>
</issue>

<issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.embrace.android.embracesdk.internal.EmbraceInternalInterface;
import io.embrace.android.embracesdk.internal.Systrace;
import io.embrace.android.embracesdk.network.EmbraceNetworkRequest;
import io.embrace.android.embracesdk.payload.PushNotificationBreadcrumb;
import io.embrace.android.embracesdk.spans.EmbraceSpan;
import io.embrace.android.embracesdk.spans.EmbraceSpanEvent;
import io.embrace.android.embracesdk.spans.ErrorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,115 +1,116 @@
package io.embrace.android.embracesdk;
package io.embrace.android.embracesdk

import android.content.Context;

import androidx.annotation.NonNull;
import android.content.Context

/**
* Declares the functions that consist of Embrace's public API - specifically
* those that are only declared on Android. You should not use
* {@link EmbraceAndroidApi} directly or implement it in your own custom classes,
* as new functions may be added in future. Use the {@link Embrace} class instead.
* [EmbraceAndroidApi] directly or implement it in your own custom classes,
* as new functions may be added in future. Use the [Embrace] class instead.
*/
interface EmbraceAndroidApi extends EmbraceApi {
internal interface EmbraceAndroidApi : EmbraceApi {

/**
* Starts instrumentation of the Android application using the Embrace SDK. This should be
* called during creation of the application, as early as possible.
* <p>
* See <a href="https://embrace.io/docs/android/">Embrace Docs</a> for
*
* See [Embrace Docs](https://embrace.io/docs/android/) for
* integration instructions. For compatibility with other networking SDKs such as Akamai,
* the Embrace SDK must be initialized after any other SDK.
*
* @param context an instance of the application context
*/
void start(@NonNull Context context);
fun start(context: Context)

/**
* Starts instrumentation of the Android application using the Embrace SDK. This should be
* called during creation of the application, as early as possible.
* <p>
* See <a href="https://embrace.io/docs/android/">Embrace Docs</a> for
*
* See [Embrace Docs](https://embrace.io/docs/android/) for
* integration instructions. For compatibility with other networking SDKs such as Akamai,
* the Embrace SDK must be initialized after any other SDK.
*
* @param context an instance of context
* @param appFramework the AppFramework of the application
*/
void start(@NonNull Context context,
@NonNull Embrace.AppFramework appFramework);
fun start(
context: Context,
appFramework: Embrace.AppFramework
)

/**
* Starts instrumentation of the Android application using the Embrace SDK. This should be
* called during creation of the application, as early as possible.
* <p>
* See <a href="https://embrace.io/docs/android/">Embrace Docs</a> for
*
* See [Embrace Docs](https://embrace.io/docs/android/) for
* integration instructions. For compatibility with other networking SDKs such as Akamai,
* the Embrace SDK must be initialized after any other SDK.
*
* @param context an instance of context
* @param isDevMode if true, and the build type is debuggable, it
* sets the environment for all sessions to 'Development'.
*
* @deprecated Use {@link #start(Context)} instead. The isDevMode parameter has no effect.
* sets the environment for all sessions to 'Development'.
*/
@Deprecated
void start(@NonNull Context context,
boolean isDevMode);
@Deprecated("Use {@link #start(Context)} instead. The isDevMode parameter has no effect.")
fun start(
context: Context,
isDevMode: Boolean
)

/**
* Starts instrumentation of the Android application using the Embrace SDK. This should be
* called during creation of the application, as early as possible.
* <p>
* See <a href="https://embrace.io/docs/android/">Embrace Docs</a> for
*
* See [Embrace Docs](https://embrace.io/docs/android/) for
* integration instructions. For compatibility with other networking SDKs such as Akamai,
* the Embrace SDK must be initialized after any other SDK.
*
* @param context an instance of context
* @param isDevMode if true, and the build type is debuggable, it
* sets the environment for all sessions to 'Development'.
* sets the environment for all sessions to 'Development'.
* @param appFramework the AppFramework of the application
*
* @deprecated Use {@link #start(Context, Embrace.AppFramework)} instead. The isDevMode parameter has no effect.
*/
@Deprecated
void start(@NonNull Context context,
boolean isDevMode,
@NonNull Embrace.AppFramework appFramework);
@Deprecated("Use {@link #start(Context, Embrace.AppFramework)} instead. The isDevMode parameter has no effect.")
fun start(
context: Context,
isDevMode: Boolean,
appFramework: Embrace.AppFramework
)

/**
* Whether or not the SDK has been started.
*
* @return true if the SDK is started, false otherwise
*/
boolean isStarted();
val isStarted: Boolean

/**
* Records that a view 'started'. You should call this when your app starts displaying an
* activity, a fragment, a screen, or any custom UI element, and you want to capture a
* breadcrumb that this happens.
* <p>
* A matching call to {@link #endView(String)} must be made when the view is no longer
*
* A matching call to [.endView] must be made when the view is no longer
* displayed.
* <p>
*
* A maximum of 100 breadcrumbs will be recorded per session, with a maximum length of 256
* characters per view name.
*
* @param name the name of the view to log
*/
boolean startView(@NonNull String name);
fun startView(name: String): Boolean

/**
* Records that a view 'ended'. You should call this when your app stops displaying an
* activity, a fragment, a screen, or any custom UI element, and you want to capture a
* breadcrumb that this happens.
* <p>
* A matching call to {@link #startView(String)} must be made when the view is first
*
* A matching call to [.startView] must be made when the view is first
* displayed, or no breadcrumb will be logged.
* <p>
*
* A maximum of 100 breadcrumbs will be recorded per session, with a maximum length of 256
* characters per view name.
*
* @param name the name of the view to log
*/
boolean endView(@NonNull String name);
fun endView(name: String): Boolean
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
package io.embrace.android.embracesdk;
package io.embrace.android.embracesdk

import android.webkit.ConsoleMessage;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.embrace.android.embracesdk.spans.TracingApi;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import android.webkit.ConsoleMessage
import io.embrace.android.embracesdk.Embrace.LastRunEndState
import io.embrace.android.embracesdk.spans.TracingApi
import io.opentelemetry.sdk.logs.export.LogRecordExporter
import io.opentelemetry.sdk.trace.export.SpanExporter

/**
* Declares the functions that consist of Embrace's public API. You should not use
* {@link EmbraceApi} directly or implement it in your own custom classes,
* as new functions may be added in future. Use the {@link Embrace} class instead.
* [EmbraceApi] directly or implement it in your own custom classes,
* as new functions may be added in future. Use the [Embrace] class instead.
*/
interface EmbraceApi extends LogsApi, MomentsApi, NetworkRequestApi, SessionApi, UserApi, TracingApi {
internal interface EmbraceApi : LogsApi, MomentsApi, NetworkRequestApi, SessionApi, UserApi, TracingApi {

/**
* Sets a custom app ID that overrides the one specified at build time. Must be called before
* the SDK is started.
*
* @param appId custom app ID
* @return true if the app ID could be set, false otherwise.
*/
boolean setAppId(@NonNull String appId);
fun setAppId(appId: String): Boolean

/**
* Adds a breadcrumb.
* <p>
*
* Breadcrumbs track a user's journey through the application and will be shown on the timeline.
*
* @param message the name of the breadcrumb to log
*/
void addBreadcrumb(@NonNull String message);
fun addBreadcrumb(message: String)

/**
* Retrieve the HTTP request header to extract trace ID from.
*
* @return the Trace ID header.
*/
@NonNull
String getTraceIdHeader();
val traceIdHeader: String

/**
* Randomly generate a W3C-compliant traceparent
*/
@NonNull
String generateW3cTraceparent();
fun generateW3cTraceparent(): String

/**
* Get the user identifier assigned to the device by Embrace
*
* @return the device identifier created by Embrace
*/
@NonNull
String getDeviceId();
val deviceId: String

/**
* Listen to performance-tracking JavaScript previously embedded in the website's code.
Expand All @@ -62,7 +57,7 @@ interface EmbraceApi extends LogsApi, MomentsApi, NetworkRequestApi, SessionApi,
* @param tag a name used to identify the WebView being tracked
* @param consoleMessage the console message collected from the WebView
*/
void trackWebViewPerformance(@NonNull String tag, @NonNull ConsoleMessage consoleMessage);
fun trackWebViewPerformance(tag: String, consoleMessage: ConsoleMessage)

/**
* Listen to performance-tracking JavaScript previously embedded in the website's code.
Expand All @@ -71,36 +66,34 @@ interface EmbraceApi extends LogsApi, MomentsApi, NetworkRequestApi, SessionApi,
* @param tag a name used to identify the WebView being tracked
* @param message the console message collected from the WebView
*/
void trackWebViewPerformance(@NonNull String tag, @NonNull String message);
fun trackWebViewPerformance(tag: String, message: String)

/**
* Get the ID for the current session.
* Returns null if a session has not been started yet or the SDK hasn't been initialized.
*
* @return The ID for the current Session, if available.
*/
@Nullable
String getCurrentSessionId();
val currentSessionId: String?

/**
* Get the end state of the last run of the application.
*
* @return LastRunEndState enum value representing the end state of the last run.
*/
@NonNull
Embrace.LastRunEndState getLastRunEndState();
val lastRunEndState: LastRunEndState

/**
* Adds a [SpanExporter] to the tracer.
*
* @param spanExporter the span exporter to add
*/
void addSpanExporter(@NonNull SpanExporter spanExporter);
fun addSpanExporter(spanExporter: SpanExporter)

/**
* Adds a [LogRecordExporter] to the open telemetry logger.
*
* @param logRecordExporter the LogRecord exporter to add
*/
void addLogRecordExporter(@NonNull LogRecordExporter logRecordExporter);
fun addLogRecordExporter(logRecordExporter: LogRecordExporter)
}