Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added examples of recordMetric and incrementMetric #289

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions custom-instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This folder contains example applications using the [Agent API](https://newrelic
* [instrumentDatastore](./instrument-datastore) - example application that uses the [newrelic.instrumentDatastore API](https://newrelic.github.io/node-newrelic/API.html#instrumentDatastore) and [datastore shim API](https://newrelic.github.io/node-newrelic/DatastoreShim.html) to instrument a toy datastore called Simple Datastore
* [instrumentWebframework](./instrument-webframework) - example application that uses the [newrelic.instrumentWebframework API](https://newrelic.github.io/node-newrelic/API.html#instrumentWebframework) and associated [WebFramework shim API](https://newrelic.github.io/node-newrelic/WebFrameworkShim.html) to instrument a hypothetical web framework
* [instrumentMessages](./instrument-messages) - example application that uses the [newrelic.instrumentMessages API](https://newrelic.github.io/node-newrelic/API.html#instrumentMessages) and associated [messaging shim API](https://newrelic.github.io/node-newrelic/MessageShim.html) to instrument a toy messaging library called Nifty Messages
* [attributesAndEvents](./attributes-and-events) - example application that demonstrates how to share custom [attributes](https://newrelic.github.io/node-newrelic/API.html#addCustomAttribute) and [events](https://newrelic.github.io/node-newrelic/API.html#recordCustomEvent)
* [backgroundTransactions](./background-transactions) - example application that uses the newrelic API to create [background transactions](https://newrelic.github.io/node-newrelic/API.html#startBackgroundTransaction)
* [segments](./segments) - example application that demonstrates how to use the [newrelic.startSegment API](https://newrelic.github.io/node-newrelic/API.html#startSegment) in a variety of cases: callback-based, promise-based, asyncronously, and syncronously
* [distributed tracing](./distributed-tracing/) - example application that demonstrates distributed tracing
* [Attributes, Events, and Metrics](./attributes-events-metrics) - example application that demonstrates how to create custom [attributes](https://newrelic.github.io/node-newrelic/API.html#addCustomAttribute), [events](https://newrelic.github.io/node-newrelic/API.html#recordCustomEvent), and [metrics](https://newrelic.github.io/node-newrelic/API.html#recordMetric).
* [Background Transactions](./background-transactions) - example application that uses the newrelic API to create [background transactions](https://newrelic.github.io/node-newrelic/API.html#startBackgroundTransaction)
* [Segments](./segments) - example application that demonstrates how to use the [newrelic.startSegment API](https://newrelic.github.io/node-newrelic/API.html#startSegment) in a variety of cases: callback-based, promise-based, asyncronously, and syncronously
* [Distributed tracing](./distributed-tracing/) - example application that demonstrates distributed tracing

## Purpose of Instrumentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,45 @@ This example provides an application to demonstrate how to share custom attribut
# Start the application
npm start
```
4. Make requests to the application. Route names include: 'custom-attribute', 'custom-attributes', 'custom-span-attribute', 'custom-span-attributes', and 'custom-event'.
4. Make requests to the application. Route names include: 'custom-attribute', 'custom-attributes', 'custom-span-attribute', 'custom-span-attributes', 'custom-event', and `custom-metric`.
```
curl -X POST http://localhost:3000/custom-attribute
```

## Exploring Telemetry

After sending a few requests, navigate to your application in APM & Services. Locate the 'Example Attributes & Events 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.
After sending a few requests, navigate to your application in APM & Services. Locate the 'Example Attributes, Events & Metrics 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.

![1721149128373](./image/README/1721149128373.png)

### Find your custom attributes

Select 'Distirbuted tracing' on the left side of your screen. Then, select a trace group with your custom attribute and select a single trace. If you expand the transaction, you should see 'Nodejs/ ... //custom-attriibute'. Select 'Attributes' on the right side of your screen; scroll down the list of attributes to find your custom attribute. Notice 'hello: world' in the below example.
Select 'Distributed tracing' on the left side of your screen. Then, select a trace group with your custom attribute and select a single trace. If you expand the transaction, you should see 'Nodejs/ ... //custom-attribute'. Select 'Attributes' on the right side of your screen; scroll down the list of attributes to find your custom attribute. Notice 'hello: world' in the below example.

![1721149619968](./image/README/1721149619968.png)

### Find your custom event

Navigate to 'Query Your Data' in New Relic. Enter the following query. You should now see information about your custom event(s).

```NRQL
```SQL
FROM `my_app:my_event` SELECT *
```

![1721149915594](./image/README/1721149915594.png)

### Find your custom metrics

Navigate to 'Query Your Data' in New Relic. Enter the following query. You should now see information about your custom event(s).

```SQL
SELECT count(newrelic.timeslice.value)
FROM Metric
WHERE metricTimesliceName like 'Custom/%'
AND entity.guid = '<guid>'
FACET metricTimesliceName
SINCE 30 MINUTES AGO TIMESERIES
```

![metrics-query](./image/README/metrics-query.png)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ fastify.post('/custom-event', async (request, reply) => {
return reply.send({ status: 'Custom event recorded' });
});

fastify.post('/custom-metric', async (request, reply) => {
newrelic.incrementMetric('TestMetric')
newrelic.recordMetric('MyTestMetric', 100)
newrelic.recordMetric('MyComplexTestMetric', {
count: 1,
total: 2,
min: 1,
max: 2,
sumOfSquares: 4,
callCount: 1
})
newrelic.incrementMetric('TestMetric')
return reply.send({ status: 'Custom metric recorded' });
});

//Start the server
const start = async () => {
try {
Expand All @@ -48,4 +63,5 @@ const start = async () => {
}
};

start();
start();

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* description of configuration variables and their potential values.
*/
exports.config = {
app_name: ['Example Attributes & Events App'],
app_name: ['Example Attributes, Events & Metrics App'],
logging: {
/**
* Level at which to log. 'trace' is most useful to New Relic when diagnosing
Expand Down
Loading