Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: Apply options and environment from options
  • Loading branch information
bruno-garcia committed Oct 24, 2019
commit 75a53ee7306bcfbf8c7429d511453341c9c3eb3c
8 changes: 8 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public SentryClient(SentryOptions options, @Nullable AsyncConnection connection)
public SentryId captureEvent(SentryEvent event, @Nullable Scope scope) {
log(options.getLogger(), SentryLevel.DEBUG, "Capturing event: %s", event.getEventId());

// TODO: To be done in the main processor
if (event.getRelease() == null) {
event.setRelease(options.getRelease());
}
if (event.getEnvironment() == null) {
event.setEnvironment(options.getEnvironment());
}

for (EventProcessor processor : options.getEventProcessors()) {
processor.process(event);
}
Expand Down
18 changes: 18 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class SentryOptions {
private String sentryClientName;
private BeforeSecondCallback beforeSend;
private String cacheDirPath;
private String release;
private String environment;

public void addEventProcessor(EventProcessor eventProcessor) {
eventProcessors.add(eventProcessor);
Expand Down Expand Up @@ -120,6 +122,22 @@ public void setCacheDirPath(String cacheDirPath) {
this.cacheDirPath = cacheDirPath;
}

public String getRelease() {
return release;
}

public void setRelease(String release) {
this.release = release;
}

public String getEnvironment() {
return environment;
}

public void setEnvironment(String environment) {
this.environment = environment;
}

public interface BeforeSecondCallback {
SentryEvent execute(SentryEvent event);
}
Expand Down
45 changes: 45 additions & 0 deletions sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,49 @@ class SentryClientTest {
sut.captureMessage(actual)
assertEquals(actual, sentEvent!!.message.formatted)
}

@Test
fun `when event has release, value from options not applied`() {
val event = SentryEvent()
val expected = "original"
fixture.sentryOptions.environment = "not to be applied"
event.release = expected
val sut = fixture.getSut()
sut.captureEvent(event)
verify(fixture.connection).send(event)
assertEquals(expected, event.release)
}

@Test
fun `when event doesn't have release, value from options applied`() {
val event = SentryEvent()
val expected = "original"
fixture.sentryOptions.release = expected
val sut = fixture.getSut()
sut.captureEvent(event)
verify(fixture.connection).send(event)
assertEquals(expected, event.release)
}

@Test
fun `when event has environment, value from options not applied`() {
val event = SentryEvent()
val expected = "original"
fixture.sentryOptions.environment = "not to be applied"
event.environment = expected
val sut = fixture.getSut()
sut.captureEvent(event)
verify(fixture.connection).send(event)
assertEquals(expected, event.environment)
}

@Test
fun `when event doesn't have environment, value from options applied`() {
val event = SentryEvent()
val expected = "original"
fixture.sentryOptions.environment = expected
val sut = fixture.getSut()
sut.captureEvent(event)
assertEquals(expected, event.environment)
}
}