-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added example of using startWebTransaction (#290)
- Loading branch information
Showing
13 changed files
with
317,029 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright 2022 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
module.exports = { | ||
extends: '@newrelic', | ||
parserOptions: { | ||
ecmaVersion: 'latest' | ||
}, | ||
rules: { | ||
'no-console': 'off' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Sample Start Web Transactions Application | ||
This example demonstrates how to wrap server code in [startWebTransaction](https://newrelic.github.io/node-newrelic/API.html#startWebTransaction) to record custom web transactions. This wraps [socket.io](https://github.com/socketio/socket.io) events in web transactions and records custom segments for the work. It also contains a [socket.io](https://github.com/socketio/socket.io) client that interacts with the web socket server. | ||
|
||
## Getting Started | ||
|
||
1. Clone or fork this repository. | ||
2. Navigate to this example's sub directory | ||
``` | ||
cd newrelic-node-examples/custom-instrumentation/start-web-transaction | ||
``` | ||
3. Install dependencies and run application. | ||
``` | ||
npm install | ||
cp env.sample .env | ||
# Fill out `NEW_RELIC_LICENSE_KEY` in .env and save | ||
# Start the application | ||
npm start | ||
npm run client | ||
``` | ||
|
||
## Exploring Telemetry | ||
After running both the server and client, navigate to your application in APM & Services. Locate the 'Example Start Web Transaction App' service and then select Transactions on the left-side of the screen. You should see your requests in a few minutes in a similar fashion to below. | ||
|
||
![transactions](./images/transactions.png) | ||
|
||
To see a breakdown of a transaction, navigate to `Distributed Tracing`. Open a trace group for `/websocket/new-message`. You should see the custom segment as well as a full breakdown of the trace. | ||
|
||
![distributed-trace](./images/dt.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const io = require('socket.io-client') | ||
|
||
const socket = io.connect('http://localhost:3000', { reconnect: true }) | ||
let responses = 0 | ||
|
||
socket.on('pong', () => { | ||
responses += 1 | ||
console.log('ping pong success') | ||
}) | ||
|
||
socket.on('message-received', (data) => { | ||
responses += 1 | ||
console.log(`message received: ${JSON.stringify(data)}`) | ||
}) | ||
|
||
socket.on('update-done', (data) => { | ||
responses += 1 | ||
console.log(`update received: ${JSON.stringify(data)}`) | ||
}) | ||
|
||
socket.emit('ping') | ||
|
||
for (let i = 1; i < 21; i++) { | ||
socket.emit('update', { name: `Message ${i}`, msg: 'Hello world' }) | ||
socket.emit('new-message', `this is message ${i}`) | ||
} | ||
|
||
setInterval(() => { | ||
if (responses === 41) { | ||
console.log('done processing events from server') | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(0) | ||
} | ||
}, 500) |
Oops, something went wrong.