<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get the context of an error in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547080#M155093</link>
    <description>&lt;P&gt;Interesting.&amp;nbsp; I was very skeptical about that query, but it kinda worked.&amp;nbsp; It took more than 3 minutes for 1 day of logs though.&lt;/P&gt;&lt;P&gt;It returned&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2021-03-21 11:36:43,045 [thread-1] blablabla orderid 12345
2021-03-21 11:36:43,046 [thread-1] blablabla
...
2021-03-21 11:36:43,047 [thread-1] WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Error: 1366, SQLState: HY000
2021-03-21 11:36:43,048 [thread-1] ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Incorrect string value: '\xE2\x80\xAFfro...' for column 'request' at row 1
2021-03-21 11:36:43,050 [thread-1] ERROR [class-1] - org.hibernate.exception.GenericJDBCException: could not execute statement
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
&amp;lt;multi-line stack trace&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The threadname is recycled in the web server. So, just grouping by the threadname is going to be a very expensive search. My idea here was to try to limit the search to around the error only. But maybe I'm trying too hard.&lt;/P&gt;&lt;P&gt;Any suggestion to speed it up?&lt;/P&gt;&lt;P&gt;Also, I don't need all the details by threadname. Is there a way to summarize the data into a tabular format with the few data points I need? For instance, orderid, the "Incorrect string value" line, the classname after the&amp;nbsp;"Incorrect string value" line?&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20%" height="25px"&gt;datetime&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;threadname&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;orderid&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;column name&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;classname&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="47px"&gt;2021-03-21 11:36:43,047&lt;/TD&gt;&lt;TD height="47px"&gt;thread-1&lt;/TD&gt;&lt;TD height="47px"&gt;12345&lt;/TD&gt;&lt;TD height="47px"&gt;request&lt;/TD&gt;&lt;TD height="47px"&gt;class-1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Wed, 07 Apr 2021 18:09:44 GMT</pubDate>
    <dc:creator>pfs</dc:creator>
    <dc:date>2021-04-07T18:09:44Z</dc:date>
    <item>
      <title>Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547063#M155084</link>
      <description>&lt;P&gt;Hi Splunk Community!&lt;/P&gt;&lt;P&gt;I'm trying to get the context of an error.&lt;/P&gt;&lt;P&gt;Here is a snippet of the logs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2021-03-21 11:36:43,045 [thread-1] blablabla orderid 12345
2021-03-21 11:36:43,045 [thread-2] blablabla orderid 23456
2021-03-21 11:36:43,045 [thread-3] blablabla orderid 34567
2021-03-21 11:36:43,046 [thread-1] blablabla
...
2021-03-21 11:36:43,047 [thread-1] WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Error: 1366, SQLState: HY000
2021-03-21 11:36:43,048 [thread-1] ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Incorrect string value: '\xE2\x80\xAFfro...' for column 'request' at row 1
2021-03-21 11:36:43,050 [thread-1] ERROR [class-1] - org.hibernate.exception.GenericJDBCException: could not execute statement
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
&amp;lt;multi-line stack trace&amp;gt;
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "context" I'm trying to get is:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; For orderid 12345, error "SQL Error: 1366, SQLState: HY000" while trying to write '\xE2\x80\xAFfro...' for column 'request' in "class-1".&lt;/P&gt;&lt;P&gt;As you can see, the order and the error messages are all on different lines.&amp;nbsp; I know, it's not ideal, but that's what I have to deal with right now.&lt;/P&gt;&lt;P&gt;Is there a way to get this summary?&lt;/P&gt;&lt;P&gt;My idea is:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;find the error&lt;/LI&gt;&lt;LI&gt;get the thread name&lt;/LI&gt;&lt;LI&gt;find logs with the same thread name in the past few seconds to get the orderid&lt;/LI&gt;&lt;LI&gt;find logs with the same thread name in the next few seconds to get the character(s), the column name and the class name&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Something to keep in mind on our setup:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;the "_time" is the indexed time, not the real log time.&amp;nbsp; Because of that, sometimes there are logs from the previous day having the same "_time" as logs from the current day. So, I've used extracted fields to get the date/time from the log entry.&lt;/LI&gt;&lt;LI&gt;I have been able to extract fields for the date/time (rm_datetime), the thread name (rm_threadname), the log message (rm_logmessage)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I've tried using:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;transaction to get the next line grouped by the rm_threadname, but transaction can only go in 1 direction, i.e. either up or down. In this case, I'm looking for "SQL Error: 1366". So, I have to walk up and down to get the full context.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main | transaction rm_threadname startswith="[org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Incorrect string value:" maxevents=5 | rex field=_raw "(?&amp;lt;FirstFewLines&amp;gt;(.*[\n]){2})" | table FirstFewLines​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;map based on the rm_threadname of the previous search, but I'm failing to get log entries around the rm_datetime of the error (a few seconds before and a few seconds after)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main "SQL Error: 1366"
| eval errordateserial=strptime(rm_datetime, "%Y-%m-%d %H:%M:%S,%Q"), fromdateserial=strptime(rm_datetime, "%Y-%m-%d %H:%M:%S,%Q") - 2, todateserial=strptime(rm_datetime, "%Y-%m-%d %H:%M:%S,%Q") + 1
| table rm_datetime, rm_threadname, rm_logmessage, errordateserial, fromdateserial, todateserial
| map [ search index=main rm_threadname=$rm_threadname$
  | eval datetime=strptime(rm_datetime, "%Y-%m-%d %H:%M:%S,%Q")
  | eval datetime &amp;gt;= $fromdateserial$ | eval datetime &amp;lt;= $todateserial$
  | eval errordateserial=$errordateserial$, fromdateserial=$fromdateserial$, todateserial=$todateserial$
]​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;subsearches using the rm_threadname, but I'm failing to get log entries around the rm_datetime of the error (a few seconds before and a few seconds after)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main [ search index=main "SQL Error: 1366" | fields rm_datetime, rm_threadname | format ] ​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 16:44:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547063#M155084</guid>
      <dc:creator>pfs</dc:creator>
      <dc:date>2021-04-07T16:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547071#M155088</link>
      <description>&lt;P&gt;Have you tried&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction rm_threadname startswith="blablabla orderid" endswith="Incorrect string value"&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 16:37:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547071#M155088</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-07T16:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547073#M155090</link>
      <description>&lt;P&gt;Thanks for replying&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;As I mentioned, &lt;STRONG&gt;transaction&lt;/STRONG&gt; can only go in 1 direction (as far as I know).&lt;/P&gt;&lt;P&gt;In this case, it will return me the orderid (which, by the way, can have many variations, like order id, order.id, order number, etc) with a block of logs, up to the "Incorrect string value", but it will not return me the class name "class-1" in the next line after the&amp;nbsp;"Incorrect string value".&lt;/P&gt;&lt;P&gt;Am I asking for too much?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 16:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547073#M155090</guid>
      <dc:creator>pfs</dc:creator>
      <dc:date>2021-04-07T16:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547076#M155092</link>
      <description>&lt;P&gt;Yes, so make sure the events are ordered correctly, then use transaction to pick up the start i.e. when the order id is logged, and all events for the thread id until it get restarted, then search for the error&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction rm_threadname startswith="blablabla"
| search "SQL Error: 1366"&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 17:09:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547076#M155092</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-07T17:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547080#M155093</link>
      <description>&lt;P&gt;Interesting.&amp;nbsp; I was very skeptical about that query, but it kinda worked.&amp;nbsp; It took more than 3 minutes for 1 day of logs though.&lt;/P&gt;&lt;P&gt;It returned&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2021-03-21 11:36:43,045 [thread-1] blablabla orderid 12345
2021-03-21 11:36:43,046 [thread-1] blablabla
...
2021-03-21 11:36:43,047 [thread-1] WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Error: 1366, SQLState: HY000
2021-03-21 11:36:43,048 [thread-1] ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Incorrect string value: '\xE2\x80\xAFfro...' for column 'request' at row 1
2021-03-21 11:36:43,050 [thread-1] ERROR [class-1] - org.hibernate.exception.GenericJDBCException: could not execute statement
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
&amp;lt;multi-line stack trace&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The threadname is recycled in the web server. So, just grouping by the threadname is going to be a very expensive search. My idea here was to try to limit the search to around the error only. But maybe I'm trying too hard.&lt;/P&gt;&lt;P&gt;Any suggestion to speed it up?&lt;/P&gt;&lt;P&gt;Also, I don't need all the details by threadname. Is there a way to summarize the data into a tabular format with the few data points I need? For instance, orderid, the "Incorrect string value" line, the classname after the&amp;nbsp;"Incorrect string value" line?&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20%" height="25px"&gt;datetime&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;threadname&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;orderid&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;column name&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;classname&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="47px"&gt;2021-03-21 11:36:43,047&lt;/TD&gt;&lt;TD height="47px"&gt;thread-1&lt;/TD&gt;&lt;TD height="47px"&gt;12345&lt;/TD&gt;&lt;TD height="47px"&gt;request&lt;/TD&gt;&lt;TD height="47px"&gt;class-1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 18:09:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547080#M155093</guid>
      <dc:creator>pfs</dc:creator>
      <dc:date>2021-04-07T18:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547083#M155096</link>
      <description>&lt;P&gt;If it were me, I would try to extract the information you need using rex. The transaction command will have gathered all the _raw fields together (unless you have specifically chosen to create multi-value fields) so you might even be able to do it in one long rex expression, but it doesn't matter if you use more than one.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 18:26:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547083#M155096</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-07T18:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547141#M155119</link>
      <description>&lt;P&gt;Thanks for your input&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;I used rex to find the few fields I wanted.&amp;nbsp; It's a bit clumsy, but it works.&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;transaction&lt;/STRONG&gt; command is somewhat slow.&amp;nbsp; Any suggestions on how to speed it up?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 02:57:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547141#M155119</guid>
      <dc:creator>pfs</dc:creator>
      <dc:date>2021-04-08T02:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547154#M155125</link>
      <description>&lt;P&gt;You could set up some scheduled searches (say once an hour) to populate a summary index with the results you are after, then use that index.&lt;/P&gt;&lt;P&gt;There might be something you could do with streamstats to copy the latest fields e.g. order id down to other events with the same thread id, but there is no guarantee that this would be any quicker if you have a large amount of data in the first place.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 06:43:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547154#M155125</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-08T06:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Get the context of an error</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547941#M155380</link>
      <description>&lt;P&gt;Thx&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;I have tried some subsearches but it was getting too complex and was even slower than the &lt;STRONG&gt;transaction&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;The grouping with &lt;STRONG&gt;transaction&lt;/STRONG&gt; with a limited duration (maxspan) and limited number of events is the best compromise.&amp;nbsp; It currently does take ~10min per search per day.&lt;/P&gt;&lt;P&gt;My final query is something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main
| transaction rm_threadname maxevents=40 maxspan=2s
| search "SQL Error: 1366" "Incorrect string value" "exception" ("currentOrderNumber" OR "orderid" OR "ordernumber")
| ...do some field extraction
| table ...all the relevant fields...&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 19:17:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-the-context-of-an-error/m-p/547941#M155380</guid>
      <dc:creator>pfs</dc:creator>
      <dc:date>2021-04-14T19:17:20Z</dc:date>
    </item>
  </channel>
</rss>

