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

> Send GraphQL transactions to New Relic

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

Canonical URL: https://packagento.com/jomashop/module-new-relic-monitoring-for-gql

## At a glance

- **Vendor**: jomashop (https://packagento.com/jomashop.md)
- **Latest version**: 2.0.1 — released 2026-04-24
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/jomashop/module-new-relic-monitoring-for-gql and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require jomashop/module-new-relic-monitoring-for-gql:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Send GraphQL transactions to New Relic

## README

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
```graphql
mutation createCustomerTest{
  createCustomer(
    input: {
      firstname: "Bob"
      lastname: "Loblaw"
      email: "test@example.com"
      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`

2. Operation name is not set and only 1 query/mutation is requested
```graphql
mutation {
  createCustomer(
    input: {
      firstname: "Bob"
      lastname: "Loblaw"
      email: "test@example.com"
      password: "b0bl0bl@w"
      is_subscribed: true
    }
  ) {
    customer {
      firstname
      lastname
      email
      is_subscribed
    }
  }
}
```

In NR, the transaction name would be `/GraphQl/Controller/GraphQl/Mutation/createCustomer`

3. Operation name is not set and multiple queries/mutations are requested
```graphql
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

## Changelog

### 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

## Recent Versions

| Version | Released |
|---|---|
| 2.0.1 | 2026-04-24 |
| 2.0.0 | 2026-04-23 |
| 1.1.1 | 2021-08-04 |
| 1.1.0 | 2020-11-23 |
| 1.0.0 | 2020-06-29 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/framework | * |

## Quality

Latest release (2.0.1) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| 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. Never affect the Compatibility verdict — 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.

| 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 against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| 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 per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| 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

| 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

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["jomashop/module-new-relic-monitoring-for-gql"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

jomashop is a Magento 2 vendor on Packagento. See https://packagento.com/jomashop.md for their full catalogue.

