jomashop / module-new-relic-monitoring-for-gql

jomashop/module-new-relic-monitoring-for-gql

Send GraphQL transactions to New Relic

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: N/A Security: Pass

Magento 2 - Automatic GraphQL transaction naming for New Relic

New Relic's PHP agent has support for automatic transaction naming for REST and SOAP, but not GraphQL. Thus, this Magento 2 module is developed to support sending a GraphQL transaction name to New Relic automatically.

Details

A transaction is named based on the service class and method that handled the request, /GraphQl/Controller/GraphQl\{operation name|(query|mutation)}\{name|Multiple}.

The logic is explained as follows:

  1. If the operationName field is set, use the operation name.
  2. If the operationName field is not set, use the name of the query or mutation.
  3. If a GraphQL query consists of multiple queries or mutations, the transaction would be indicated as 'Multiple'. Note that in any cases, the operationName field takes the priority.

Installation

composer require jomashop/module-new-relic-monitoring-for-gql

Examples

  1. Operation name is set
mutation createCustomerTest{
  createCustomer(
    input: {
      firstname: "Bob"
      lastname: "Loblaw"
      email: "[email protected]"
      password: "b0bl0bl@w"
      is_subscribed: true
    }
  ) {
    customer {
      firstname
      lastname
      email
      is_subscribed
    }
  }
}

In New Relic, the transaction name would be: /GraphQl/Controller/GraphQl/Mutation/createCustomerTest

  1. Operation name is not set and only 1 query/mutation is requested
mutation {
  createCustomer(
    input: {
      firstname: "Bob"
      lastname: "Loblaw"
      email: "[email protected]"
      password: "b0bl0bl@w"
      is_subscribed: true
    }
  ) {
    customer {
      firstname
      lastname
      email
      is_subscribed
    }
  }
}

In NR, the transaction name would be /GraphQl/Controller/GraphQl/Mutation/createCustomer

  1. Operation name is not set and multiple queries/mutations are requested
query {
  cmsBlocks(identifiers: "footer_links_block") {
    items {
      identifier
      title
      content
    }
  },
  storeConfig {
    id
    code
    website_id
    locale
    base_currency_code
    default_display_currency_code
    timezone
    weight_unit
    base_url
    base_link_url
    base_static_url
    base_media_url
    secure_base_url
    secure_base_link_url
    secure_base_static_url
    secure_base_media_url
    store_name
  }
}

In NR, the transaction name would be /GraphQl/Controller/GraphQl/Query/Multiple


Other features

This module also supports using newrelic_add_custom_parameter instead of newrelic_notice_error.

  • See ErrorHandler and ReportErrorEvaluatorInterface
  • This can be used to reduce the number of GraphQlInputException / GraphQlAuthorizationException / GraphQlAuthenticationException which are logged as errors
  • Data is set to ExceptionIsSkipReportError / ExceptionClass / ExceptionMessage

Error extraction:

  • If the error is an AggregateExceptionInterface the module tries to use the inner error.
  • If the error is a LocalizedException then ExceptionRawMessage is set as a custom parameter

If the header x-client-version is set then ClientVersion is set as a custom parameter

  • This can be used to track the Frontend Version sending the GQL request

Core Magento logging from 2.4.4 is disabled as running both is does not provide extra value

If Magento >= 2.4.7 is used the extracted data changes

  • The AST is parsed to extract various data
  • <2.4.7 parses the string

Change Log

v2.0.1

  • PHP 8.4 Compatibility - Fixing Implicitly marking parameter as nullable is deprecated

v2.0.0

  • Improved error extraction for LocalizedException and AggregateExceptionInterface
  • Support for using newrelic_add_custom_parameter instead of newrelic_notice_error.
    • This requires custom code providing a ReportErrorEvaluatorInterface which controls which errors are diverted
  • Support for reading the x-client-version header to set ClientVersion
  • Magento 2.4.4's NewRelic logging is disabled to prevent double work extracting the data
  • If the GQL's AST is available, as in 2.4.7, the extracted data changes and should be improved.
  • Transaction naming uses forward slashes only
    • This will 'break' all dashboards and queries that check or facet on the operation name

v1.1.1

  • Send requested fields as a custom parameter to NR

v1.1.0

  • Able to log GraphQl errors
Versions
Version Stability QA Status Compatibility Released
2.0.1 stable Fail Magento 2.4.7-2.4.9 Details 2026-04-24 14:33:18
2.0.0 stable Not tested Not yet tested Details 2026-04-23 20:00:46
1.1.1 stable Not tested Not yet tested Details 2021-08-04 18:02:19
1.1.0 stable Not tested Not yet tested Details 2020-11-23 22:57:42
1.0.0 stable Not tested Not yet tested Details 2020-06-29 21:29:52

Requires 1

Package Constraint
magento/framework *

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — a phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Warning 9 9 warnings (ruleset: Magento2) — 4 auto-fixable with phpcbf
PHPMD Warning 14 14 rule violations (UnusedFormalParameter:12, MissingImport:1, ExcessiveMethodLength:1)
Cpd Pass 0
Composer validate Info 3 valid; 3 advisory notes (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 4 4
2.4.8 4 4
2.4.9 4 4

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0

No license declared

This package's composer.json doesn't declare a license, homepage, or authors. Check the source repository for terms of use.

Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.