Rastrear implantações
Você pode ativar o New Relic Rastrear alterações recurso para monitorar eventos de implantação no seu projeto do Commerce na infraestrutura em nuvem.
A coleta de dados de Implantações ajuda a analisar o impacto das alterações de implantação no desempenho geral, como CPU, memória, tempo de resposta e muito mais. Consulte Rastrear alterações usando o NerdGraph no Documentação do New Relic.
NR_API_URL
: endpoint da API do New Relic, neste caso o URL da API NerdGraphhttps://api.newrelic.com/graphql
NR_API_KEY
: para criar uma chave de usuário, consulte Chaves de API do New Relic no New Relic documentação.NR_APP_GUID
: uma entidade que relata dados para o New Relic tem uma ID exclusiva (GUID). Como exemplo, para ativar em um ambiente de preparo, ajuste o ambiente de preparoNR_APP_GUID
variável de nuvem com o GUID da entidade de preparo do New Relic. Consulte a Saiba mais sobre entidades do New Relic e Tutorial do NerdGraph: exibir dados da entidade no New Relic documentação.
Ativar Rastrear implantações
Acompanhe os eventos de implantação de projeto do Commerce no New Relic criando uma script integração.
Para ativar as implantações de rastreamento:
-
Na estação de trabalho local, altere para o diretório do projeto.
-
Criar um
action-integration.js
arquivo. Copie o código a seguir e cole-o noaction-integration.js
arquivo e salvar: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();
-
Criar um script integração usando o
magento-cloud
Comando da CLI e referência aaction-integration.js
arquivo.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>
Exemplo de resposta:
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(); | | | | +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
-
Anote a ID de integração para uso posterior. Neste exemplo, a ID é:
code language-terminal Created integration 767u4hathojjw (type: script)
Como opção, verifique a integração e observe a ID de integração usando:
magento-cloud integration:list
-
Crie a variável de ambiente usando os pré-requisitos.
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>
-
Revise o último log de atividades.
code language-bash magento-cloud integration:activity:log <INTEGRATION_ID> -p <YOUR_PROJECT_ID> -e <YOUR_ENVIRONMENT_ID>
Resposta:
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"}}}
-
Faça logon no Conta do New Relic.
-
No menu de navegação do Explorer, clique em APM & Services. Selecione seu ambiente Name e Account.
-
Em Eventos, clique em Change tracking.