Skip to content

Commit

Permalink
feat: introduce sentry (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd authored Jan 1, 2025
1 parent 62bdba2 commit 09de046
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Unless otherwise specified, any version comparison below is the comparison of se
### Added

- Implemented trapdoor except redstone feature (Redstone feature requires the implementation of redstone system).
- Introduced [sentry](https://www.sentry.io) to capture exception and upload them to sentry server automatically, which
helps us to track and fix bug more efficiently. Sentry is only enabled in non-dev version.

### Changed

Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ lombok = { group = "org.projectlombok", name = "lombok", version = "1.18.36" }
# Random generator
rng-simple = { module = "org.apache.commons:commons-rng-simple", version.ref = "commons-rng" }
rng-sampling = { module = "org.apache.commons:commons-rng-sampling", version.ref = "commons-rng" }
# Sentry
sentry = { group = "io.sentry", name = "sentry-log4j2", version = "7.19.1" }

[bundles]
logging = ["log4j-slf4j2-impl", "log4j-core"]
Expand All @@ -94,6 +96,7 @@ fastutil = [
"fastutil-short-sets", "fastutil-short-object-maps", "fastutil-byte-object-maps", "fastutil-io"
]
leveldb = ["leveldb", "leveldb-api"]
rng = ["rng-simple", "rng-sampling"]

[plugins]
shadow = { id = "com.gradleup.shadow", version = "8.3.5" }
Expand Down
4 changes: 2 additions & 2 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ dependencies {
implementation(libs.oshi)
implementation(libs.flatlaf)
implementation(libs.formsrt)
implementation(libs.rng.simple)
implementation(libs.rng.sampling)
implementation(libs.bundles.rng)
implementation(libs.sentry)

testImplementation(libs.bundles.junit)
testAnnotationProcessor(libs.lombok)
Expand Down
6 changes: 5 additions & 1 deletion server/src/main/java/org/allaymc/server/Allay.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.allaymc.server;

import io.netty.util.ResourceLeakDetector;
import io.sentry.Sentry;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.AllayAPI;
Expand Down Expand Up @@ -65,6 +66,10 @@ public final class Allay {

public static void main(String[] args) {
long initialTime = System.currentTimeMillis();
if (GitProperties.isDevBuild()) {
// Enable sentry only in non-dev build
Sentry.close();
}
ResourceLeakDetector.setLevel(Server.SETTINGS.networkSettings().resourceLeakDetectorLevel());
// Disable scientific notation in joml
System.setProperty("joml.format", "false");
Expand Down Expand Up @@ -120,7 +125,6 @@ private static boolean isHeadless() {
return true;
}


/**
* NOTICE: The i18n implementation must be registered before initializing allay,
* which means that you should call initI18n() before call initAllay()!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ public void prepareCommandTree(CommandTree tree) {
player.sendText("InternalSkyLight: " + lightService.getInternalSkyLight(x, y, z));
player.sendText("QueuedUpdateCount: " + lightService.getQueuedUpdateCount());
return context.success();
}, SenderType.PLAYER);
}, SenderType.PLAYER)
.root()
.key("triggerexception")
.exec(context -> {
throw new RuntimeException("Triggered exception");
});
}
}
9 changes: 7 additions & 2 deletions server/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="[%cyan{%d{HH:mm:ss} %level}] [%yellow{%t}] [%blue{%c{0}}] %minecraftFormatting{%msg}%n"/>
<PatternLayout
pattern="[%cyan{%d{HH:mm:ss} %level}] [%yellow{%t}] [%blue{%c{0}}] %minecraftFormatting{%msg}%n"/>
</Console>
<RollingRandomAccessFile name="File" fileName="logs/server.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="[%d{HH:mm:ss} %level] [%t] [%c{0}] %replace{%msg}{§([0-9]|[a|b|c|d|e|f|k|l|o|r])}{}%n"/>
<PatternLayout
pattern="[%d{HH:mm:ss} %level] [%t] [%c{0}] %replace{%msg}{§([0-9]|[a|b|c|d|e|f|k|l|o|r])}{}%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
<Sentry name="Sentry"
dsn="https://3b05ad2e5f307e5ce587efe63b444e0a@o4508567898685440.ingest.us.sentry.io/4508567997972480"/>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
<AppenderRef ref="Sentry"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit 09de046

Please sign in to comment.