Implementaties bijhouden

U kunt de de veranderingen eigenschap van het Spoor van New Relic toelaten om plaatsingsgebeurtenissen op uw Commerce op het project van de wolkeninfrastructuur te controleren.

De de gegevensinzameling van Plaatsingen helpt de invloed van plaatsingsveranderingen in algemene prestaties, zoals cpu, geheugen, reactietijd, en meer analyseren. Zie {de veranderingen van het 0} Spoor gebruikend NerdGraph šŸ”— in de documentatie van New Relic.

PREREQUISITES
  • NR_API_URL: New Relic API-eindpunt, in dit geval NerdGraph API-URL https://api.newrelic.com/graphql
  • NR_API_KEY: Creeer een gebruikerssleutel, zie New Relic API Sleutelsin de New Relic documentatie.
  • NR_APP_GUID: Een entiteit die gegevens aan New Relic rapporteert heeft een unieke identiteitskaart (GUID). Als voorbeeld, om op een het Opvoeren milieu toe te laten, pas de het Opvoeren milieu NR_APP_GUID wolkenvariabele met het opvoeren entiteit GUID van New Relic aan. Zie leren over de entiteiten van New Relicen NerdGraph leerprogramma: De entiteitgegevens van de meningin de New Relic documentatie.

Trackimplementaties inschakelen

Spoor uw de gebeurtenissen van de projectplaatsing van Commerce in New Relic door a manuscript integratie te creƫren.

