fix(cloudflarereceiver): preserve array-typed log fields as slice attrs#47842
Open
SAY-5 wants to merge 1 commit intoopen-telemetry:mainfrom
Open
fix(cloudflarereceiver): preserve array-typed log fields as slice attrs#47842SAY-5 wants to merge 1 commit intoopen-telemetry:mainfrom
SAY-5 wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
Cloudflare's http_requests dataset carries several array-typed fields
(BotDetectionIDs, SecurityActions, SecurityRuleIDs, BotDetectionTags,
BotTags, SecuritySources, ContentScanObj{Results,Sizes,Types},
FraudDetection{IDs,Tags}, ...). The receiver's type switch in
processLogs only handled scalar values and maps, so any []any -- which
is what encoding/json unmarshals a JSON array into -- fell through to
the default branch and was dropped with an "unsupported type" warning.
Handle []any explicitly via pcommon.Value.FromRaw(v) on a new empty
slice attribute; do the same in the flatten-map subcase so nested
array fields aren't lost either. Add a regression test
(TestArrayAttributes) that feeds a payload with
BotDetectionIDs/SecurityActions/SecurityRuleIDs and asserts each
survives as a pcommon.ValueTypeSlice attribute.
Fixes open-telemetry#46716.
Contributor
|
Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib. Important reminders:
A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #46716.
Component: `receiver/cloudflare`
Problem
Cloudflare's `http_requests` dataset carries several array-typed fields — `BotDetectionIDs`, `BotDetectionTags`, `BotTags`, `SecurityActions`, `SecurityRuleIDs`, `SecuritySources`, `ContentScanObj{Results,Sizes,Types}`, `FraudDetection{IDs,Tags}` — per the docs.
The type switch in `logs.go` only handled scalars and `map[string]any`. A JSON array unmarshals to `[]any`, so every such field fell through to the `default:` branch and was dropped with an "unable to translate field to attribute, unsupported type" warning. The issue reporter pointed at exactly that log line.
Fix
Add a `[]any` case to the outer type switch that writes the value via `attrs.PutEmptySlice(attrName).FromRaw(v)`, so arrays become `pcommon.ValueTypeSlice` attributes. The flatten-map subcase gets the same treatment, so arrays nested inside map-typed fields aren't lost either.
`FromRaw` returns an error on values `pcommon` can't represent; in that case we log a warning (not a panic / attribute drop) so the operator still sees the field name.
Tests
Added `TestArrayAttributes` in `logs_test.go` covering a payload with `BotDetectionIDs` (int array), `SecurityActions` and `SecurityRuleIDs` (string arrays) and asserting each round-trips as a `pcommon.ValueTypeSlice` attribute with the expected values:
```
$ go test -count=1 ./receiver/cloudflarereceiver/...
ok .../receiver/cloudflarereceiver 1.101s
ok .../receiver/cloudflarereceiver/internal/metadata 0.540s
```
Changelog entry added under `.chloggen/46716-cloudflare-array-attrs.yaml` (`bug_fix`, `cloudflarereceiver`).