SigNoz/signoz · error · basemodel.ApiError

couldn't serialize request payload to JSON: %w

Error message

couldn't serialize request payload to JSON: %w

What it means

json.Marshal of the request payload failed inside the generic gateway request helper (requestAndParseResponse). The payload contains a type that cannot be serialized to JSON, such as a channel, func, or a value with an unmarshalable field.

Source

Thrown at ee/query-service/app/api/cloudIntegrations.go:315

		"X-Consumer-Username":    "lid:00000000-0000-0000-0000-000000000000",
		"X-Consumer-Groups":      "ns:default",
	}

	return requestAndParseResponse[ResponseType](ctx, reqUrl, headers, payload)
}

func requestAndParseResponse[ResponseType any](
	ctx context.Context, url string, headers map[string]string, payload any,
) (*ResponseType, *basemodel.ApiError) {

	reqMethod := http.MethodGet
	var reqBody io.Reader
	if payload != nil {
		reqMethod = http.MethodPost

		bodyJson, err := json.Marshal(payload)
		if err != nil {
			return nil, basemodel.InternalError(fmt.Errorf(
				"couldn't serialize request payload to JSON: %w", err,
			))
		}
		reqBody = bytes.NewBuffer([]byte(bodyJson))
	}

	req, err := http.NewRequestWithContext(ctx, reqMethod, url, reqBody)
	if err != nil {
		return nil, basemodel.InternalError(fmt.Errorf(
			"couldn't prepare request: %w", err,
		))
	}

	for k, v := range headers {
		req.Header.Set(k, v)
	}

	client := &http.Client{

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Inspect the payload struct for channels, funcs, or cyclic references
  2. Fix or remove the offending field / custom MarshalJSON
  3. Unit-test marshalling the payload before passing it
Defensive patterns

Strategy: validation

Validate before calling

if _, err := json.Marshal(payload); err != nil {
    return fmt.Errorf("payload not serializable: %w", err)
}

Try / catch

Pre-marshal payloads (see validationCode) so unserializable types fail with a clear caller-side error before the HTTP path.

Prevention

When it happens

Trigger: Calling requestGateway/requestAndParseResponse with a payload struct containing unsupported types (chan, func, complex, cyclic pointer) or a MarshalJSON method that errors.

Common situations: Adding a new field of an unserializable type to a gateway request struct, or a custom MarshalJSON that returns an error.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/61fc2053ba3bc7a6. Report an issue: GitHub.