Skip to content

fix(cloudflarereceiver): preserve array-typed log fields as slice attrs#47842

Open
SAY-5 wants to merge 1 commit intoopen-telemetry:mainfrom
SAY-5:fix/cloudflarereceiver-array-attrs-46716
Open

fix(cloudflarereceiver): preserve array-typed log fields as slice attrs#47842
SAY-5 wants to merge 1 commit intoopen-telemetry:mainfrom
SAY-5:fix/cloudflarereceiver-array-attrs-46716

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 22, 2026

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`).

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.
@SAY-5 SAY-5 requested review from a team and dehaansa as code owners April 22, 2026 01:21
@github-actions github-actions Bot added the first-time contributor PRs made by new contributors label Apr 22, 2026
@github-actions
Copy link
Copy Markdown
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[receiver/cloudflare] array-typed fields (e.g. BotDetectionIDs, SecurityActions) are dropped

2 participants