Spåra distributioner
Du kan aktivera funktionen Spåra ändringar i New Relic för att övervaka distributionshändelser i ditt Commerce i molninfrastrukturprojekt.
Datainsamlingen för driftsättningar hjälper till att analysera effekten av driftsättningsändringar på övergripande prestanda, som CPU, minne, svarstid med mera. Se Spåra ändringar med NerdGraph i New Relic-dokumentationen.
NR_API_URL
: New Relic API-slutpunkt, i det här fallet NerdGraph API URLhttps://api.newrelic.com/graphql
NR_API_KEY
: Skapa en användarnyckel, se New Relic API-nycklar i New Relic -dokumentationen.NR_APP_GUID
: En entitet som rapporterar data till New Relic har ett unikt ID (GUID). Om du till exempel vill aktivera i en mellanlagringsmiljö justerar du mellanlagringsmiljönsNR_APP_GUID
molnvariabel med mellanlagringsenhetens GUID från New Relic. Se självstudiekursen Lär dig mer om New Relic-entiteter och NerdGraph: Visa entitetsdata i New Relic -dokumentationen.
Aktivera spårning av distributioner
Spåra dina Commerce-projektdistributionshändelser i New Relic genom att skapa en script-integrering.
Så här aktiverar du spårdistributioner:
-
Byt till din projektkatalog på din lokala arbetsstation.
-
Skapa en
action-integration.js
-fil. Kopiera följande kod och klistra in den i filenaction-integration.js
och spara den: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();
-
Skapa en skript-integrering med CLI-kommandot
magento-cloud
och referera till filenaction-integration.js
.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>
Exempelsvar:
code language-none 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(); | | | | +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
-
Anteckna integrerings-ID:t för senare bruk. I det här exemplet är ID:
code language-none Created integration 767u4hathojjw (type: script)
Du kan också verifiera integreringen och anteckna integrerings-ID med:
magento-cloud integration:list
-
Skapa systemvariabeln med hjälp av de obligatoriska inställningarna.
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>
-
Granska den senaste aktivitetsloggen.
code language-bash magento-cloud integration:activity:log <INTEGRATION_ID> -p <YOUR_PROJECT_ID> -e <YOUR_ENVIRONMENT_ID>
Svar:
code language-none 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"}}}
-
Logga in på ditt New Relic-konto.
-
Klicka på APM & Services på navigeringsmenyn i Utforskaren. Välj din miljö Name och Account.
-
Klicka på Change tracking under Händelser.