Skip to content

Commit d917858

Browse files
committed
1 parent 53be767 commit d917858

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/main/kotlin/spp/protocol/artifact/ArtifactLanguage.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717
package spp.protocol.artifact
1818

19+
/**
20+
* Languages supported by Source++.
21+
*/
1922
enum class ArtifactLanguage {
20-
JAVA,
21-
KOTLIN,
22-
SCALA,
23-
GROOVY,
23+
JVM,
2424
PYTHON,
25-
NodeJS
25+
NODEJS
2626
}

src/main/kotlin/spp/protocol/artifact/exception/LiveStackTrace.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package spp.protocol.artifact.exception
1818

1919
import io.vertx.codegen.annotations.DataObject
2020
import io.vertx.core.json.JsonObject
21+
import spp.protocol.artifact.ArtifactLanguage
2122

2223
/**
2324
* todo: description.
@@ -30,14 +31,16 @@ class LiveStackTrace(
3031
var exceptionType: String,
3132
var message: String?,
3233
val elements: MutableList<LiveStackTraceElement>,
33-
val causedBy: LiveStackTrace? = null
34+
val causedBy: LiveStackTrace? = null,
35+
val language: ArtifactLanguage? = null
3436
) : Iterable<LiveStackTraceElement> {
3537

3638
constructor(json: JsonObject) : this(
3739
json.getString("exceptionType"),
3840
json.getString("message"),
3941
json.getJsonArray("elements").map { LiveStackTraceElement(JsonObject.mapFrom(it)) }.toMutableList(),
40-
json.getJsonObject("causedBy")?.let { LiveStackTrace(it) }
42+
json.getJsonObject("causedBy")?.let { LiveStackTrace(it) },
43+
json.getString("language")?.let { ArtifactLanguage.valueOf(it) }
4144
)
4245

4346
fun toJson(): JsonObject {
@@ -82,7 +85,7 @@ class LiveStackTrace(
8285
companion object {
8386
private const val skywalkingInterceptor =
8487
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept"
85-
private val frameRegex = Regex(
88+
private val jvmFrameRegex = Regex(
8689
"\\s*at\\s+((?:[\\w\\s](?:\\\$+|\\.|/)?)+)" +
8790
"\\.([\\w|_$\\s<>]+)\\s*\\(([^()]+(?:\\([^)]*\\))?)\\)"
8891
)
@@ -96,7 +99,7 @@ class LiveStackTrace(
9699
fun fromString(data: String): LiveStackTrace? {
97100
return when {
98101
nodeFrameRegex.containsMatchIn(data) -> extractNodeStackTrace(data)
99-
frameRegex.containsMatchIn(data) -> extractJvmStackTrace(data)
102+
jvmFrameRegex.containsMatchIn(data) -> extractJvmStackTrace(data)
100103
pythonFrameRegex.containsMatchIn(data) -> extractPythonStackTrace(data)
101104
else -> null
102105
}
@@ -116,7 +119,7 @@ class LiveStackTrace(
116119
val firstLine = data.split("\n").first()
117120
val exceptionType = firstLine.split(":").firstOrNull() ?: "n/a"
118121
val message = firstLine.split(": ").drop(1).firstOrNull() ?: "n/a"
119-
return LiveStackTrace(exceptionType, message, elements)
122+
return LiveStackTrace(exceptionType, message, elements, language = ArtifactLanguage.NODEJS)
120123
}
121124

122125
private fun extractPythonStackTrace(data: String): LiveStackTrace {
@@ -128,7 +131,7 @@ class LiveStackTrace(
128131
val sourceCode = el.groupValues[4]
129132
elements.add(LiveStackTraceElement(inLocation, "$file:$lineNumber", sourceCode = sourceCode))
130133
}
131-
return LiveStackTrace("n/a", "n/a", elements)
134+
return LiveStackTrace("n/a", "n/a", elements, language = ArtifactLanguage.PYTHON)
132135
}
133136

134137
private fun extractJvmStackTrace(data: String): LiveStackTrace {
@@ -141,13 +144,13 @@ class LiveStackTrace(
141144
logLines[0]
142145
}
143146
val elements = mutableListOf<LiveStackTraceElement>()
144-
for (el in frameRegex.findAll(data)) {
147+
for (el in jvmFrameRegex.findAll(data)) {
145148
val clazz = el.groupValues[1]
146149
val method = el.groupValues[2]
147150
val source = el.groupValues[3]
148151
elements.add(LiveStackTraceElement("$clazz.$method", source))
149152
}
150-
return LiveStackTrace(exceptionClass, message, elements)
153+
return LiveStackTrace(exceptionClass, message, elements, language = ArtifactLanguage.JVM)
151154
}
152155
}
153156

@@ -180,6 +183,7 @@ class LiveStackTrace(
180183
if (message != other.message) return false
181184
if (elements != other.elements) return false
182185
if (causedBy != other.causedBy) return false
186+
if (language != other.language) return false
183187
return true
184188
}
185189

@@ -188,6 +192,7 @@ class LiveStackTrace(
188192
result = 31 * result + (message?.hashCode() ?: 0)
189193
result = 31 * result + elements.hashCode()
190194
result = 31 * result + (causedBy?.hashCode() ?: 0)
195+
result = 31 * result + language.hashCode()
191196
return result
192197
}
193198
}

0 commit comments

Comments
 (0)