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

[processor/probabilisticsampler] panics when non-Bytes log attribute chosen #18222

Closed
e-dard opened this issue Feb 1, 2023 · 5 comments · Fixed by #26564
Closed

[processor/probabilisticsampler] panics when non-Bytes log attribute chosen #18222

e-dard opened this issue Feb 1, 2023 · 5 comments · Fixed by #26564
Assignees
Labels
bug Something isn't working processor/probabilisticsampler Probabilistic Sampler processor

Comments

@e-dard
Copy link

e-dard commented Feb 1, 2023

Component(s)

processor/probabilisticsampler

What happened?

Description

It is possible to configure the processor to sample based upon an arbitrary attribute of each log record. Currently, if you provide an attribute that is not a Bytes typed attribute, then the collector will panic with something similar to the following:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x102c9c0e8]

goroutine 14 [running]:
testing.tRunner.func1.2({0x102e93760, 0x1034ec850})
    /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1396 +0x1c8
testing.tRunner.func1()
    /opt/homebrew/Cellar/go/1.19.5/libexec/src/testing/testing.go:1399 +0x378
panic({0x102e93760, 0x1034ec850})
    /opt/homebrew/Cellar/go/1.19.5/libexec/src/runtime/panic.go:884 +0x204
go.opentelemetry.io/collector/pdata/pcommon.ByteSlice.AsRaw(...)

<snip>

Effectively, when Bytes() is called on any attribute value that is not of type AnyValue_BytesValue here:

if lidBytes == nil && lsp.samplingSource != "" {
if value, ok := l.Attributes().Get(lsp.samplingSource); ok {
tagPolicyValue = lsp.samplingSource
lidBytes = value.Bytes().AsRaw()
}
}

The returned BytesSlice will be zero-initialised, resulting in the AsRaw() call panicking.

Steps to Reproduce

Configure the processor to sample based on an attribute of each log record, where the attribute is not of type Bytes e.g.,

processors:
  probabilistic_sampler:
    sampling_percentage: 15
    attribute_source: record
    from_attribute: <an_attribute_thats_not_bytes>

Expected Result

Either the attribute value is used for a sampling decision, or the log record is skipped and not sampled.

Actual Result

The collector panics.

Collector version

latest

Environment information

Environment

All

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

@e-dard e-dard added bug Something isn't working needs triage New item requiring triage labels Feb 1, 2023
@github-actions github-actions bot added the processor/probabilisticsampler Probabilistic Sampler processor label Feb 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

Pinging code owners:

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

@github-actions
Copy link
Contributor

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

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.

@liwanxue
Copy link

liwanxue commented Sep 11, 2023

facing same issue. any solutions?

@jpkrohling jpkrohling assigned jpkrohling and unassigned e-dard Sep 11, 2023
jpkrohling referenced this issue in jpkrohling/opentelemetry-collector-contrib Sep 11, 2023
When doing a probabilistic sampling for logs, the probabilistic sampler currently requires the source attribute to be of bytes value. This PR changes that to allow any value type to be used.

Fixes #18222

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
@jpkrohling
Copy link
Member

I submitted a PR to get this fixed.

codeboten pushed a commit that referenced this issue Oct 4, 2023
When doing a probabilistic sampling for logs, the probabilistic sampler
currently requires the source attribute to be of bytes value. This PR
changes that to allow any value type to be used.

Fixes #18222

Signed-off-by: Juraci Paixão Kröhling <[email protected]>

---------

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
jmsnll pushed a commit to jmsnll/opentelemetry-collector-contrib that referenced this issue Nov 12, 2023
…emetry#26564)

When doing a probabilistic sampling for logs, the probabilistic sampler
currently requires the source attribute to be of bytes value. This PR
changes that to allow any value type to be used.

Fixes open-telemetry#18222

Signed-off-by: Juraci Paixão Kröhling <[email protected]>

---------

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working processor/probabilisticsampler Probabilistic Sampler processor
Projects
None yet
4 participants