Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in webhookevent receiver #35028

Open
francisan opened this issue Sep 5, 2024 · 8 comments
Open

Issue in webhookevent receiver #35028

francisan opened this issue Sep 5, 2024 · 8 comments
Labels

Comments

@francisan
Copy link

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
Copy link
Contributor

transferring to contrib repo

@codeboten codeboten transferred this issue from open-telemetry/opentelemetry-collector Sep 5, 2024
Copy link
Contributor

github-actions bot commented Sep 5, 2024

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

@codeboten codeboten added the needs triage New item requiring triage label Sep 5, 2024
@francisan
Copy link
Author

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

@shalper2
Copy link
Contributor

shalper2 commented Sep 6, 2024

@francisan taking a look now!

@shalper2
Copy link
Contributor

shalper2 commented Sep 6, 2024

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
Copy link
Member

Removing needs triage based on code owner response.

@crobert-1 crobert-1 added bug Something isn't working and removed needs triage New item requiring triage labels Sep 6, 2024
@francisan
Copy link
Author

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.

codeboten pushed a commit that referenced this issue Oct 2, 2024
**Description:** Fixed a bug where request bodies containing newlines
caused logs to split into separate entries.

**Link to tracking Issue:**
[35028](#35028)

**Testing:** Added a new unit test to `req_to_log_test.go` for the case
where request body data contains newline characters

**Documentation:** Some comments in `req_to_log.go` for clarity were
added.
jriguera pushed a commit to springernature/opentelemetry-collector-contrib that referenced this issue Oct 4, 2024
**Description:** Fixed a bug where request bodies containing newlines
caused logs to split into separate entries.

**Link to tracking Issue:**
[35028](open-telemetry#35028)

**Testing:** Added a new unit test to `req_to_log_test.go` for the case
where request body data contains newline characters

**Documentation:** Some comments in `req_to_log.go` for clarity were
added.
Copy link
Contributor

github-actions bot commented Nov 6, 2024

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants