Skip to content

Spectrum analytics bytime queries for multiple metrics/dimensions only returns one dimension/metric #4197

@axon-droe

Description

@axon-droe

Confirm this is a Go library issue and not an underlying Cloudflare API issue

  • This is an issue with the Go library

Describe the bug

As best as I read the API docs dimensions and metrics should be provided as a comma delimited array and when I query this way via curl I get the values I expect
https://developers.cloudflare.com/api/resources/spectrum/subresources/analytics/subresources/events/

curl -H "Authorization: Bearer *******" "https://api.cloudflare.com/client/v4/zones/*******/spectrum/analytics/events/bytime?metrics=count,bytesIngress,bytesEgress&dimensions=appID,event,coloName,ipVersion&since=$(date -u -v-5M +%Y-%m-%dT%H:%M:%SZ)&timeDelta=minute" | jq .

However after doing some debugging trying to figure out why I was only getting one dimension and metric back I finally figured out that this was the call the SDK was making. Each of the dimensions and metrics are being set as their own query param instead of a single comma delimited one

2025/09/24 17:19:25 http2: Transport encoding header ":authority" = "api.cloudflare.com"
2025/09/24 17:19:25 http2: Transport encoding header ":method" = "GET"
2025/09/24 17:19:25 http2: Transport encoding header ":path" = "/client/v4/zones/*******/spectrum/analytics/events/bytime?dimensions=appID&dimensions=event&dimensions=coloName&dimensions=ipVersion&metrics=count&metrics=bytesIngress&metrics=bytesEgress&since=2025-09-25T00%3A14%3A25Z&time_delta=minute"
2025/09/24 17:19:25 http2: Transport encoding header ":scheme" = "https"

Here's how I'm setting up the params

	params := spectrum.AnalyticsEventBytimeGetParams{
		ZoneID:    cloudflare.F(zoneID),
		Since:     cloudflare.F(since),
		TimeDelta: cloudflare.F(spectrum.AnalyticsEventBytimeGetParamsTimeDeltaMinute),
		Metrics: cloudflare.F([]spectrum.AnalyticsEventBytimeGetParamsMetric{
			spectrum.AnalyticsEventBytimeGetParamsMetricCount,
			spectrum.AnalyticsEventBytimeGetParamsMetricBytesIngress,
			spectrum.AnalyticsEventBytimeGetParamsMetricBytesEgress,
		}),
		Dimensions: cloudflare.F([]spectrum.Dimension{
			spectrum.DimensionAppID,
			spectrum.DimensionEvent,
			spectrum.DimensionColoName,
			spectrum.DimensionIPVersion,
		}),
	}

Using the tests as an example it looks like I'm setting the dimensions correctly
https://github.com/cloudflare/cloudflare-go/blob/v6.0.1/spectrum/analyticseventbytime_test.go#L34

this nasty hack returns the values I expect

	params := spectrum.AnalyticsEventBytimeGetParams{
		ZoneID:    cloudflare.F(zoneID),
		Since:     cloudflare.F(since),
		TimeDelta: cloudflare.F(spectrum.AnalyticsEventBytimeGetParamsTimeDeltaMinute),
		Metrics: cloudflare.F([]spectrum.AnalyticsEventBytimeGetParamsMetric{
			// Work around bug that puts these as individual params instead of a single param with comma separated values
			spectrum.AnalyticsEventBytimeGetParamsMetric(strings.Join([]string{string(spectrum.AnalyticsEventBytimeGetParamsMetricCount), string(spectrum.AnalyticsEventBytimeGetParamsMetricBytesIngress), string(spectrum.AnalyticsEventBytimeGetParamsMetricBytesEgress)}, ",")),
		}),
		Dimensions: cloudflare.F([]spectrum.Dimension{
			// Work around bug that puts these as individual params instead of a single param with comma separated values
			spectrum.Dimension(strings.Join([]string{string(spectrum.DimensionAppID), string(spectrum.DimensionEvent), string(spectrum.DimensionColoName), string(spectrum.DimensionIPVersion)}, ",")),
		}),
	}

To Reproduce

Make a spectrum analytics bytime call attempting to use multiple metrics and/or dimensions.

Observe that values for only one dimension and metric are returned

Code snippets

OS

macOS

Go version

Go 1.25.1

Library version

github.com/cloudflare/cloudflare-go/v6 v6.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions