Skip to content

Commit ad4e9ce

Browse files
authored
Merge 46a800c into 749ed65
2 parents 749ed65 + 46a800c commit ad4e9ce

File tree

10 files changed

+348
-15
lines changed

10 files changed

+348
-15
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ static void installDefaultIntegrations(
295295
new NetworkBreadcrumbsIntegration(context, buildInfoProvider, options.getLogger()));
296296
options.addIntegration(new TempSensorBreadcrumbsIntegration(context));
297297
options.addIntegration(new PhoneStateBreadcrumbsIntegration(context));
298+
// options.addIntegration(new SpotlightIntegration());
298299
}
299300

300301
/**

sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
android:label="@string/app_name"
2727
android:roundIcon="@mipmap/ic_launcher_round"
2828
android:theme="@style/AppTheme"
29+
android:networkSecurityConfig="@xml/network"
2930
tools:ignore="GoogleAppIndexingWarning, UnusedAttribute">
3031

3132
<activity
@@ -143,7 +144,7 @@
143144
<!-- <meta-data android:name="io.sentry.breadcrumbs.app-components" android:value="false" />-->
144145

145146
<!-- how to enable the attach screenshot feature-->
146-
<meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
147+
<meta-data android:name="io.sentry.attach-screenshot" android:value="false" />
147148

148149
<!-- how to enable the attach view hierarchy feature-->
149150
<meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<domain-config cleartextTrafficPermitted="true">
4+
<domain includeSubdomains="true">10.0.2.2</domain>
5+
</domain-config>
6+
</network-security-config>

sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ sentry.ignored-checkins=ignored_monitor_slug_1,ignored_monitor_slug_2
1414
sentry.debug=true
1515
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
1616
sentry.enable-backpressure-handling=true
17+
sentry.enable-spotlight=true
18+
sentry.enablePrettySerializationOutput=false
1719
in-app-includes="io.sentry.samples"
1820

1921
# Uncomment and set to true to enable aot compatibility

sentry/api/sentry.api

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,7 @@ public class io/sentry/SentryOptions {
21532153
public static fun empty ()Lio/sentry/SentryOptions;
21542154
public fun getBackpressureMonitor ()Lio/sentry/backpressure/IBackpressureMonitor;
21552155
public fun getBeforeBreadcrumb ()Lio/sentry/SentryOptions$BeforeBreadcrumbCallback;
2156+
public fun getBeforeEnvelopeCallback ()Lio/sentry/SentryOptions$BeforeEnvelopeCallback;
21562157
public fun getBeforeSend ()Lio/sentry/SentryOptions$BeforeSendCallback;
21572158
public fun getBeforeSendTransaction ()Lio/sentry/SentryOptions$BeforeSendTransactionCallback;
21582159
public fun getBundleIds ()Ljava/util/Set;
@@ -2215,6 +2216,7 @@ public class io/sentry/SentryOptions {
22152216
public fun getSessionTrackingIntervalMillis ()J
22162217
public fun getShutdownTimeout ()J
22172218
public fun getShutdownTimeoutMillis ()J
2219+
public fun getSpotlightConnectionUrl ()Ljava/lang/String;
22182220
public fun getSslSocketFactory ()Ljavax/net/ssl/SSLSocketFactory;
22192221
public fun getTags ()Ljava/util/Map;
22202222
public fun getTracePropagationTargets ()Ljava/util/List;
@@ -2237,6 +2239,7 @@ public class io/sentry/SentryOptions {
22372239
public fun isEnableExternalConfiguration ()Z
22382240
public fun isEnablePrettySerializationOutput ()Z
22392241
public fun isEnableShutdownHook ()Z
2242+
public fun isEnableSpotlight ()Z
22402243
public fun isEnableTimeToFullDisplayTracing ()Z
22412244
public fun isEnableUncaughtExceptionHandler ()Z
22422245
public fun isEnableUserInteractionBreadcrumbs ()Z
@@ -2256,6 +2259,7 @@ public class io/sentry/SentryOptions {
22562259
public fun setAttachThreads (Z)V
22572260
public fun setBackpressureMonitor (Lio/sentry/backpressure/IBackpressureMonitor;)V
22582261
public fun setBeforeBreadcrumb (Lio/sentry/SentryOptions$BeforeBreadcrumbCallback;)V
2262+
public fun setBeforeEnvelopeCallback (Lio/sentry/SentryOptions$BeforeEnvelopeCallback;)V
22592263
public fun setBeforeSend (Lio/sentry/SentryOptions$BeforeSendCallback;)V
22602264
public fun setBeforeSendTransaction (Lio/sentry/SentryOptions$BeforeSendTransactionCallback;)V
22612265
public fun setCacheDirPath (Ljava/lang/String;)V
@@ -2275,6 +2279,7 @@ public class io/sentry/SentryOptions {
22752279
public fun setEnableExternalConfiguration (Z)V
22762280
public fun setEnablePrettySerializationOutput (Z)V
22772281
public fun setEnableShutdownHook (Z)V
2282+
public fun setEnableSpotlight (Z)V
22782283
public fun setEnableTimeToFullDisplayTracing (Z)V
22792284
public fun setEnableTracing (Ljava/lang/Boolean;)V
22802285
public fun setEnableUncaughtExceptionHandler (Z)V
@@ -2322,6 +2327,7 @@ public class io/sentry/SentryOptions {
23222327
public fun setSessionTrackingIntervalMillis (J)V
23232328
public fun setShutdownTimeout (J)V
23242329
public fun setShutdownTimeoutMillis (J)V
2330+
public fun setSpotlightConnectionUrl (Ljava/lang/String;)V
23252331
public fun setSslSocketFactory (Ljavax/net/ssl/SSLSocketFactory;)V
23262332
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
23272333
public fun setTraceOptionsRequests (Z)V
@@ -2341,6 +2347,10 @@ public abstract interface class io/sentry/SentryOptions$BeforeBreadcrumbCallback
23412347
public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)Lio/sentry/Breadcrumb;
23422348
}
23432349

2350+
public abstract interface class io/sentry/SentryOptions$BeforeEnvelopeCallback {
2351+
public abstract fun execute (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/SentryEnvelope;
2352+
}
2353+
23442354
public abstract interface class io/sentry/SentryOptions$BeforeSendCallback {
23452355
public abstract fun execute (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
23462356
}
@@ -2714,6 +2724,14 @@ public final class io/sentry/SpanStatus$Deserializer : io/sentry/JsonDeserialize
27142724
public synthetic fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
27152725
}
27162726

2727+
public final class io/sentry/SpotlightIntegration : io/sentry/Integration, io/sentry/SentryOptions$BeforeEnvelopeCallback, java/io/Closeable {
2728+
public fun <init> ()V
2729+
public fun close ()V
2730+
public fun execute (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/SentryEnvelope;
2731+
public fun getSpotlightConnectionUrl ()Ljava/lang/String;
2732+
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
2733+
}
2734+
27172735
public final class io/sentry/SystemOutLogger : io/sentry/ILogger {
27182736
public fun <init> ()V
27192737
public fun isEnabled (Lio/sentry/SentryLevel;)Z

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
212212

213213
final boolean shouldSendAttachments = event != null;
214214
List<Attachment> attachments = shouldSendAttachments ? getAttachments(hint) : null;
215-
final SentryEnvelope envelope =
216-
buildEnvelope(event, attachments, session, traceContext, null);
215+
@Nullable
216+
SentryEnvelope envelope = buildEnvelope(event, attachments, session, traceContext, null);
217217

218218
hint.clear();
219219
if (envelope != null) {
220-
transport.send(envelope, hint);
220+
sentryId = sendEnvelope(envelope, hint);
221221
}
222222
} catch (IOException | SentryEnvelopeException e) {
223223
options.getLogger().log(SentryLevel.WARNING, e, "Capturing event %s failed.", sentryId);
@@ -445,8 +445,8 @@ public void captureUserFeedback(final @NotNull UserFeedback userFeedback) {
445445
.log(SentryLevel.DEBUG, "Capturing userFeedback: %s", userFeedback.getEventId());
446446

447447
try {
448-
final SentryEnvelope envelope = buildEnvelope(userFeedback);
449-
transport.send(envelope);
448+
@Nullable SentryEnvelope envelope = buildEnvelope(userFeedback);
449+
sendEnvelope(envelope, null);
450450
} catch (IOException e) {
451451
options
452452
.getLogger()
@@ -582,14 +582,29 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
582582

583583
try {
584584
hint.clear();
585-
transport.send(envelope, hint);
585+
return sendEnvelope(envelope, hint);
586586
} catch (IOException e) {
587587
options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope.", e);
588-
return SentryId.EMPTY_ID;
589588
}
590-
final SentryId eventId = envelope.getHeader().getEventId();
591-
if (eventId != null) {
592-
return eventId;
589+
return SentryId.EMPTY_ID;
590+
}
591+
592+
private @NotNull SentryId sendEnvelope(
593+
@NotNull final SentryEnvelope envelope, @Nullable final Hint hint) throws IOException {
594+
final @Nullable SentryOptions.BeforeEnvelopeCallback beforeEnvelopeCallback =
595+
options.getBeforeEnvelopeCallback();
596+
@Nullable SentryEnvelope envelopeToSend = envelope;
597+
if (beforeEnvelopeCallback != null) {
598+
envelopeToSend = beforeEnvelopeCallback.execute(envelope, hint);
599+
}
600+
if (envelopeToSend != null) {
601+
if (hint == null) {
602+
transport.send(envelope);
603+
} else {
604+
transport.send(envelope, hint);
605+
}
606+
final @Nullable SentryId id = envelope.getHeader().getEventId();
607+
return id != null ? id : SentryId.EMPTY_ID;
593608
} else {
594609
return SentryId.EMPTY_ID;
595610
}
@@ -665,9 +680,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
665680

666681
hint.clear();
667682
if (envelope != null) {
668-
transport.send(envelope, hint);
669-
} else {
670-
sentryId = SentryId.EMPTY_ID;
683+
sentryId = sendEnvelope(envelope, hint);
671684
}
672685
} catch (IOException | SentryEnvelopeException e) {
673686
options.getLogger().log(SentryLevel.WARNING, e, "Capturing transaction %s failed.", sentryId);
@@ -732,7 +745,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
732745
final SentryEnvelope envelope = buildEnvelope(checkIn, traceContext);
733746

734747
hint.clear();
735-
transport.send(envelope, hint);
748+
sentryId = sendEnvelope(envelope, hint);
736749
} catch (IOException e) {
737750
options.getLogger().log(SentryLevel.WARNING, e, "Capturing check-in %s failed.", sentryId);
738751
// if there was an error capturing the event, we return an emptyId

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ public class SentryOptions {
442442
/** Whether to send modules containing information about versions. */
443443
private boolean sendModules = true;
444444

