Before you start
You need:
- First enable API errors from Configure Error collection panel.
- A clear list of the API requests and data points that you need to investigate.
- A review of the personal-data implications of collecting headers, bodies, body elements, or query parameters.
This basic setting collects requests in the 4XX–5XX range with basic information such as:
- Status code.
- Request URL.
- Method (GET, POST, UPDATE etc..)
What a collection rule does
Create an API error collection rule when you need more information about API errors or want to collect additional requests, called Troubleshooting details in Contentsquare.
A rule can collect:
- Request headers.
- Response headers.
- Request body.
- Response body.
- Selected body elements.
- Query parameters.
Available conditions and data points depend on the selected data source.
Access rules edition
In the Errors collection configuration page, find the API errors card and click View and create rules. The API errors collection-rules page displays existing rules, including the default rules.
Default and Predefined rules
The default rule collects the request URL, HTTP status code, and method for supported network requests that return a 4xx or 5xx status code. You can’t edit or delete this rule.
Predefined rules are already included on your project and allow for the automatic collection of API errors and API error details:
- GraphQL: This rule is designed to collect basic graphQL errors which are not collected by default, since the status code is generally 200. This rule can be edited and deleted as needed.
- Headers on all endpoints: This rule is used to set up the collection of headers for all API 4XX-5XX errors. The list of headers can be edited, but the rule cannot be deleted.
Define API error collection rules
Create/edit a rule
You can define up to 30 rules.
Use the search field to find a rule or click the view button to inspect an existing rule or click New rule to add a new rule.
- Enter a rule name (mandatoy)
- Enter the request URL condition (mandatory)
- Select the status code condition (mandatory)
- (optional) Enter the Response Body Content to collect
- (optional) Add up to 20 header entries per rule. For each entry, choose whether to collect the request or response header.
- (optional) Identify Response body elements for analysis of the response body (with Json path) you want to collect. 10 max.
- (optional) Identify Body elements for troubleshooting. 20 max.
- (optional) Set the encryption for the selected data where the option is available.
- Save the rule.
Use a specific request URL when you need to troubleshoot one endpoint.
Use All endpoints only when you need the same collection behavior across the project.
| Troubleshoot detail to collect | Use it to | Protection guidance |
| Request headers | Review metadata sent with a request. | Do not collect sensitive headers. Cookies, authorization, and proxy-authorization headers cannot be collected. |
| Response headers | Review metadata returned by a service. | Check whether a header can contain personal data before you collect it. |
| Request body | Review the data sent by the request. | Collect the entire body only when you have confirmed that it does not expose unnecessary personal data. |
| Response body | Review the data returned by the service. | Use a specific body element when the entire response is not needed. Body contents are collected encrypted, and requires an encryption/decryption key |
| Body elements | Collect one or more values from a JSON body. | Use JSON Path to select the smallest useful value. Encrypt values that can contain personal data. |
| Query parameters | Review parameters sent in the request URL. | can contain identifiers or other personal data. Collect them only when necessary. Query parameters are collected encrypted, and requires an encryption/decryption key. |
About Exposing Personal data
Review Protect personal data in Errors before you collect headers, request or response bodies, body elements, or query parameters. Use the narrowest rule that meets your investigation need and encrypt values that can contain personal data.
Collect and read body elements with JSON Path
Use JSON Path to collect a specific value from a JSON request or response body. For example, errors[0].message can identify an error message, while errors[0].code can identify an error code.
- Add a body-element data point to the rule.
- Enter the JSON Path expression.
- Select the request or response body.
- Select encryption when the value can contain personal data.
- Apply the body-element setting.
Operators available: .<name>, ['<name>'], [<number>]
Operators not available: Filter expressions, array slices, deep scans, current nodes, and wildcards.
Additionally, you are not allowed to use any of the JSON Path functions or filter operators.
Body element collection
|
Response body elements for analysis
|
Response body elements for troubleshooting |
| Used for error grouping and filtering (in the Analysis Context) and for Dashboard widget and Alert creation, these are elements on the response body that will be collected unencrypted. |
Visible at the individual event level in Session Replay, these are elements of the request/response body you want to collect for troubleshooting. These might need encryption to avoid collecting personal data. |
Get more flexibility in the data points you want to leverage, by collecting specific elements of the request or response body in JSON format, by using JSONPath-based query language.
Encryption of body collection
- If encryption is set, the default state for request body will be “encrypted”. Toggle it off to collect the body element unencrypted.
- For the response: the body element for troubleshooting can only be collected encrypted, as the unencrypted response body element are added for analysis.
- If encryption is not set, only request body element can be collected unencrypted. Make sure not to collect a body element containing personal information.
Types of bodies supported & limitations
| Web | Mobile applications |
|
application/json application/graphql application/xml text/plain text/csv text/xml text/html |
The SDK will attempt to parse the body as a string, whatever the format
|
Entire body collection limitations:
Request body will be collected if its size does not exceed 64 KB.
Response body will be collected if its size does not exceed 5 KB
Headers collection
Note, you can add multiple headers at once by clicking on the “+” button. This is useful if they all share the same conditions (request or response, encrypted or unencrypted).
By default “Request” is selected. You can update this to collect a Response instead.
Encryption of header collection
- If encryption is set, the default state will be “encrypted”. Toggle it off to collect the header unencrypted
-
If encryption is not set, the header can only be collected unencrypted.
Make sure not to collect a header containing personal information.
Query params
Tick the box to collect the query parameters. Query parameters will be collected encrypted, and if their size does not exceed 2 KB.
FAQs
Can I retroactively track error troubleshooting details?
No, error troubleshooting details are only collected after the setup is defined.
What happens when a request exceeds the accepted limits?
There are three data points with the following limits:
- Query parameter limit: 2 KB
- Request body size limit: 64 KB
- Response body size limit: 5 KB
Each of these data points is assessed independently from the other. When the limit is reached, we will not collect the data. For each we will push "..." un-encrypted. This will be reflected in the replay's troubleshooting details.
Why does the request or/and response body look like it is encoded, even after decryption?
This may happen if the request has the header Transfer-Encoding set to gzip value. Chrome DevTools automatically decompresses the body so this is not noticeable when using it. However, when seen in the Player Troubleshoot modal, the body is not decompressed automatically. Third-party tools can be used to decompress it after decryption.