Objective
How to instrument Keystone CMS with the Node Agent.
Process
The following process describes how to instrument Keystone (https://github.com/keystonejs/keystone) CMS with the Node Agent.
1. Keystone
We'll follow the "Getting Started" guide from Keystone (https://keystonejs.com/docs/getting-started) to install a Keystone instance. We'll use npm
in this example.
- From a directory of your choice, create a new Keystone project by running:
npm init keystone-app@latest
- You'll be prompted to enter a desired directory for your project.
✔ What directory should create-keystone-app generate your app into? · keystone
- Allow
create-keystone-app
to complete the installation. You'll see the following once completed:🎉 Keystone created a starter project in: keystone
To launch your app, run:
- cd keystone
- npm run dev
Next steps:
- Read keystone/README.md for additional getting started details.
- Edit keystone/keystone.ts to customize your app.
- Open the Admin UI
- Open the Graphql API
- Read the docs
- Star Keystone on GitHub - Navigate to the newly created project and make sure it runs
cd keystone
e.g.
npm run dev
❯ cd keystone
❯ npm run dev
> keystone-app@1.0.2 dev
> keystone dev
✨ Starting Keystone
⭐️ Server listening on :3000 (http://localhost:3000/)
⭐️ GraphQL API available at /api/graphql
✨ Generating GraphQL and Prisma schemas
✨ sqlite database "keystone.db" created at file:./keystone.db
✨ Your database is now in sync with your schema
✨ Connecting to the database
✨ Creating server
✅ GraphQL API ready
✨ Generating Admin UI code
✨ Preparing Admin UI app
✅ Admin UI ready
2. Node Agent
- In the directory for your Keystone project (e.g.,
keystone
above), run:npm install @contrast/agent
- Configure the Node Agent with either
CONTRAST
environment variables or acontrast_security.yaml
file located in one of the default locations - Configuration - Order of precedence - We'll utilize the NODE_OPTIONS environment variable to require the Node Agent by running:
NODE_OPTIONS='-r @contrast/agent' npm run dev
e.g.
❯ NODE_OPTIONS='-r @contrast/agent' npm run dev
@contrast/agent 4.33.2
--------------------------------------
> keystone-app@1.0.2 dev
> keystone dev
@contrast/agent 4.33.2
--------------------------------------
✨ Starting Keystone
⭐️ Server listening on :3000 (http://localhost:3000/)
⭐️ GraphQL API available at /api/graphql
✨ Generating GraphQL and Prisma schemas
✨ The database is already in sync with the Prisma schema
@contrast/agent 4.33.2
--------------------------------------
✨ Connecting to the database
✨ Creating server
✅ GraphQL API ready
✨ Generating Admin UI code
✨ Preparing Admin UI app
✅ Admin UI ready - The application should now be visible in the Contrast UI: