Skip to content

Conversation

@andyabih
Copy link
Contributor

@andyabih andyabih commented Oct 26, 2025

Given that Sentry is still not ready for RC, New Relic is pretty much the next best thing.

Added a quick guide on how to have it setup for monitoring.

Summary by CodeRabbit

  • Documentation
    • Expanded observability docs with a full New Relic integration guide, including quick-start configuration, server and client integration steps, middleware and route setup examples for collecting traces and custom attributes, and CLI guidance to run the agent. New Relic content is presented alongside existing OpenTelemetry and other external observability tooling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2025

Walkthrough

Adds a New Relic integration guide to the React observability docs, including a sample newrelic.js config, server middleware and route-aware transaction examples, SPA/browser entry snippet, and a CLI command to run the server with the New Relic agent.

Changes

Cohort / File(s) Change Summary
New Relic Integration Documentation
docs/start/framework/react/guide/observability.md
Expanded External Observability Tools with a New Relic section: added newrelic.js quick-start config, server-side snippets (agent require, nrTransactionMiddleware, route-based transaction naming, custom attributes, start.ts / server.tsx init), SPA/browser __root.tsx example, and CLI usage (node -r newrelic .output/server/index.mjs).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Server as App Server
  participant NR as New Relic Agent
  participant Browser as SPA / Browser
  participant Collector as New Relic Collector

  rect rgb(230,248,255)
  Dev->>Server: start server with `node -r newrelic .output/server/index.mjs`
  Server->>NR: require('newrelic') -> load `newrelic.js`
  end

  rect rgb(240,255,230)
  Browser->>Server: HTTP request / route
  Server->>Server: nrTransactionMiddleware sets transaction name
  Server->>NR: NR.setTransactionName(routeId)\nNR.addCustomAttributes({ route, method, user })
  Server->>Collector: NR sends traces & events
  Collector-->>NR: ingest ack
  end

  rect rgb(255,248,230)
  Browser->>Browser: client-side NR script in `__root.tsx` collects SPA telemetry
  Browser->>Collector: browser agent sends telemetry
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify example newrelic.js values are non-sensitive and follow New Relic config schema.
  • Confirm server snippets (middleware, transaction naming) match project server/bootstrap patterns and TypeScript/Node syntax.
  • Check the SPA __root.tsx snippet and CLI example placement for clarity and consistency.

Poem

🐇 I nibbled code and found a trace,
New Relic lights each hidden place.
Routes and spans in tidy rows,
I hop through metrics as they grow. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "docs: add guide for New Relic integration" is directly and accurately related to the main change in the changeset. The summary confirms that a comprehensive New Relic integration guide section was added to the observability documentation, covering SSR configuration, server routes/functions, SPA/Browser guidance, and CLI guidance. The title uses the conventional "docs:" prefix, is concise and specific, and clearly conveys the primary change from the developer's perspective without ambiguity, noise, or vague terminology.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the documentation Everything documentation related label Oct 26, 2025
@nx-cloud
Copy link

nx-cloud bot commented Oct 26, 2025

View your CI Pipeline Execution ↗ for commit 0f1f05b

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded <1s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-26 21:26:04 UTC

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
docs/start/framework/react/guide/observability.md (3)

491-506: Add environment variable guidance and file placement instructions.

The configuration example hardcodes the license key as a placeholder, but provides no guidance on using environment variables in production or where to place this file. Compare this to the Sentry section, which references environment variables via import.meta.env.

Add a note explaining that:

  1. The newrelic.js file should be placed at the root of your project
  2. The license_key should be loaded from environment variables in production
