#general

Issues with Adding SpanId and TraceId to Log Entries in SigNoz

TLDR Hannes was struggling with adding spanId and traceId to log entries using SigNoz. Nocnica offered support, after which Hannes managed to solve the issue by using regex_parser & key_value_parser.

Powered by Struct AI
Jul 14, 2023 (5 months ago)
Hannes
Photo of md5-5fd18cb6c0f914cf7a6415b80c54af65
Hannes
06:18 PM
I found SigNoz today and I've been trying it out 🙂 One thing that I am having some trouble with is adding the spanId and traceId to the log entries. I've got an app running on Ruby on Rails and I've instrumented it with otel and everything is hunky dory. I've also got the applicat log file being sent across to SigNoz using rsyslog. However, if I send the log entries as plain text, even if it does contain the spanid and traceid, they do not appear in the json data structure for the log entries. If I try to send the log as JSON via rsyslog, I get no entries whatsoever. I have a couple of questions:

1. Should I be using rsyslog for this, or is there a better way to send log entries from the application to SigNoz?
2. If I should, should I be using a regex parser operator in the syslog entry of the otel-collector-config?
3. Is there a better/easier way?
Nocnica
Photo of md5-7d3e7e5883af6e145e90d5d5a7a25acf
Nocnica
11:07 PM
Hi there Hannes! So great to see that you're trying out SigNoz. I'm new to the team and not certain of the best way to get some structure out of a plaintext log. It's 4am for the rest of the team right now so I'll see what they say in a few hours 🙂
Jul 15, 2023 (5 months ago)
Hannes
Photo of md5-5fd18cb6c0f914cf7a6415b80c54af65
Hannes
04:24 AM
I managed to get this done with a combination of regex_parser & key_value_parser:

   logstransform/internal:
     operators:
       - type: regex_parser
         regex: 'trace_id=(?P<trace_id>\S*)'
       - type: key_value_parser
        parse_to: attributes
       - type: regex_parser
         regex: 'span_id=(?P<span_id>\S*)'
       - type: key_value_parser
         parse_to: attributes