Skip to content

Commit b1b4563

Browse files
committed
SF-4325 - adding APMLogData class to provide the APM project a means for providing trace information. EventAdapter updated to use APMLogData if available will fallback on existing methods.
1 parent b4b174f commit b1b4563

File tree

3 files changed

+111
-10
lines changed

3 files changed

+111
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
.project
33
.settings
44
target
5-
coverage.ec
5+
coverage.ec
6+
.idea
7+
*.iml
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.stackify.api.common.log;
2+
3+
import com.stackify.api.WebRequestDetail;
4+
5+
import java.util.Map;
6+
7+
/**
8+
* Provides means for APM to link and provide data elements from the current profiler trace.
9+
*
10+
* @author Darin Howard
11+
*/
12+
public class APMLogData {
13+
14+
/**
15+
* Details if APM has established a link to this class. When false all methods return null.
16+
*/
17+
public static boolean isLinked() {
18+
return false;
19+
}
20+
21+
public static String getTransactionId() {
22+
// empty implementation - value will be provided by apm
23+
return null;
24+
}
25+
26+
public static String getUser() {
27+
// empty implementation - value will be provided by apm
28+
return null;
29+
}
30+
31+
public static WebRequestDetail getWebRequest() {
32+
if (isLinked()) {
33+
WebRequestDetail.Builder builder = WebRequestDetail.newBuilder();
34+
builder.userIpAddress(getUserIpAddress());
35+
builder.httpMethod(getHttpMethod());
36+
builder.requestProtocol(getRequestProtocol());
37+
builder.requestUrl(getRequestUrl());
38+
builder.requestUrlRoot(getRequestUrlRoot());
39+
builder.referralUrl(getReferralUrl());
40+
builder.headers(getHeaders());
41+
builder.cookies(getCookies());
42+
builder.queryString(getQueryString());
43+
builder.sessionData(getSessionData());
44+
return builder.build();
45+
}
46+
return null;
47+
}
48+
49+
private static String getUserIpAddress() {
50+
// empty implementation - value will be provided by apm
51+
return null;
52+
}
53+
54+
private static String getHttpMethod() {
55+
// empty implementation - value will be provided by apm
56+
return null;
57+
}
58+
59+
private static String getRequestProtocol() {
60+
// empty implementation - value will be provided by apm
61+
return null;
62+
}
63+
64+
private static String getRequestUrl() {
65+
// empty implementation - value will be provided by apm
66+
return null;
67+
}
68+
69+
private static String getRequestUrlRoot() {
70+
// empty implementation - value will be provided by apm
71+
return null;
72+
}
73+
74+
private static String getReferralUrl() {
75+
// empty implementation - value will be provided by apm
76+
return null;
77+
}
78+
79+
private static Map<String, String> getHeaders() {
80+
// empty implementation - value will be provided by apm
81+
return null;
82+
}
83+
84+
private static Map<String, String> getCookies() {
85+
// empty implementation - value will be provided by apm
86+
return null;
87+
}
88+
89+
private static Map<String, String> getQueryString() {
90+
// empty implementation - value will be provided by apm
91+
return null;
92+
}
93+
94+
private static Map<String, String> getSessionData() {
95+
// empty implementation - value will be provided by apm
96+
return null;
97+
}
98+
}

src/main/java/com/stackify/api/common/log/direct/LogEventAdapter.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
*/
1616
package com.stackify.api.common.log.direct;
1717

18-
import java.util.Date;
19-
2018
import com.stackify.api.EnvironmentDetail;
2119
import com.stackify.api.LogMsg;
2220
import com.stackify.api.StackifyError;
2321
import com.stackify.api.WebRequestDetail;
2422
import com.stackify.api.common.lang.Throwables;
23+
import com.stackify.api.common.log.APMLogData;
2524
import com.stackify.api.common.log.EventAdapter;
2625
import com.stackify.api.common.log.ServletLogContext;
2726
import com.stackify.api.common.util.Maps;
2827
import com.stackify.api.common.util.Preconditions;
2928

29+
import java.util.Date;
30+
3031
/**
3132
* LogEvent
3233
* @author Eric Martin
@@ -70,14 +71,14 @@ public StackifyError getStackifyError(final LogEvent event, final Throwable exce
7071
builder.error(Throwables.toErrorItem(event.getMessage(), event.getClassName(), event.getMethodName(), event.getLineNumber()));
7172
}
7273

73-
String user = ServletLogContext.getUser();
74-
74+
String user = APMLogData.isLinked() ? APMLogData.getUser() : ServletLogContext.getUser();
75+
7576
if (user != null) {
7677
builder.userName(user);
7778
}
7879

79-
WebRequestDetail webRequest = ServletLogContext.getWebRequest();
80-
80+
WebRequestDetail webRequest = APMLogData.isLinked() ? APMLogData.getWebRequest() : ServletLogContext.getWebRequest();
81+
8182
if (webRequest != null) {
8283
builder.webRequestDetail(webRequest);
8384
}
@@ -100,9 +101,9 @@ public LogMsg getLogMsg(final LogEvent event, final StackifyError error) {
100101
if (event.getLevel() != null) {
101102
builder.level(event.getLevel().toLowerCase());
102103
}
103-
104-
String transactionId = ServletLogContext.getTransactionId();
105-
104+
105+
String transactionId = APMLogData.isLinked() ? APMLogData.getTransactionId() : ServletLogContext.getTransactionId();
106+
106107
if (transactionId != null) {
107108
builder.transId(transactionId);
108109
}

0 commit comments

Comments
 (0)