@@ -172,6 +172,80 @@ public void testException() {
172172 .doesNotContainKey ("sampled" ));
173173 }
174174
175+ @ Test
176+ public void testLogFormatingData () {
177+ final String message = "Replacement string" ;
178+ final String expected = "infof " + message ;
179+ assertEquals ("hello " + message , jBossLoggingBean .helloLogFormating (message ));
180+
181+ List <LogRecordData > finishedLogRecordItems = logRecordExporter .getFinishedLogRecordItemsAtLeast (1 );
182+ LogRecordData last = finishedLogRecordItems .get (finishedLogRecordItems .size () - 1 );
183+
184+ assertThat (last .getSpanContext ().getSpanId ()).isEqualTo ("0000000000000000" );
185+ assertThat (last .getSpanContext ().getTraceId ()).isEqualTo ("00000000000000000000000000000000" );
186+ assertThat (last .getSpanContext ().getTraceFlags ().asHex ()).isEqualTo ("00" );
187+ assertThat (last .getTimestampEpochNanos ()).isNotNull ().isLessThan (System .currentTimeMillis () * 1_000_000 );
188+
189+ assertThat (last )
190+ .hasSeverity (Severity .INFO )
191+ .hasSeverityText ("INFO" )
192+ .hasBody (expected )
193+ .hasAttributesSatisfying (
194+ attributes -> assertThat (attributes )
195+ .containsEntry (CODE_NAMESPACE .getKey (),
196+ "io.quarkus.opentelemetry.deployment.logs.OtelLoggingTest$JBossLoggingBean" )
197+ .containsEntry (CODE_FUNCTION .getKey (), "helloLogFormating" )
198+ .containsEntry (THREAD_NAME .getKey (), Thread .currentThread ().getName ())
199+ .containsEntry (THREAD_ID .getKey (), Thread .currentThread ().getId ())
200+ .containsEntry ("log.logger.namespace" , "org.jboss.logging.Logger" )
201+ .containsKey (CODE_LINENO .getKey ())
202+ .doesNotContainKey (EXCEPTION_TYPE )
203+ .doesNotContainKey (EXCEPTION_MESSAGE )
204+ .doesNotContainKey (EXCEPTION_STACKTRACE )
205+ .doesNotContainKey (LOG_FILE_PATH )
206+ // attributed do not duplicate tracing data
207+ .doesNotContainKey ("spanId" )
208+ .doesNotContainKey ("traceId" )
209+ .doesNotContainKey ("sampled" ));
210+ }
211+
212+ @ Test
213+ public void testLogParameterValue () {
214+ final String message = "Replacement parameter value" ;
215+ final String expected = "infov " + message ;
216+ assertEquals ("hello " + message , jBossLoggingBean .helloLogParameterValue (message ));
217+
218+ List <LogRecordData > finishedLogRecordItems = logRecordExporter .getFinishedLogRecordItemsAtLeast (1 );
219+ LogRecordData last = finishedLogRecordItems .get (finishedLogRecordItems .size () - 1 );
220+
221+ assertThat (last .getSpanContext ().getSpanId ()).isEqualTo ("0000000000000000" );
222+ assertThat (last .getSpanContext ().getTraceId ()).isEqualTo ("00000000000000000000000000000000" );
223+ assertThat (last .getSpanContext ().getTraceFlags ().asHex ()).isEqualTo ("00" );
224+ assertThat (last .getTimestampEpochNanos ()).isNotNull ().isLessThan (System .currentTimeMillis () * 1_000_000 );
225+
226+ assertThat (last )
227+ .hasSeverity (Severity .INFO )
228+ .hasSeverityText ("INFO" )
229+ .hasBody (expected )
230+ .hasAttributesSatisfying (
231+ attributes -> assertThat (attributes )
232+ .containsEntry (CODE_NAMESPACE .getKey (),
233+ "io.quarkus.opentelemetry.deployment.logs.OtelLoggingTest$JBossLoggingBean" )
234+ .containsEntry (CODE_FUNCTION .getKey (), "helloLogParameterValue" )
235+ .containsEntry (THREAD_NAME .getKey (), Thread .currentThread ().getName ())
236+ .containsEntry (THREAD_ID .getKey (), Thread .currentThread ().getId ())
237+ .containsEntry ("log.logger.namespace" , "org.jboss.logging.Logger" )
238+ .containsKey (CODE_LINENO .getKey ())
239+ .doesNotContainKey (EXCEPTION_TYPE )
240+ .doesNotContainKey (EXCEPTION_MESSAGE )
241+ .doesNotContainKey (EXCEPTION_STACKTRACE )
242+ .doesNotContainKey (LOG_FILE_PATH )
243+ // attributed do not duplicate tracing data
244+ .doesNotContainKey ("spanId" )
245+ .doesNotContainKey ("traceId" )
246+ .doesNotContainKey ("sampled" ));
247+ }
248+
175249 private String extractStackTrace (final Throwable throwable ) {
176250 try (StringWriter sw = new StringWriter (1024 ); PrintWriter pw = new PrintWriter (sw )) {
177251 throwable .printStackTrace (pw );
@@ -201,5 +275,15 @@ public boolean logException(final Throwable throwable) {
201275 LOG .error ("logging an exception" , throwable );
202276 return true ;
203277 }
278+
279+ public String helloLogFormating (final String replacement ) {
280+ LOG .infof ("infof %s" , replacement );
281+ return "hello " + replacement ;
282+ }
283+
284+ public String helloLogParameterValue (final String replacement ) {
285+ LOG .infov ("infov {0}" , replacement );
286+ return "hello " + replacement ;
287+ }
204288 }
205289}
0 commit comments