Skip to content

Commit 957947d

Browse files
v3.5.0
2 parents 11817d6 + 8348130 commit 957947d

14 files changed

Lines changed: 146 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 3.5.0 (2019-05-07)
4+
5+
* Migrate version information to device.runtimeVersions
6+
[#141](https://github.com/bugsnag/bugsnag-java/pull/141)
7+
38
## 3.4.6 (2019-04-16)
49

510
* Swallow Throwables thrown when configuring bugsnag appender

bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.context.annotation.Import;
99
import org.springframework.core.SpringVersion;
1010

11+
import java.util.Map;
1112
import javax.annotation.PostConstruct;
1213

1314
/**
@@ -27,17 +28,33 @@ public class BugsnagSpringConfiguration {
2728
* Add a callback to add the version of Spring used by the application
2829
*/
2930
@Bean
30-
Callback springVersionCallback() {
31+
Callback springVersionErrorCallback() {
3132
Callback callback = new Callback() {
3233
@Override
3334
public void beforeNotify(Report report) {
34-
report.addToTab("device", "springVersion", SpringVersion.getVersion());
35+
addSpringRuntimeVersion(report.getDevice());
3536
}
3637
};
3738
bugsnag.addCallback(callback);
3839
return callback;
3940
}
4041

42+
@Bean
43+
BeforeSendSession springVersionSessionCallback() {
44+
BeforeSendSession beforeSendSession = new BeforeSendSession() {
45+
@Override
46+
public void beforeSendSession(SessionPayload payload) {
47+
addSpringRuntimeVersion(payload.getDevice());
48+
}
49+
};
50+
bugsnag.addBeforeSendSession(beforeSendSession);
51+
return beforeSendSession;
52+
}
53+
54+
private void addSpringRuntimeVersion(Map<String, Object> device) {
55+
Diagnostics.addDeviceRuntimeVersion(device, "springFramework", SpringVersion.getVersion());
56+
}
57+
4158
@Bean
4259
ScheduledTaskBeanLocator scheduledTaskBeanLocator() {
4360
return new ScheduledTaskBeanLocator();

bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.context.annotation.Conditional;
1111
import org.springframework.context.annotation.Configuration;
1212

13+
import java.util.Map;
1314
import javax.servlet.ServletRequestListener;
1415

1516
/**
@@ -26,17 +27,33 @@ class SpringBootConfiguration {
2627
* Add a callback to add the version of Spring Boot used by the application.
2728
*/
2829
@Bean
29-
Callback springBootVersionCallback() {
30+
Callback springBootVersionErrorCallback() {
3031
Callback callback = new Callback() {
3132
@Override
3233
public void beforeNotify(Report report) {
33-
report.addToTab("device", "springBootVersion", SpringBootVersion.getVersion());
34+
addSpringRuntimeVersion(report.getDevice());
3435
}
3536
};
3637
bugsnag.addCallback(callback);
3738
return callback;
3839
}
3940

41+
@Bean
42+
BeforeSendSession springBootVersionSessionCallback() {
43+
BeforeSendSession beforeSendSession = new BeforeSendSession() {
44+
@Override
45+
public void beforeSendSession(SessionPayload payload) {
46+
addSpringRuntimeVersion(payload.getDevice());
47+
}
48+
};
49+
bugsnag.addBeforeSendSession(beforeSendSession);
50+
return beforeSendSession;
51+
}
52+
53+
private void addSpringRuntimeVersion(Map<String, Object> device) {
54+
Diagnostics.addDeviceRuntimeVersion(device, "springBoot", SpringBootVersion.getVersion());
55+
}
56+
4057
/**
4158
* The {@link com.bugsnag.servlet.BugsnagServletContainerInitializer} does not work for Spring Boot, need to
4259
* register the {@link BugsnagServletRequestListener} using a Spring Boot

bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,18 @@ public void requestMetadataSetCorrectly() {
157157
}
158158

159159
@Test
160+
@SuppressWarnings("unchecked")
160161
public void springVersionSetCorrectly() {
161162
callRuntimeExceptionEndpoint();
162163

163164
Report report = verifyAndGetReport(delivery);
164165

165166
// Check that the Spring version is set as expected
166-
@SuppressWarnings(value = "unchecked") Map<String, Object> deviceMetadata =
167-
(Map<String, Object>) report.getMetaData().get("device");
168-
assertEquals(SpringVersion.getVersion(), deviceMetadata.get("springVersion"));
169-
assertEquals(SpringBootVersion.getVersion(), deviceMetadata.get("springBootVersion"));
167+
Map<String, Object> deviceMetadata = report.getDevice();
168+
Map<String, Object> runtimeVersions =
169+
(Map<String, Object>) deviceMetadata.get("runtimeVersions");
170+
assertEquals(SpringVersion.getVersion(), runtimeVersions.get("springFramework"));
171+
assertEquals(SpringBootVersion.getVersion(), runtimeVersions.get("springBoot"));
170172
}
171173

172174
@Test
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.bugsnag;
2+
3+
interface BeforeSendSession {
4+
void beforeSendSession(SessionPayload payload);
5+
}

bugsnag/src/main/java/com/bugsnag/Bugsnag.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,8 @@ public static Set<Bugsnag> uncaughtExceptionClients() {
665665
}
666666
return Collections.emptySet();
667667
}
668+
669+
void addBeforeSendSession(BeforeSendSession beforeSendSession) {
670+
sessionTracker.addBeforeSendSession(beforeSendSession);
671+
}
668672
}

bugsnag/src/main/java/com/bugsnag/Diagnostics.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ private Map<String, Object> getDefaultDeviceInfo() {
2323
map.put("hostname", DeviceCallback.getHostnameValue());
2424
map.put("osName", System.getProperty("os.name"));
2525
map.put("osVersion", System.getProperty("os.version"));
26+
map.put("runtimeVersions", getRuntimeVersions());
2627
return map;
2728
}
2829

30+
private Map<String, String> getRuntimeVersions() {
31+
Map<String, String> runtimeVersions = new HashMap<String, String>();
32+
runtimeVersions.put("javaType", System.getProperty("java.runtime.name"));
33+
runtimeVersions.put("javaVersion", System.getProperty("java.runtime.version"));
34+
return runtimeVersions;
35+
}
36+
2937
private Map<String, Object> getDefaultAppInfo(Configuration configuration) {
3038
Map<String, Object> map = new HashMap<String, Object>();
3139

@@ -37,4 +45,18 @@ private Map<String, Object> getDefaultAppInfo(Configuration configuration) {
3745
}
3846
return map;
3947
}
48+
49+
@SuppressWarnings("unchecked")
50+
static void addDeviceRuntimeVersion(Map<String, Object> device, String key, Object value) {
51+
Object obj = device.get("runtimeVersions");
52+
Map<String, Object> runtimeVersions;
53+
54+
if (obj instanceof Map) {
55+
runtimeVersions = (Map<String, Object>) obj;
56+
} else { // fallback to creating a new map if payload was mutated
57+
runtimeVersions = new HashMap<String, Object>();
58+
device.put("runtimeVersions", runtimeVersions);
59+
}
60+
runtimeVersions.put(key, value);
61+
}
4062
}

bugsnag/src/main/java/com/bugsnag/Notifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Notifier {
66

77
private static final String NOTIFIER_NAME = "Bugsnag Java";
8-
private static final String NOTIFIER_VERSION = "3.4.6";
8+
private static final String NOTIFIER_VERSION = "3.5.0";
99
private static final String NOTIFIER_URL = "https://github.com/bugsnag/bugsnag-java";
1010

1111
private String notifierName = NOTIFIER_NAME;

bugsnag/src/main/java/com/bugsnag/SessionTracker.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SessionTracker {
2121

2222
private final Semaphore flushingRequest = new Semaphore(1);
2323
private final AtomicBoolean shuttingDown = new AtomicBoolean();
24+
private final Collection<BeforeSendSession> sessionCallbacks = new ConcurrentLinkedQueue<BeforeSendSession>();
2425

2526
SessionTracker(Configuration configuration) {
2627
this.config = configuration;
@@ -88,6 +89,11 @@ private void sendSessions(Date now) {
8889
Collection<SessionCount> requestValues
8990
= new ArrayList<SessionCount>(enqueuedSessionCounts);
9091
SessionPayload payload = new SessionPayload(requestValues, config);
92+
93+
for (BeforeSendSession callback : sessionCallbacks) {
94+
callback.beforeSendSession(payload);
95+
}
96+
9197
Delivery delivery = config.sessionDelivery;
9298
delivery.deliver(config.serializer, payload, config.getSessionApiHeaders());
9399
enqueuedSessionCounts.removeAll(requestValues);
@@ -102,4 +108,8 @@ void shutdown() {
102108
sendSessions(new Date(Long.MAX_VALUE)); // flush all remaining sessions
103109
}
104110
}
111+
112+
void addBeforeSendSession(BeforeSendSession beforeSendSession) {
113+
sessionCallbacks.add(beforeSendSession);
114+
}
105115
}

bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public static void initializeCache() {
5656
public void beforeNotify(Report report) {
5757
report
5858
.addToTab("device", "osArch", System.getProperty("os.arch"))
59-
.addToTab("device", "runtimeName", System.getProperty("java.runtime.name"))
60-
.addToTab("device", "runtimeVersion", System.getProperty("java.runtime.version"))
6159
.addToTab("device", "locale", Locale.getDefault())
6260
.setDeviceInfo("hostname", getHostnameValue())
6361
.setDeviceInfo("osName", System.getProperty("os.name"))

0 commit comments

Comments
 (0)