-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.js
67 lines (57 loc) · 1.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const newrelic = require('newrelic')
const fastify = require('fastify')({ logger: true })
const { PORT: port = 3000, HOST: host = '127.0.0.1' } = process.env
//Define routes for each type of transaction and event
fastify.post('/custom-attribute', async (request, reply) => {
newrelic.addCustomAttribute('hello', 'world');
return reply.send({ status: 'Custom attribute recorded' });
});
fastify.post('/custom-attributes', async (request, reply) => {
newrelic.addCustomAttributes({ hello: 'world' });
return reply.send({ status: 'Custom attributes recorded' });
});
fastify.post('/custom-span-attribute', async (request, reply) => {
newrelic.addCustomSpanAttribute('hello', 'world');
return reply.send({ status: 'Custom span attribute recorded' });
});
fastify.post('/custom-span-attributes', async (request, reply) => {
newrelic.addCustomSpanAttributes({ hello: 'world' });
return reply.send({ status: 'Custom span attributes recorded' });
});
fastify.post('/custom-event', async (request, reply) => {
newrelic.recordCustomEvent('my_app:my_event', {
custom: 'properties',
n: 1,
ok: true
});
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 {
await fastify.listen({ port: port, host: host });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();