open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.03k stars 2.35k forks source link

Issue in webhookevent receiver #35028

Open francisan opened 1 month ago

francisan commented 1 month ago

I am facing one issue in below webhookevent receiver.

receivers: webhookevent:

  endpoint: 0.0.0.0:1111
  path: /get/info

processors: transform/tr:

   error_mode: ignore
   log_statements:
    - context: log
      statements:
       - set(body, ParseJSON(body)) where body != nil
       - set(resource.attributes["name"], body["name"])

exporters: logging: loglevel: debug

service: pipelines:

logs/receivers: receivers: [webhookevent] processors: [transform/tr] exporters: [logging]

If I put any new line in between Json, then rather than considering it as a single log statement, it will consider it as two different log statements.

For example,

If we use below Json, then it will consider it as a single log. We are good here. {"name" : "francis" ,"city" : "newyork"}

But if we use below Json, then it will consider it as 4 different logs. I think, ideally it should consider it as a single log statement.

{ "name": "francis", "city": "newyork" }

{ --->log1 "name": "francis", --->log2 "city": "newyork" --->log3 } --->log4

Why is it behaving in this way?

codeboten commented 1 month ago

transferring to contrib repo

github-actions[bot] commented 1 month ago

Pinging code owners for receiver/webhookevent: @atoulme @shalper2. See Adding Labels via Comments if you do not have permissions to add labels yourself.

francisan commented 1 month ago

@atoulme @shalper2 Could you please help me to resolve this.

shalper2 commented 1 month ago

@francisan taking a look now!

shalper2 commented 1 month ago

The behavior comes from the way that go's bufio.Scanner implements its default Scan() behavior. By default Scan() advances the buffer to the next token using a SplitFunc which stops at newline and return characters. This causes the for sc.Scan() loop in webhookevent receiver's req_to_log.go to create a new log entry for each newline encountered (which is what you're seeing). I do not think this behavior is desirable for the webhookevent receiver and so I will try to push a fix.

crobert-1 commented 1 month ago

Removing needs triage based on code owner response.

francisan commented 1 month ago

Thanks @crobert-1 One Observation---- It happens when I use postman for triggering API. If we call webhookevent API from a java program using rest template, then it's not happening.