Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3420,6 +3420,7 @@ public class io/sentry/SentryOptions {
public fun getMaxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize;
public fun getMaxSpans ()I
public fun getMaxTraceFileSize ()J
public fun getMetrics ()Lio/sentry/SentryOptions$Metrics;
public fun getModulesLoader ()Lio/sentry/internal/modules/IModulesLoader;
public fun getOnDiscard ()Lio/sentry/SentryOptions$OnDiscardCallback;
public fun getOnOversizedEvent ()Lio/sentry/SentryOptions$OnOversizedEventCallback;
Expand Down Expand Up @@ -3572,6 +3573,7 @@ public class io/sentry/SentryOptions {
public fun setMaxRequestBodySize (Lio/sentry/SentryOptions$RequestSize;)V
public fun setMaxSpans (I)V
public fun setMaxTraceFileSize (J)V
public fun setMetrics (Lio/sentry/SentryOptions$Metrics;)V
public fun setModulesLoader (Lio/sentry/internal/modules/IModulesLoader;)V
public fun setOnDiscard (Lio/sentry/SentryOptions$OnDiscardCallback;)V
public fun setOnOversizedEvent (Lio/sentry/SentryOptions$OnOversizedEventCallback;)V
Expand Down Expand Up @@ -3626,10 +3628,6 @@ public abstract interface class io/sentry/SentryOptions$BeforeBreadcrumbCallback
public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)Lio/sentry/Breadcrumb;
}

public abstract interface class io/sentry/SentryOptions$BeforeEmitMetricCallback {
public abstract fun execute (Ljava/lang/String;Ljava/util/Map;)Z
}

public abstract interface class io/sentry/SentryOptions$BeforeEnvelopeCallback {
public abstract fun execute (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
}
Expand Down Expand Up @@ -3683,6 +3681,18 @@ public abstract interface class io/sentry/SentryOptions$Logs$BeforeSendLogCallba
public abstract fun execute (Lio/sentry/SentryLogEvent;)Lio/sentry/SentryLogEvent;
}

public final class io/sentry/SentryOptions$Metrics {
public fun <init> ()V
public fun getBeforeSend ()Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;
public fun isEnabled ()Z
public fun setBeforeSend (Lio/sentry/SentryOptions$Metrics$BeforeSendMetricCallback;)V
public fun setEnabled (Z)V
}

public abstract interface class io/sentry/SentryOptions$Metrics$BeforeSendMetricCallback {
public abstract fun execute (Ljava/lang/Object;)Ljava/lang/Object;
}

public abstract interface class io/sentry/SentryOptions$OnDiscardCallback {
public abstract fun execute (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;Ljava/lang/Long;)V
}
Expand Down
87 changes: 73 additions & 14 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ public class SentryOptions {

private @NotNull SentryOptions.Logs logs = new SentryOptions.Logs();

private @NotNull SentryOptions.Metrics metrics = new SentryOptions.Metrics();

private @NotNull ISocketTagger socketTagger = NoOpSocketTagger.getInstance();

/** Runtime manager to manage runtime policies, like StrictMode on Android. */
Expand Down Expand Up @@ -3261,20 +3263,6 @@ public interface BeforeEnvelopeCallback {
void execute(@NotNull SentryEnvelope envelope, @Nullable Hint hint);
}

/** The BeforeEmitMetric callback */
@ApiStatus.Experimental
public interface BeforeEmitMetricCallback {

/**
* A callback which gets called right before a metric is about to be emitted.
*
* @param key the metric key
* @param tags the metric tags
* @return true if the metric should be emitted, false otherwise
*/
boolean execute(@NotNull String key, @Nullable Map<String, String> tags);
}

/**
* Creates SentryOptions instance without initializing any of the internal parts.
*
Expand Down Expand Up @@ -3537,6 +3525,16 @@ public void setLogs(@NotNull SentryOptions.Logs logs) {
this.logs = logs;
}

@ApiStatus.Experimental
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New APIs should not be marked Experimental

public @NotNull SentryOptions.Metrics getMetrics() {
return metrics;
}

@ApiStatus.Experimental
public void setMetrics(@NotNull SentryOptions.Metrics metrics) {
this.metrics = metrics;
}

public static final class Proxy {
private @Nullable String host;
private @Nullable String port;
Expand Down Expand Up @@ -3741,6 +3739,67 @@ public interface BeforeSendLogCallback {
}
}

public static final class Metrics {

/** Whether Sentry Metrics feature is enabled and metrics are sent to Sentry. */
private boolean enable = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to true in a follow up PR


/**
* This function is called with a metric key and tags and can return false to skip sending the
* metric
*/
private @Nullable BeforeSendMetricCallback beforeSend;

/**
* Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
*
* @return true if Sentry Metrics should be enabled
*/
public boolean isEnabled() {
return enable;
}

/**
* Whether Sentry Metrics feature is enabled and metrics are sent to Sentry.
*
* @param enableMetrics true if Sentry Metrics should be enabled
*/
public void setEnabled(boolean enableMetrics) {
this.enable = enableMetrics;
}

/**
* Returns the BeforeSendMetric callback
*
* @return the beforeSend callback or null if not set
*/
public @Nullable BeforeSendMetricCallback getBeforeSend() {
return beforeSend;
}

/**
* Sets the beforeSend callback for metrics
*
* @param beforeSend the beforeSend callback for metrics
*/
public void setBeforeSend(@Nullable BeforeSendMetricCallback beforeSend) {
this.beforeSend = beforeSend;
}

public interface BeforeSendMetricCallback {

/**
* A callback which gets called right before a metric is about to be sent.
*
* @param metric the metric
* @return the original metric, mutated metric or null if metric was dropped
*/
// TODO replace with SentryMetric
@Nullable
Object execute(@NotNull Object metric);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature updated in follow-up PRs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need any kind of hint here? just wondering if it makes sense to add it now to not break this API in the future in case we need it (i'm imagining if we start sending default metrics like Android's AppExitReasons, the hint could be a good place to expose some information along)

}
}

@ApiStatus.Experimental
public @NotNull DistributionOptions getDistribution() {
return distribution;
Expand Down
Loading