WebSocket Testing

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Overview

WebSocket tests allow you to proactively open WebSocket connections on your endpoints to verify responses and defined conditions, such as overall response times or expected headers.

WebSocket tests can run from both managed and private locations depending on your preference for running the test from outside or inside your network. WebSocket tests can run on a schedule, on-demand, or directly within your CI/CD pipelines.

Configuration

After choosing to create an WebSocket test, define your test’s request.

Define request

  1. Specify the URL to run your test on.

  2. Enter the string you want to send in your test.

  3. Add Advanced Options (optional) to your test:

    • Timeout: Specify the amount of time in seconds before the test times out.
    • Request headers: Define headers to add to the HTTP request initiating the WebSocket connection. You can also override the default headers (for example, the user-agent header).
    • Cookies: Define cookies to add to the HTTP request initiating the WebSocket connection. Set multiple cookies using the format <COOKIE_NAME1>=<COOKIE_VALUE1>; <COOKIE_NAME2>=<COOKIE_VALUE2>.
    • HTTP Basic Auth: Add HTTP basic authentication credentials.

  1. Name your WebSocket test.
  2. Add env Tags as well as any other tag to your WebSocket test. You can then use these tags to filter through your Synthetic tests on the Synthetic Monitoring & Continuous Testing page.
Define WebSocket request

Click Test URL to try out the request configuration. A response preview is displayed on the right side of your screen.

Define assertions

Assertions define what an expected test result is. When you click Test URL, a basic assertion on response time is added. You must define at least one assertion for your test to monitor.

TypeOperatorValue Type
response timeis less thanInteger (ms)
string responsecontains, does not contain, is, is not,
matches, does not match
String
Regex
headercontains, does not contain, is, is not,
matches, does not match
String
Regex

Select the response preview directly or click New Assertion to create an assertion. You can create up to 20 assertions per WebSocket test.

Define assertions for your WebSocket test to succeed or fail on

To perform OR logic in an assertion, use the matches regex or does not match regex comparators to define a regex with multiple expected values for the same assertion type like (0|100). The test result is successful if the string response or header assertions’ value is 0 or 100.

If a test does not contain an assertion on the response body, the body payload drops and returns an associated response time for the request within the timeout limit set by the Synthetics Worker.

If a test contains an assertion on the response body and the timeout limit is reached, an Assertions on the body/response cannot be run beyond this limit error appears.

Select locations

Select the Locations to run your WebSocket test from. WebSocket tests can run from both managed and private locations depending on your preference for running the test from outside or inside your network.

Datadog’s out-of-the-box managed locations allow you to test public-facing websites and endpoints from regions where your customers are located.

AmericasAPACEMEA
Canada Central (AWS)Hong Kong (AWS)Cape Town (AWS)
Northern California (AWS)Mumbai (AWS)Frankfurt (AWS)
Northern Virginia (AWS)Seoul (AWS)Ireland (AWS)
Ohio (AWS)Singapore (AWS)London (AWS)
Oregon (AWS)Sydney (AWS)Paris (AWS)
São Paulo (AWS)Tokyo (AWS)Stockholm (AWS)
Virginia (Azure)Osaka (AWS)Milan (AWS)
Jakarta (AWS)Bahrain (AWS)

The Datadog for Government site (US1-FED) uses the following managed location:

Americas
US-West

Specify test frequency

WebSocket tests can run:

  • On a schedule to ensure your most important endpoints are always accessible to your users. Select the frequency at which you want Datadog to run your WebSocket test.
  • Within your CI/CD pipelines to start shipping without fearing faulty code might impact your customers’ experience.
  • On-demand to run your tests whenever makes the most sense for your team.

Définir des conditions d’alerte

Définissez des conditions d’alerte afin de spécifier les circonstances dans lesquelles vous souhaitez qu’un test échoue et déclenche une alerte.

Règle d’alerte

Lorsque vous définissez les conditions d’alerte sur An alert is triggered if any assertion fails for X minutes from any n of N locations, une alerte se déclenche uniquement si les deux conditions suivantes se vérifient :

  • Au moins un emplacement a donné lieu à un échec (au moins une assertion a échoué) au cours des X dernières minutes
  • À un moment au cours des X dernières minutes, au moins n emplacements ont donné lieu à un échec.

Nouvelle tentative rapide

Votre test peut déclencher X nouvelles tentatives après Y ms en cas d’échec. Cet intervalle peut être personnalisé en fonction de vos préférences en matière d’alertes.

La disponibilité d’un emplacement est calculée pour chaque évaluation (quels que soient les résultats du dernier test avant l’évaluation). La disponibilité totale est calculée selon les conditions d’alerte configurées. Les notifications envoyées se basent sur la disponibilité totale.

Configurer le monitor de test

Votre test envoie une notification selon les conditions d’alerte définies au préalable. Cette section vous permet de définir les conditions et le message à envoyer à vos équipes.

  1. Tout comme pour les monitors, sélectionnez les utilisateurs et/ou services qui doivent recevoir des notifications. Pour ce faire, ajoutez @notification au message, ou cherchez des membres d’équipe ou des intégrations connectées à l’aide du menu déroulant.

  2. Saisissez un message de notification pour le test. Ce champ accepte le format de mise en forme Markdown standard ainsi que les variables conditionnelles suivantes :

    Variable conditionnelleDescription
    {{ #is_alert }}S’affiche lorsque le test envoie une alerte.
    {{ ^is_alert }}S’affiche lorsque le test n’envoie pas d’alerte.
    {{ #is_recovery }}S’affiche lorsque le test est rétabli depuis un état d’alerte.
    {{ ^is_recovery }}S’affiche lorsque le test n’est pas rétabli depuis un état d’alerte.
    {{ #is_renotify }}S’affiche lorsque le monitor renvoie des notifications.
    {{ ^is_renotify }}S’affiche lorsque le monitor ne renvoie pas de notification.
    {{ #is_priority }}S’affiche lorsque le monitor correspond à la priorité (P1 à P5).
    {{ ^is_priority }}S’affiche lorsque le monitor ne correspond pas à la priorité (P1 à P5).
  3. Indiquez une fréquence de renvoi du message de notification en cas d’échec d’un test. Si vous ne souhaitez pas renvoyer de notification en cas d’échec, définissez l’option sur Never renotify if the monitor has not been resolved.

  4. Cliquez sur Create pour enregistrer la configuration de votre test et votre monitor.

Pour en savoir plus, consultez la section Utiliser des monitors de test Synthetic.

Variables

Create local variables

To create a local variable, click Create a Local Variable. You can select one of the following available builtins to add to your variable string:

{{ numeric(n) }}
Generates a numeric string with n digits.
{{ alphabetic(n) }}
Generates an alphabetic string with n letters.
{{ alphanumeric(n) }}
Generates an alphanumeric string with n characters.
{{ date(n unit, format) }}
Generates a date in one of Datadog’s accepted formats with a value corresponding to the UTC date the test is initiated at + or - n units.
{{ timestamp(n, unit) }}
Generates a timestamp in one of Datadog’s accepted units with a value corresponding to the UTC timestamp the test is initiated at +/- n units.
{{ uuid }}
Generates a version 4 universally unique identifier (UUID).
{{ public-id }}
Injects the Public ID of your test.
{{ result-id }}
Injects the Result ID of your test run.

To obfuscate local variable values in test results, select Hide and obfuscate variable value. Once you have defined the variable string, click Add Variable.

Use variables

You can use the global variables defined on the Settings page in the URL, advanced options, and assertions of your WebSocket tests.

To display your list of variables, type {{ in your desired field.

Test failure

A test is considered FAILED if it does not satisfy one or more assertions or if the request prematurely failed. In some cases, the test can fail without testing the assertions against the endpoint.

These reasons include the following:

CONNRESET
The connection was abruptly closed by the remote server. Possible causes include the web server encountering an error or crashing while responding, or loss of connectivity of the web server.
DNS
DNS entry not found for the test URL. Possible causes include misconfigured test URL or the wrong configuration of your DNS entries.
INVALID_REQUEST
The configuration of the test is invalid (for example, a typo in the URL).
SSL
The SSL connection couldn’t be performed. See the dedicated error page for more information.
TIMEOUT
The request couldn’t be completed in a reasonable time. Two types of TIMEOUT errors can happen:
  • TIMEOUT: The request couldn't be completed in a reasonable time. indicates that the request duration hit the test defined timeout (default is set to 60s). For each request only the completed stages for the request are displayed in the network waterfall. For example, in the case of Total response time only being displayed, the timeout occurred during the DNS resolution.
  • TIMEOUT: Overall test execution couldn't be completed in a reasonable time. indicates that the test duration (request + assertions) hits the maximum duration (60.5s).
WEBSOCKET
The WebSocket connection was closed or cannot be opened. One type of WEBSOCKET error can happen:
  • WEBSOCKET: Received message longer than the maximum supported length. indicates that the response message length hits the maximum length (50kb).

Permissions

By default, only users with the Datadog Admin and Datadog Standard roles can create, edit, and delete Synthetic WebSocket tests. To get create, edit, and delete access to Synthetic WebSocket tests, upgrade your user to one of those two default roles.

If you are using the custom role feature, add your user to any custom role that includes synthetics_read and synthetics_write permissions.

Restrict access

Access restriction is available for customers using custom roles on their accounts.

You can restrict access to a WebSocket test based on the roles in your organization. When creating a WebSocket test, choose which roles (in addition to your user) can read and write your test.

Set permissions for your test

Further Reading

PREVIEWING: esther/docs-9518-update-example-control-sensitive-log-data