445+
private @Nullable BeforeEnvelopeCallback beforeEnvelopeCallback;
446+
447+
private boolean enableSpotlight = false;
448+
449+
private @Nullable String spotlightConnectionUrl;
450+
445451
/** Contains a list of monitor slugs for which check-ins should not be sent. */
446452
@ApiStatus.Experimental private @Nullable List<String> ignoredCheckIns = null;
447453

@@ -2274,6 +2280,39 @@ public void setSessionFlushTimeoutMillis(final long sessionFlushTimeoutMillis) {
22742280
this.sessionFlushTimeoutMillis = sessionFlushTimeoutMillis;
22752281
}
22762282

2283+
@ApiStatus.Internal
2284+
@Nullable
2285+
public BeforeEnvelopeCallback getBeforeEnvelopeCallback() {
2286+
return beforeEnvelopeCallback;
2287+
}
2288+
2289+
@ApiStatus.Internal
2290+
public void setBeforeEnvelopeCallback(
2291+
@Nullable final BeforeEnvelopeCallback beforeEnvelopeCallback) {
2292+
this.beforeEnvelopeCallback = beforeEnvelopeCallback;
2293+
}
2294+
2295+
@ApiStatus.Experimental
2296+
@Nullable
2297+
public String getSpotlightConnectionUrl() {
2298+
return spotlightConnectionUrl;
2299+
}
2300+
2301+
@ApiStatus.Experimental
2302+
public void setSpotlightConnectionUrl(final @Nullable String spotlightConnectionUrl) {
2303+
this.spotlightConnectionUrl = spotlightConnectionUrl;
2304+
}
2305+
2306+
@ApiStatus.Experimental
2307+
public boolean isEnableSpotlight() {
2308+
return enableSpotlight;
2309+
}
2310+
2311+
@ApiStatus.Experimental
2312+
public void setEnableSpotlight(final boolean enableSpotlight) {
2313+
this.enableSpotlight = enableSpotlight;
2314+
}
2315+
22772316
/** The BeforeSend callback */
22782317
public interface BeforeSendCallback {
22792318

@@ -2345,6 +2384,21 @@ public interface ProfilesSamplerCallback {
23452384
Double sample(@NotNull SamplingContext samplingContext);
23462385
}
23472386

2387+
/** The BeforeSend callback */
2388+
public interface BeforeEnvelopeCallback {
2389+
2390+
/**
2391+
* Mutates or drop an event before being sent
2392+
*
2393+
* @param envelope the envelope
2394+
* @param hint the hints
2395+
* @return the original envelope or the mutated envelope or null if the envelope should be
2396+
* dropped
2397+
*/
2398+
@Nullable
2399+
SentryEnvelope execute(@NotNull SentryEnvelope envelope, @Nullable Hint hint);
2400+
}
2401+
23482402
/**
23492403
* Creates SentryOptions instance without initializing any of the internal parts.
23502404
*
@@ -2378,6 +2432,7 @@ private SentryOptions(final boolean empty) {
23782432
integrations.add(new UncaughtExceptionHandlerIntegration());
23792433

23802434
integrations.add(new ShutdownHookIntegration());
2435+
integrations.add(new SpotlightIntegration());
23812436

23822437
eventProcessors.add(new MainEventProcessor(this));
23832438
eventProcessors.add(new DuplicateEventDetectionEventProcessor(this));

0 commit comments

Comments
 (0)