-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy pathLocation.java
111 lines (88 loc) · 2.7 KB
/
Location.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.datadog.iast.model;
import com.squareup.moshi.Json;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import javax.annotation.Nullable;
public final class Location {
@Nullable private final String path;
private final int line;
@Nullable private final String method;
@Nullable private Long spanId;
@Nullable private transient String serviceName;
@Nullable
@Json(name = "class")
private final String className;
private Location(
@Nullable final Long spanId,
@Nullable final String path,
final int line,
@Nullable final String className,
@Nullable final String method,
@Nullable final String serviceName) {
this.spanId = spanId;
this.path = path;
this.line = line;
this.method = method;
this.serviceName = serviceName;
this.className = className;
}
public static Location forSpanAndStack(
@Nullable final AgentSpan span, final StackTraceElement stack) {
return new Location(
spanId(span),
stack.getFileName(),
stack.getLineNumber(),
stack.getClassName(),
stack.getMethodName(),
serviceName(span));
}
public static Location forSpanAndClassAndMethod(
@Nullable final AgentSpan span, final String clazz, final String method) {
return new Location(spanId(span), null, -1, clazz, method, serviceName(span));
}
public static Location forSpanAndFileAndLine(
@Nullable final AgentSpan span, final String file, final int line) {
return new Location(spanId(span), file, line, null, null, serviceName(span));
}
public static Location forSpan(@Nullable final AgentSpan span) {
return new Location(spanId(span), null, -1, null, null, serviceName(span));
}
public static Location forClassAndMethodAndLine(String clazz, String method, int currentLine) {
return new Location(null, null, currentLine, clazz, method, null);
}
public long getSpanId() {
return spanId == null ? 0 : spanId;
}
@Nullable
public String getPath() {
return path;
}
public int getLine() {
return line;
}
@Nullable
public String getMethod() {
return method;
}
@Nullable
public String getServiceName() {
return serviceName;
}
@Nullable
public String getClassName() {
return className;
}
public void updateSpan(@Nullable final AgentSpan span) {
if (span != null) {
this.spanId = span.getSpanId();
this.serviceName = span.getServiceName();
}
}
@Nullable
private static Long spanId(@Nullable AgentSpan span) {
return span != null ? span.getSpanId() : null;
}
@Nullable
private static String serviceName(@Nullable AgentSpan span) {
return span != null ? span.getServiceName() : null;
}
}