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

filelogreceiver panics when trace_flags is an empty string #20924

Closed
bgranetzke opened this issue Apr 17, 2023 · 5 comments
Closed

filelogreceiver panics when trace_flags is an empty string #20924

bgranetzke opened this issue Apr 17, 2023 · 5 comments
Labels
bug Something isn't working pkg/stanza

Comments

@bgranetzke
Copy link
Contributor

bgranetzke commented Apr 17, 2023

Component(s)

pkg/stanza

What happened?

Description

collector panics when trace parse operator encounters empty string for trace_flags

Steps to Reproduce

My use case is a regex operator which accounts for the log line optionally containing the trace/trace flags at the end.

      - type: regex_parser
        regex: '(?P<traceid>[0-9a-f]+)?[_]?(?P<traceflags>[0-9a-f]+)?$'
        trace:
          trace_id:
            parse_from: attributes.traceid
          trace_flags:
            parse_from: attributes.traceflags

Expected Result

parser gracefully does not try to add trace flags

Actual Result

Panic:
panic: runtime error: index out of range [0] with length 0 goroutine 177 [running]: github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.convertInto(0xc047473140, {0x90?}) github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.70.0/adapter/converter.go:338 +0x2b5 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.convert(0xc000baef90?) github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.70.0/adapter/converter.go:284 +0x37 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.(*Converter).workerLoop(0xc000617680) github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.70.0/adapter/converter.go:167 +0x27b created by github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.(*Converter).Start github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.70.0/adapter/converter.go:118 +0xf5

panic line in current main:
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/adapter/converter.go#L271

The root cause might be further upstream (passing an empty []byte instead of a nil), but I think some simple defensive programming here makes sense (add a len() check in addition to the nil check)

Collector version

0.70.0

Environment information

No response

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

@bgranetzke bgranetzke added bug Something isn't working needs triage New item requiring triage labels Apr 17, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

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

@atoulme atoulme removed the needs triage New item requiring triage label Apr 17, 2023
@atoulme
Copy link
Contributor

atoulme commented Apr 17, 2023

Thanks for the report @bgranetzke, would you be interested in contributing a test case reproducing the problem?

@bgranetzke
Copy link
Contributor Author

@atoulme Not sure if this is what you meant, but I cut a PR with a unit test which exercised the specific condition and then I fixed the cause.

@bgranetzke
Copy link
Contributor Author

FYI: I was also able to reproduce the problem when I upgraded the collector version to 0.75.0

panic: runtime error: index out of range [0] with length 0
goroutine 121 [running]:
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.convertInto(0xc000000a80, {0xc000418d50?})
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.75.0/adapter/converter.go:271 +0x2b5
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.(*Converter).workerLoop(0xc000644a50)
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.75.0/adapter/converter.go:174 +0x6ac
created by github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter.(*Converter).Start
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.75.0/adapter/converter.go:104 +0x112

@crobert-1
Copy link
Member

@bgranetzke Thanks for fixing this! Feel free to close this issue if it's in fact resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg/stanza
Projects
None yet
Development

No branches or pull requests

3 participants