om de spoorplaatsingen toe te laten:

  1. Wijzig op uw lokale werkstation de projectmap.

  2. Maak een action-integration.js -bestand. Kopieer de volgende code en plak deze in het action-integration.js -bestand en sla het op:

    code language-javascript
    function trackDeployments() {
      const envName = activity.payload.environment.name;
      let variables;
      activity.payload.deployment.variables.forEach(function(variable) {
        if (variable.name === "env:NR_CONFIG") {
          variables = variable.value;
        }
      });
      const config = JSON.parse(variables.replace(/'/g, '"'));
      const commitSha = activity.payload.commits ? activity.payload.commits[0].sha : activity.payload.environment.head_commit;
      const deploymentType = activity.type;
    
      if (!(envName in config)) {
        throw new Error('There is no configuration for ' + envName);
      }
    
      const configEnv = config[envName];
    
      if (!configEnv.NR_APP_GUID || !configEnv.NR_API_KEY || !configEnv.NR_API_URL) {
        throw new Error('You must define the next configuation in the env variable NR_CONFIG: NR_APP_GUID, NR_API_KEY and NR_API_URL');
      }
    
      const query = `mutation {
        changeTrackingCreateDeployment(
        deployment: {
            version: "${commitSha}",
            entityGuid: "${configEnv.NR_APP_GUID}",
            commit: "${commitSha}",
            changelog: "${deploymentType}"
        }
        ) {
          deploymentId
          entityGuid
        }
      }`;
    
      var resp = fetch(configEnv.NR_API_URL, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'API-Key': configEnv.NR_API_KEY
        },
        body: JSON.stringify({
            query
        })
      });
    
      if (!resp.ok) {
        console.log('Sending new relic change tracking failed: ' + resp.text());
      } else {
        console.log(resp.text());
      }
    }
    
    trackDeployments();
    
  3. Creeer de integratie van het a manuscript gebruikend het magento-cloud CLI bevel en van verwijzingen het action-integration.js dossier.

    code language-bash
    magento-cloud integration:add --type script --events='environment.restore, environment.push, environment.branch, environment.activate, environment.synchronize, environment.initialize, environment.merge, environment.redeploy, environment.variable.create, environment.variable.delete, environment.variable.update' --file ./action-integration.js --project=<YOUR_PROJECT_ID> --environments=<YOUR_ENVIRONMENT_ID>
    

    Monsterrespons:

    code language-terminal
    Created integration 767u4hathojjw (type: script)
    +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
    | Property              | Value                                                                                                                                   |
    +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
    | id                    | 767u4hathojjw                                                                                                                           |
    | type                  | script                                                                                                                                  |
    | role                  |                                                                                                                                         |
    | events                | - environment.restore                                                                                                                   |
    |                       | - environment.push                                                                                                                      |
    |                       | - environment.branch                                                                                                                    |
    |                       | - environment.activate                                                                                                                  |
    |                       | - environment.synchronize                                                                                                               |
    |                       | - environment.initialize                                                                                                                |
    |                       | - environment.merge                                                                                                                     |
    |                       | - environment.redeploy                                                                                                                  |
    |                       | - environment.variable.create                                                                                                           |
    |                       | - environment.variable.delete                                                                                                           |
    |                       | - environment.variable.update                                                                                                           |
    | environments          | - staging                                                                                                                               |
    |                       | - production                                                                                                                            |
    | excluded_environments | {  }                                                                                                                                    |
    | states                | - complete                                                                                                                              |
    | result                | *                                                                                                                                       |
    | script                | function variables() {                                                                                                                  |
    |                       |     var vars = {};                                                                                                                      |
    |                       |     activity.payload.deployment.variables.forEach(function(variable) {                                                                  |
    |                       |         vars[variable.name] = variable.value;                                                                                           |
    |                       |     });                                                                                                                                 |
    |                       |     return vars;                                                                                                                        |
    |                       | }                                                                                                                                       |
    |                       |                                                                                                                                         |
    |                       | function trackDeployments() {                                                                                                           |
    |                       |     const envName = activity.payload.environment.name;                                                                                  |
    |                       |                                                                                                                                         |
    |                       |     const config = JSON.parse(variables()['env:NR_CONFIG'].replace(/'/g, '"'));                                                         |
    |                       |     const commitSha = activity.payload.commits ? activity.payload.commits[0].sha : activity.payload.environment.head_commit;            |
    |                       |     const deploymentType = activity.type;                                                                                               |
    |                       |                                                                                                                                         |
    |                       |     if (!(envName in config)) {                                                                                                         |
    |                       |         throw new Error('There is no configuration for ' + envName);                                                                    |
    |                       |     }                                                                                                                                   |
    |                       |                                                                                                                                         |
    |                       |     const configEnv = config[envName];                                                                                                  |
    |                       |                                                                                                                                         |
    |                       |     if (!configEnv.NR_APP_GUID || !configEnv.NR_API_KEY || !configEnv.NR_API_URL) {                                                     |
    |                       |         throw new Error('You must define the next configuation in the env variable NR_CONFIG: NR_APP_GUID, NR_API_KEY and NR_API_URL'); |
    |                       |     }                                                                                                                                   |
    |                       |                                                                                                                                         |
    |                       |     const query = `mutation {                                                                                                           |
    |                       |         changeTrackingCreateDeployment(                                                                                                 |
    |                       |           deployment: {                                                                                                                 |
    |                       |             version: "${commitSha}",                                                                                                    |
    |                       |             entityGuid: "${configEnv.NR_APP_GUID}",                                                                                     |
    |                       |             commit: "${commitSha}",                                                                                                     |
    |                       |             changelog: "${deploymentType}"                                                                                              |
    |                       |           }                                                                                                                             |
    |                       |         ) {                                                                                                                             |
    |                       |           deploymentId                                                                                                                  |
    |                       |           entityGuid                                                                                                                    |
    |                       |         }                                                                                                                               |
    |                       |     }`;                                                                                                                                 |
    |                       |                                                                                                                                         |
    |                       |     var resp = fetch(configEnv.NR_API_URL, {                                                                                            |
    |                       |         method: 'POST',                                                                                                                 |
    |                       |         headers: {                                                                                                                      |
    |                       |             'Content-Type': 'application/json',                                                                                         |
    |                       |             'API-Key': configEnv.NR_API_KEY                                                                                             |
    |                       |         },                                                                                                                              |
    |                       |         body: JSON.stringify({                                                                                                          |
    |                       |             query                                                                                                                       |
    |                       |         })                                                                                                                              |
    |                       |     });                                                                                                                                 |
    |                       |                                                                                                                                         |
    |                       |     if (!resp.ok) {                                                                                                                     |
    |                       |         console.log('Sending new relic change tracking failed: ' + resp.text());                                                        |
    |                       |     } else {                                                                                                                            |
    |                       |         console.log(resp.text());                                                                                                       |
    |                       |     }                                                                                                                                   |
    |                       | }                                                                                                                                       |
    |                       |                                                                                                                                         |
    |                       | trackDeployments();                                                                                                                     |
    |                       |                                                                                                                                         |
    +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
    
  4. Noteer de integratie-id voor later gebruik. In dit voorbeeld is de id:

    code language-terminal
    Created integration 767u4hathojjw (type: script)
    

    U kunt desgewenst de integratie verifiƫren en de integratie-id noteren met: magento-cloud integration:list

  5. Maak de omgevingsvariabele met behulp van de voorwaarden.

    code language-bash
    magento-cloud variable:create --level project --name=env:NR_CONFIG --value='{"<YOUR_ENVIRONMENT_ID>":{"NR_API_KEY": "<YOUR_API_KEY>", "NR_API_URL": "https://api.newrelic.com/graphql", "NR_APP_GUID":"<YOUR_APP_GUID>"}}'  -p <YOUR_PROJECT_ID>
    
  6. Controleer het laatste activiteitenlogboek.

    code language-bash
    magento-cloud integration:activity:log <INTEGRATION_ID> -p <YOUR_PROJECT_ID> -e <YOUR_ENVIRONMENT_ID>
    

    Reactie:

    code language-terminal
    Integration ID: 767u4hathojjw
    Activity ID: poxqidsfajkmg
    Type: integration.script
    Description: Running activity script
    Created: 2023-08-28T20:32:02+00:00
    State: complete
    Log:
    HTTP request
    HTTP response
    {"data":{"changeTrackingCreateDeployment":{"deploymentId":"some-deployment-id","entityGuid":"SomeGUIDhere"}}}
    
  7. Login aan uw rekening van New Relic.

  8. Klik in het navigatiemenu Verkenner op APM & Services . Selecteer de omgeving Name en Account .

  9. Onder Gebeurtenissen, klik Change tracking.

    Plaatsingen

recommendation-more-help
05f2f56e-ac5d-4931-8cdb-764e60e16f26