Skip to content

Commit f2c183d

Browse files
authored
Merge pull request #373 from wpengine/chore-logging-develop-event-lifecycle
chore: WPGraphQL Event Lifecycle Logging
2 parents a0b0a05 + ddaae61 commit f2c183d

File tree

16 files changed

+1991
-114
lines changed

16 files changed

+1991
-114
lines changed

plugins/wpgraphql-logging/README.md

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ A WPGraphQL logging plugin that provides visibility into request lifecycle to he
66
* [Documentation](#getting-started)
77

88
> [!CAUTION]
9-
> This plugin is currently in development state and is not production ready.
9+
> This plugin is currently in alpha state and is not production ready but please feel free to test.
1010
1111
-----
1212

13-
@TODO - Badges
13+
@TODO
1414

1515
-----
1616

@@ -19,8 +19,9 @@ A WPGraphQL logging plugin that provides visibility into request lifecycle to he
1919
## Table of Contents
2020

2121
- [Overview](#overview)
22-
- [Features](#features)
2322
- [Getting Started](#getting-started)
23+
- [Features](#features)
24+
- [Usage](#usage)
2425
- [Configuration](#configuration)
2526
- [Extending the Functionality](#extending-the-functionality)
2627
- [Testing](#testing)
@@ -37,14 +38,16 @@ Designed with extensibility in mind, developers can easily customize and extend
3738

3839
---
3940

40-
## Features
4141

42-
@TODO
42+
## Getting Started
4343

44+
To install, you need to follow our guide here to install the plugin via composer - [https://github.com/wpengine/hwptoolkit/blob/main/docs/how-to/install-toolkit-plugins/index.md]
4445

45-
## Getting Started
46+
Once you have the composer repository setup, please run `composer req wpengine/wpgraphql-logging:*` to install the plugin.
4647

47-
@TODO
48+
Plugin should start logging data, once activated.
49+
50+
@TODO add more info once we have configuration setup.
4851

4952

5053
---
@@ -53,10 +56,10 @@ Designed with extensibility in mind, developers can easily customize and extend
5356

5457
```text
5558
wpgraphql-logging/
59+
├── docs/ # Docs for extending the plugin.
5660
├── src/ # Main plugin source code
5761
│ ├── Admin/ # Admin settings, menu, and settings page logic
58-
│ ├── Events/ # Event definitions and event dispatcher logic
59-
│ ├── Hooks/ # WordPress hooks and filters
62+
│ ├── Events/ # Event logging, pub/sub event manager for extending the logging.
6063
│ ├── Logging/ # Logging logic, logger service, Monolog handlers & processors
6164
│ ├── Plugin.php # Main plugin class (entry point)
6265
│ └── Autoload.php # PSR-4 autoloader
@@ -66,24 +69,60 @@ wpgraphql-logging/
6669
├── [activation.php]
6770
├── [composer.json]
6871
├── [deactivation.php]
69-
├── [ACTIONS_AND_FILTERS.md]
7072
├── [TESTING.md]
7173
├── [README.md]
7274
```
7375

74-
## Configuration
76+
## Features
7577

76-
@TODO - When we integrate plugin configuration.
78+
- **Query event lifecycle logging**
79+
- **Pre Request** (`do_graphql_request`): captures `query`, `variables`, `operation_name`.
80+
- **Before Execution** (`graphql_before_execute`): includes a snapshot of request `params`.
81+
- **Before Response Returned** (`graphql_return_response`): inspects `response` and automatically upgrades level to Error when GraphQL `errors` are present (adds `errors` to context when found).
7782

78-
### Settings
83+
- **Built-in pub/sub event bus**
84+
- In-memory event manager with priorities: `subscribe(event, listener, priority)` and `publish(event, payload)`.
85+
- Transform pipeline: `transform(event, payload)` lets you mutate `context` and `level` before logging/publishing.
86+
- WordPress bridges: actions `wpgraphql_logging_event_{event}` and filters `wpgraphql_logging_filter_{event}` to integrate with standard hooks.
87+
88+
- **Monolog-powered logging pipeline**
89+
- Default handler: stores logs in a WordPress table (`{$wpdb->prefix}wpgraphql_logging`).
90+
- Default processors: Memory usage, memory peak, web request, process ID, and `WPGraphQLQueryProcessor` (adds `wpgraphql_query`, `wpgraphql_operation_name`, `wpgraphql_variables`).
91+
92+
- **Simple developer API**
93+
- `Plugin::on()` to subscribe, `Plugin::emit()` to publish, `Plugin::transform()` to modify payloads.
94+
95+
- **Safe-by-default listeners/transforms**
96+
- Exceptions in listeners/transforms are caught and logged without breaking the pipeline.
97+
98+
---
99+
100+
## Usage
101+
102+
WPGraphQL Logging Plugin is highly configurable and extendable and built with developers in mind to allow them to modify, change or add data, loggers etc to this plugin. Please read the docs below:
103+
104+
105+
The following documentation is available in the `docs/` directory:
106+
107+
- [Events](docs/Events.md):
108+
Learn about the event system, available events, and how to subscribe, transform, or listen to WPGraphQL Logging events.
109+
110+
- [Logging](docs/Logging.md):
111+
Learn about the logging system, Monolog integration, handlers, processors, and how to use or extend the logger.
112+
113+
---
114+
115+
116+
117+
## Configuration
79118

80119
@TODO - When we integrate plugin configuration.
81120

82121
---
83122

84-
## Actions & Filters
123+
### Settings
85124

86-
See the [Actions & Filters documentation](ACTIONS_AND_FILTERS.md) for a comprehensive list of available hooks and how to use them.
125+
@TODO - When we integrate plugin configuration.
87126

88127
---
89128

plugins/wpgraphql-logging/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"slevomat/coding-standard": "^8.0",
5454
"szepeviktor/phpstan-wordpress": "^2.0",
5555
"wp-cli/wp-cli-bundle": "^2.8.1",
56+
"wp-graphql/wp-graphql": "^2.3",
5657
"wp-graphql/wp-graphql-testcase": "^3.0.1"
5758
},
5859
"config": {
@@ -80,7 +81,7 @@
8081
"/.DS_Store",
8182
"/.docker/",
8283
"/.env.dist",
83-
"/ACTIONS_AND_FILTERS.md",
84+
"/docs",
8485
"/TESTING.md",
8586
"/Thumbs.db",
8687
"/artifacts",

0 commit comments

Comments
 (0)