-// newrelic.js - New Relic agent configuration
+// newrelic.js - New Relic agent configuration (place at project root)
 exports.config = {
   app_name: ['YourTanStackApp'],             // Your application name in New Relic
-  license_key: 'YOUR_NEW_RELIC_LICENSE_KEY', // Your New Relic license key
+  license_key: process.env.NEW_RELIC_LICENSE_KEY || 'YOUR_NEW_RELIC_LICENSE_KEY',
   agent_enabled: true,

538-540: Explain the build output path and provide context for the run command.

The command node -r newrelic .output/server/index.mjs assumes knowledge of the build output structure. Clarify that .output/server/index.mjs is the compiled server entry point after building, and provide the build step if relevant.

-```bash
-node -r newrelic .output/server/index.mjs
-```
+```bash
+# Build the app first (adjust command based on your setup)
+npm run build
+
+# Run with New Relic monitoring enabled
+# The -r flag requires the newrelic module before app startup
+node -r newrelic .output/server/index.mjs
+```

491-541: Add resource links and example repository reference for consistency.

The Sentry section includes links to documentation and a working example ([Get started with Sentry →](...) | [View integration example →](...)). The New Relic section should follow the same pattern for consistency and to help users get started quickly.

After the bash code block (line 540), add:

+
+[Get started with New Relic →](https://newrelic.com/signup) | [View New Relic Node.js agent docs →](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7b9041 and 03e149c.

📒 Files selected for processing (1)
  • docs/start/framework/react/guide/observability.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Use internal docs links relative to the docs/ folder (e.g., ./guide/data-loading)

Files:

  • docs/start/framework/react/guide/observability.md
docs/{router,start}/**

📄 CodeRabbit inference engine (AGENTS.md)

Place router docs under docs/router/ and start framework docs under docs/start/

Files:

  • docs/start/framework/react/guide/observability.md
🔇 Additional comments (1)
docs/start/framework/react/guide/observability.md (1)

508-536: Verify New Relic API methods and clarify import precedence.

The newrelic import at line 510 is correctly placed first (required for agent setup), and the API calls setControllerName() and addCustomAttributes() appear valid. However, the example would benefit from a brief comment explaining why this custom handler is needed—to group transactions by route rather than unique URLs.

Consider adding a clarifying comment:

 const customHandler = defineHandlerCallback(async (ctx) => {
-  // We do this so that transactions are grouped under the route ID instead of unique URLs
+  // Group transactions by route ID instead of unique URLs for better organization in New Relic

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 26, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5631

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5631

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5631

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5631

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5631

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5631

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5631

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5631

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5631

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5631

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5631

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5631

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5631

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5631

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5631

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5631

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5631

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5631

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5631

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5631

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5631

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5631

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5631

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5631

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5631

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5631

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5631

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5631

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5631

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5631

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5631

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5631

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5631

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5631

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5631

commit: e9a0bf8

defineHandlerCallback,
} from '@tanstack/react-start/server'

const customHandler = defineHandlerCallback(async (ctx) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will only be invoked for SSR then, not for server functions or server routes. this restriction should be documented or better, resolved

@schiller-manuel schiller-manuel merged commit 05b4def into TanStack:main Oct 26, 2025
4 of 5 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33e2170 and 0f1f05b.

📒 Files selected for processing (1)
  • docs/start/framework/react/guide/observability.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Use internal docs links relative to the docs/ folder (e.g., ./guide/data-loading)

Files:

  • docs/start/framework/react/guide/observability.md
docs/{router,start}/**

📄 CodeRabbit inference engine (AGENTS.md)

Place router docs under docs/router/ and start framework docs under docs/start/

Files:

  • docs/start/framework/react/guide/observability.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Preview

Comment on lines +548 to +550
```bash
node -r newrelic .output/server/index.mjs
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify or parameterize the build output path.

The CLI command assumes a specific build output structure (.output/server/index.mjs), which may vary depending on project configuration. Consider adding guidance on how to locate the correct server entry point or reference the framework's build configuration documentation.

🤖 Prompt for AI Agents
In docs/start/framework/react/guide/observability.md around lines 548 to 550,
the example command hard-codes the build output path (.output/server/index.mjs)
which may not match every project's build output; update the guidance to show
how to determine or parameterize the server entry point (e.g., explain to locate
the server entry in the project's build output or bundler config and replace the
path, show an example using an environment variable or npm script placeholder
like NODE_SERVER_ENTRY) and add a short note pointing readers to the
framework/build configuration docs for where to find the actual output path.

Comment on lines +594 to +601
id: 'new-relic',

// either copy/paste your New Relic integration script here
children: `...`,

// or you can create it in your public folder and then reference it here
src: '/newrelic.js',
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Provide a complete or clearer example for the New Relic script integration.

Line 597 shows children: \...`` as a placeholder, which doesn't adequately guide users on what content should go there. The comment mentions "copy/paste your New Relic integration script here," but the example is too vague.

Consider either:

  • Providing a representative example of what a real New Relic script snippet looks like
  • Removing the inline approach and emphasizing the src: '/newrelic.js' approach as the recommended method
  • Adding a link to New Relic's documentation on how to obtain the script snippet
🤖 Prompt for AI Agents
In docs/start/framework/react/guide/observability.md around lines 594 to 601,
the New Relic integration example uses a vague placeholder (`children: \`...\``)
that doesn't show what users must paste; replace that placeholder with either a
representative New Relic browser agent script snippet (a short, sanitized
example of the <script> tag and minimal config fields) or remove the inline
script example and clearly recommend using the external file approach (keep
`src: '/newrelic.js'`) while adding a link to New Relic's official docs for
obtaining the exact snippet so users know where to get the authoritative code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Everything documentation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants