Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

few improvements identified by a pre-release list #237

Merged
merged 1 commit into from
Jan 16, 2020
Merged
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
3 changes: 2 additions & 1 deletion sentry-core/src/main/java/io/sentry/core/Dsn.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.core;

import java.net.URI;
import org.jetbrains.annotations.Nullable;

final class Dsn {
private final String projectId;
Expand Down Expand Up @@ -44,7 +45,7 @@ URI getSentryUri() {
return sentryUri;
}

Dsn(String dsn) throws InvalidDsnException {
Dsn(@Nullable String dsn) throws InvalidDsnException {
try {
URI uri = new URI(dsn);
String userInfo = uri.getUserInfo();
Expand Down
2 changes: 2 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Object hint)
}
if (breadcrumb != null) {
item.scope.addBreadcrumb(breadcrumb, false);
} else {
options.getLogger().log(SentryLevel.INFO, "Breadcrumb was dropped by beforeBreadcrumb");
}
} else {
options.getLogger().log(SentryLevel.FATAL, "Stack peek was null when addBreadcrumb");
Expand Down
30 changes: 27 additions & 3 deletions sentry-core/src/main/java/io/sentry/core/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void setUser(@Nullable User user) {
this.user = user;
}

public @NotNull List<String> getFingerprint() {
@NotNull
List<String> getFingerprint() {
return fingerprint;
}

Expand Down Expand Up @@ -93,6 +94,8 @@ void addBreadcrumb(@NotNull Breadcrumb breadcrumb, boolean executeBeforeBreadcru
}

if (breadcrumb == null) {
// options.getLogger().log(SentryLevel.INFO, "Breadcrumb was dropped by scope
Copy link
Member

Choose a reason for hiding this comment

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

Sounds fair to have this log. Perhaps in Debug mode instead?
Or remove dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually we don't have access to options object on this class, that's why, it's a TODO.
I'll try to fix this "workaround" with the Scope class and Before BreadCrumb before GA, it's a design flaw.

// beforeBreadcrumb");
return;
}
}
Expand All @@ -104,22 +107,43 @@ public void clearBreadcrumbs() {
breadcrumbs.clear();
}

public @NotNull Map<String, String> getTags() {
public void clear() {
level = null;
transaction = null;
user = null;
fingerprint.clear();
breadcrumbs.clear();
tags.clear();
extra.clear();
eventProcessors.clear();
}

@NotNull
Map<String, String> getTags() {
return tags;
}

public void setTag(@NotNull String key, @NotNull String value) {
this.tags.put(key, value);
}

public @NotNull Map<String, Object> getExtras() {
public void removeTag(@NotNull String key) {
this.tags.remove(key);
}

@NotNull
Map<String, Object> getExtras() {
return extra;
}

public void setExtra(@NotNull String key, @NotNull String value) {
this.extra.put(key, value);
}

public void removeExtra(@NotNull String key) {
this.extra.remove(key);
}

private @NotNull Queue<Breadcrumb> createBreadcrumbsList(final int maxBreadcrumb) {
return SynchronizedQueue.synchronizedQueue(new CircularFifoQueue<>(maxBreadcrumb));
}
Expand Down
23 changes: 21 additions & 2 deletions sentry-core/src/main/java/io/sentry/core/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public SentryId captureEvent(SentryEvent event, @Nullable Scope scope, @Nullable
event = applyScope(event, scope, hint);

if (event == null) {
// event dropped by the scope event processors
return SentryId.EMPTY_ID;
}
} else {
Expand All @@ -90,12 +89,26 @@ public SentryId captureEvent(SentryEvent event, @Nullable Scope scope, @Nullable

for (EventProcessor processor : options.getEventProcessors()) {
event = processor.process(event, hint);

if (event == null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped by processor: %s",
processor.getClass().getName());
break;
}
}

if (event == null) {
return SentryId.EMPTY_ID;
}

event = executeBeforeSend(event, hint);

if (event == null) {
// Event dropped by the beforeSend callback
options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by beforeSend");
return SentryId.EMPTY_ID;
}

Expand Down Expand Up @@ -153,6 +166,12 @@ private SentryEvent applyScope(SentryEvent event, @Nullable Scope scope, @Nullab
event = processor.process(event, hint);

if (event == null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped by scope processor: %s",
processor.getClass().getName());
break;
}
}
Expand Down
34 changes: 30 additions & 4 deletions sentry-core/src/main/java/io/sentry/core/SentryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;

public final class SentryEvent implements IUnknownPropertiesConsumer {
Expand Down Expand Up @@ -191,7 +192,7 @@ public void setSdk(SdkVersion sdk) {
this.sdk = sdk;
}

public List<String> getFingerprints() {
List<String> getFingerprints() {
return fingerprint;
}

Expand All @@ -214,22 +215,28 @@ public void addBreadcrumb(Breadcrumb breadcrumb) {
breadcrumbs.add(breadcrumb);
}

public Map<String, String> getTags() {
Map<String, String> getTags() {
return tags;
}

public void setTags(Map<String, String> tags) {
this.tags = tags;
}

public void removeTag(@NotNull String key) {
if (tags != null) {
tags.remove(key);
}
}

public void setTag(String key, String value) {
if (tags == null) {
tags = new HashMap<>();
}
tags.put(key, value);
}

public Map<String, Object> getExtras() {
Map<String, Object> getExtras() {
return extra;
}

Expand All @@ -244,6 +251,12 @@ public void setExtra(String key, Object value) {
extra.put(key, value);
}

public void removeExtra(@NotNull String key) {
if (extra != null) {
extra.remove(key);
}
}

public Contexts getContexts() {
return contexts;
}
Expand All @@ -263,14 +276,27 @@ public Map<String, Object> getUnknown() {
return unknown;
}

public Map<String, String> getModules() {
Map<String, String> getModules() {
return modules;
}

public void setModules(Map<String, String> modules) {
this.modules = modules;
}

public void setModule(String key, String value) {
if (modules == null) {
modules = new HashMap<>();
}
modules.put(key, value);
}

public void removeModule(@NotNull String key) {
if (modules != null) {
modules.remove(key);
}
}

public DebugMeta getDebugMeta() {
return debugMeta;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SentryOptions {
private final @NotNull List<Integration> integrations = new ArrayList<>();

private @Nullable String dsn;
private long shutdownTimeoutMills = 5000;
private long shutdownTimeoutMills = 2000; // default 2s
private boolean debug;
private boolean enableNdk = true;
private @NotNull ILogger logger = NoOpLogger.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public TransportResult send(SentryEvent event) throws IOException {
options.getLogger().log(DEBUG, "Event sent %s successfully.", event.getEventId());
return TransportResult.success();
} catch (IOException e) {
long retryAfterMs = 1000; // the default is 1s
long retryAfterMs = 60000; // the default is 60s
String retryAfterHeader = connection.getHeaderField("Retry-After");
if (retryAfterHeader != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class HttpTransportTest {

verify(fixture.serializer).serialize(eq(event), any())
assertFalse(result.isSuccess)
assertEquals(1000, result.retryMillis)
assertEquals(60000, result.retryMillis)
}

@Test
Expand All @@ -122,7 +122,7 @@ class HttpTransportTest {

verify(fixture.serializer).serialize(eq(event), any())
assertFalse(result.isSuccess)
assertEquals(1000, result.retryMillis)
assertEquals(60000, result.retryMillis)
assertEquals(-1, result.responseCode)
}
}