@@ -73,17 +73,17 @@ void setUp() throws IOException {
7373 void fillStackTrace () {
7474 assertThat (stacktrace ).isNotEmpty ();
7575 // even though the stacktrace is captured within our tracer class, the first method should be getStackTrace
76- assertThat (stacktrace .get (0 ).get ("abs_path " ).textValue ()).doesNotStartWith ("co.elastic" );
76+ assertThat (stacktrace .get (0 ).get ("module " ).textValue ()).doesNotStartWith ("co.elastic" );
7777 assertThat (stacktrace .get (0 ).get ("function" ).textValue ()).isEqualTo ("getStackTrace" );
78- assertThat (stacktrace .stream ().filter (st -> st .get ("abs_path " ).textValue ().endsWith ("StacktraceSerializationTest" ))).isNotEmpty ();
78+ assertThat (stacktrace .stream ().filter (st -> st .get ("filename " ).textValue ().equals ("StacktraceSerializationTest.java " ))).isNotEmpty ();
7979 }
8080
8181 @ Test
8282 void testAppFrame () throws Exception {
8383 when (stacktraceConfiguration .getApplicationPackages ()).thenReturn (Collections .singletonList ("org.example.stacktrace" ));
8484 stacktrace = getStackTrace ();
8585 Optional <JsonNode > thisMethodsFrame = stacktrace .stream ()
86- .filter (st -> st .get ("abs_path " ).textValue ().startsWith (getClass ().getName ()))
86+ .filter (st -> st .get ("module " ).textValue ().equals (getClass ().getPackageName ()))
8787 .findAny ();
8888 assertThat (thisMethodsFrame ).isPresent ();
8989 assertThat (thisMethodsFrame .get ().get ("library_frame" ).booleanValue ()).isFalse ();
@@ -92,7 +92,7 @@ void testAppFrame() throws Exception {
9292 @ Test
9393 void testNoAppFrame () {
9494 Optional <JsonNode > thisMethodsFrame = stacktrace .stream ()
95- .filter (st -> st .get ("abs_path " ).textValue ().startsWith (getClass ().getName ()))
95+ .filter (st -> st .get ("module " ).textValue ().startsWith (getClass ().getPackageName ()))
9696 .findAny ();
9797 assertThat (thisMethodsFrame ).isPresent ();
9898 assertThat (thisMethodsFrame .get ().get ("library_frame" ).booleanValue ()).isTrue ();
@@ -106,11 +106,46 @@ void testFileNamePresent() {
106106 @ Test
107107 void testNoInternalStackFrames () {
108108 assertSoftly (softly -> {
109- softly .assertThat (stacktrace .stream ().filter (st -> st .get ("abs_path " ).textValue ().contains ("java.lang.reflect ." ))).isEmpty ();
110- softly .assertThat (stacktrace .stream ().filter (st -> st .get ("abs_path " ).textValue ().contains ("sun." ))).isEmpty ();
109+ softly .assertThat (stacktrace .stream ().filter (st -> st .get ("module " ).textValue ().startsWith ("java.lang." ))).isEmpty ();
110+ softly .assertThat (stacktrace .stream ().filter (st -> st .get ("module " ).textValue ().startsWith ("sun." ))).isEmpty ();
111111 });
112112 }
113113
114+ @ Test
115+ void testStackTraceElementSerialization () throws IOException {
116+ when (stacktraceConfiguration .getApplicationPackages ()).thenReturn (Collections .singletonList ("co.elastic.apm" ));
117+
118+ StackTraceElement stackTraceElement = new StackTraceElement ("co.elastic.apm.test.TestClass" ,
119+ "testMethod" , "TestClass.java" , 34 );
120+ String json = serializer .toJsonString (stackTraceElement );
121+ JsonNode stackTraceElementParsed = objectMapper .readTree (json );
122+ assertThat (stackTraceElementParsed .get ("filename" ).textValue ()).isEqualTo ("TestClass.java" );
123+ assertThat (stackTraceElementParsed .get ("function" ).textValue ()).isEqualTo ("testMethod" );
124+ assertThat (stackTraceElementParsed .get ("library_frame" ).booleanValue ()).isFalse ();
125+ assertThat (stackTraceElementParsed .get ("lineno" ).intValue ()).isEqualTo (34 );
126+ assertThat (stackTraceElementParsed .get ("module" ).textValue ()).isEqualTo ("co.elastic.apm.test" );
127+
128+ stackTraceElement = new StackTraceElement ("co.elastic.TestClass" ,
129+ "testMethod" , "TestClass.java" , 34 );
130+ json = serializer .toJsonString (stackTraceElement );
131+ stackTraceElementParsed = objectMapper .readTree (json );
132+ assertThat (stackTraceElementParsed .get ("library_frame" ).booleanValue ()).isTrue ();
133+ assertThat (stackTraceElementParsed .get ("module" ).textValue ()).isEqualTo ("co.elastic" );
134+
135+ stackTraceElement = new StackTraceElement (".TestClass" ,
136+ "testMethod" , "TestClass.java" , 34 );
137+ json = serializer .toJsonString (stackTraceElement );
138+ stackTraceElementParsed = objectMapper .readTree (json );
139+ assertThat (stackTraceElementParsed .get ("module" ).textValue ()).isEqualTo ("" );
140+
141+ stackTraceElement = new StackTraceElement ("TestClass" ,
142+ "testMethod" , "TestClass.java" , 34 );
143+ json = serializer .toJsonString (stackTraceElement );
144+ stackTraceElementParsed = objectMapper .readTree (json );
145+ assertThat (stackTraceElementParsed .get ("module" ).textValue ()).isEqualTo ("" );
146+ }
147+
148+
114149 private List <JsonNode > getStackTrace () throws IOException {
115150 final Transaction transaction = tracer .startTransaction (TraceContext .asRoot (), null , getClass ().getClassLoader ());
116151 final Span span = transaction .createSpan ();
0 commit comments