-
Notifications
You must be signed in to change notification settings - Fork 1
Capture application logs #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture application logs #52
Conversation
WalkthroughAdds thread-local log capture via a new Logback appender and LogRecord DTO, wires captured logs through request logging and RequestLogItem, exposes a config flag, integrates capture start/stop in the Spring filter/autoconfiguration, updates ConsumerRegistry, and adjusts tests for capture and serialization. (50 words) Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
============================================
+ Coverage 77.25% 78.20% +0.95%
- Complexity 326 358 +32
============================================
Files 32 34 +2
Lines 1121 1184 +63
Branches 140 150 +10
============================================
+ Hits 866 926 +60
- Misses 172 175 +3
Partials 83 83 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/test/java/io/apitally/common/RequestLoggerTest.java (1)
71-112: Fix failing test: enable log capture before asserting logsCI shows
logsNodeis null intestEndToEnd.logCaptureEnableddefaults tofalse, so the provided logs get dropped inRequestLogger.logRequest(...). Enable log capture in the test before asserting on logs.✅ Suggested fix
`@Test` void testEndToEnd() { + requestLoggingConfig.setLogCaptureEnabled(true); Header[] requestHeaders = new Header[] { new Header("User-Agent", "Test"), }; @@ List<LogRecord> logs = new ArrayList<>(); logs.add(new LogRecord(System.currentTimeMillis() / 1000.0, "test.Logger", "INFO", "Test log message")); requestLogger.logRequest(request, response, exception, logs);
🤖 Fix all issues with AI agents
In `@src/main/java/io/apitally/spring/ApitallyAutoConfiguration.java`:
- Around line 30-32: ApitallyAppender.register() currently assumes Logback by
casting LoggerFactory.getILoggerFactory() to
ch.qos.logback.classic.LoggerContext, which can throw ClassCastException for
other SLF4J backends; modify ApitallyAppender.register() to first check if
org.slf4j.LoggerFactory.getILoggerFactory() is an instance of
ch.qos.logback.classic.LoggerContext before casting, and if not, log a safe
warning via SLF4J and return without registering; also wrap the registration
logic in a try/catch(ClassCastException | LinkageError) that logs a non-fatal
warning and aborts registration so startup does not fail even when
ApitallyAutoConfiguration invokes register().
🧹 Nitpick comments (1)
src/main/java/io/apitally/common/RequestLogger.java (1)
151-190: Consider adding a backward-compatible overload forlogRequestThe signature change can break external users of this SDK. If
RequestLoggeris part of the public API, consider keeping the old overload delegating to the new one (or explicitly bump major version / document the break).♻️ Suggested overload
+ public void logRequest(Request request, Response response, Exception exception) { + logRequest(request, response, exception, null); + } + public void logRequest(Request request, Response response, Exception exception, List<LogRecord> logs) { if (!enabled || suspendUntil != null && suspendUntil > System.currentTimeMillis()) { return; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.github/workflows/tests.yaml:
- Around line 41-43: The workflow matrix includes an invalid Spring Boot
version; remove "3.5.9" from the spring-boot matrix so it lists only released
versions (keep spring-boot: [3.0.13, 3.1.12, 3.2.12, 3.3.8, 3.4.3]) to prevent
Maven Central resolution failures; update the matrix entry named "spring-boot"
in the tests.yaml matrix block accordingly.
🧹 Nitpick comments (1)
src/test/java/io/apitally/common/RequestLoggerTest.java (1)
108-114: Consider adding timestamp validation for completeness.The
LogRecordincludes atimestampfield that is set when creating the test log record (line 73), but the assertions only validatelogger,level, andmessage. Adding a timestamp assertion would ensure the field is correctly serialized.💡 Suggested enhancement
JsonNode logsNode = jsonNode.get("logs"); assertTrue(logsNode.isArray()); assertEquals(1, logsNode.size()); + assertTrue(logsNode.get(0).has("timestamp")); + assertTrue(logsNode.get(0).get("timestamp").asDouble() > 0); assertEquals("test.Logger", logsNode.get(0).get("logger").asText()); assertEquals("INFO", logsNode.get(0).get("level").asText()); assertEquals("Test log message", logsNode.get(0).get("message").asText());
Summary by CodeRabbit
New Features
Configuration
Tests
✏️ Tip: You can customize this high-level summary in your review settings.