sematext / logagent-js

Extensible log shipper with input/output plugins, buffering, parsing, data masking, and small memory/CPU footprint
https://sematext.com/logagent
Apache License 2.0
389 stars 79 forks source link

Java Exception not parsed well #236

Open mooselau opened 4 years ago

mooselau commented 4 years ago

Hi,

I used "logagent" docker to ship my Java Project logs to sematext cloud, but it seems Java Exceptions(especially in multilines) could not be parsed well. I have tried to add some patterns myself but Exception logs still get multiple records in sematext cloud.

Below is my sample Exception trace:

2020-05-20 16:23:23.088 [scheduling-1] ERROR n.a.processor.agent.AQIUpdateAgent.doUpdating - Failed to update AQI
net.aqimp.exception.InternalException: Failed to send request
        at net.aqimp.processor.agent.AQIFetchAgent.fetchAQI(AQIFetchAgent.java:81)
        at net.aqimp.processor.agent.AQIUpdateAgent.doUpdating(AQIUpdateAgent.java:51)
        at net.aqimp.controller.ServiceScheduler.regularlyUpdateAQI(ServiceScheduler.java:24)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: net.aqimp.exception.CommunicationException: Failed to send request to URL
        at net.aqimp.processor.communication.AQIHttpRequestHandler.proceedRequest(AQIHttpRequestHandler.java:87)
        at net.aqimp.processor.agent.AQIFetchAgent.fetchAQI(AQIFetchAgent.java:72)
        ... 15 common frames omitted
Caused by: java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
        at java.net.SocketInputStream.read(SocketInputStream.java:171)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)
        at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
        at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:593)
        at sun.security.ssl.InputRecord.read(InputRecord.java:532)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:990)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1388)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1416)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1400)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352)
        at net.aqimp.processor.communication.AQIHttpRequestHandler.proceedRequest(AQIHttpRequestHandler.java:69)
        ... 16 common frames omitted

And one normal log sample:

2020-05-20 16:23:23.088 [scheduling-1] INFO  n.a.p.c.AQIHttpRequestHandler.proceedRequest - AQI server is querying

And my adding patterns in patterns.yml:

patterns:                                                                       
 - sourceName: !!js/regexp server.log
   match:                            
     - type: log_common              
       regex: !!js/regexp ^(([\d|\-|\:|.|\s]+)\s(\[.+\])\s([A-Z]+)\s(.+)-(.+))
       fields: [raw, ts, thread, severity, logger, message]                   
       dateFormat: yyyy-MM-dd HH:mm:ss.SSS                                    

 - sourceName: !!js/regexp server.log                                           
   blockStart: !!js/regexp ^(\S.+Exception:.+)         
   match:                                     
     - type: log_trace                        
       regex: !!js/regexp ^(\S.+Exception:.+\n\s+.*)
       fields: [stacktrace]

The trace look in sematext logs panel, and I wish to see one record in sematext logs but with the whole exception stack: image

otisg commented 4 years ago

For your Java stack traces -- I assume that is not the complete stack trace. For example, I don't see the timestamp.

mooselau commented 4 years ago

Hi @otisg , updated the stack traces, there is one ERROR log above the stack traces.