Skip to content

Commit 1963555

Browse files
authored
add docs for new relic logging and metrics (#536)
1 parent 9387a3e commit 1963555

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: New Relic Plugin
3+
sidebar_label: New Relic Logging
4+
---
5+
6+
The New Relic Log plugin enables pushing logs to New Relic.
7+
8+
<EnterpriseFeature name="Custom logging" />
9+
10+
## Setup
11+
12+
To add the New Relic logging plugin to your Zuplo project, add the following
13+
code to your `zuplo.runtime.ts` file. Set the `url` parameter (optional) to the
14+
value of your New Relic log API endpoint and the `NEW_RELIC_API_KEY` environment
15+
variable to your New Relic API key.
16+
17+
Any custom fields you want to include in the log entry can be added to the
18+
`fields` property. These values will be appended to every log entry.
19+
20+
```ts title="modules/zuplo.runtime.ts"
21+
import {
22+
RuntimeExtensions,
23+
NewRelicLoggingPlugin,
24+
environment,
25+
} from "@zuplo/runtime";
26+
27+
export function runtimeInit(runtime: RuntimeExtensions) {
28+
runtime.addPlugin(
29+
new NewRelicLoggingPlugin({
30+
// Optional, defaults to "https://log-api.newrelic.com/log/v1"
31+
url: "https://log-api.newrelic.com/log/v1",
32+
apiKey: environment.NEW_RELIC_API_KEY,
33+
service: "MyAPI", // Optional, defaults to "Zuplo"
34+
fields: {
35+
field1: "value1",
36+
field2: "value2",
37+
},
38+
}),
39+
);
40+
}
41+
```
42+
43+
## Standard Fields
44+
45+
Every log entry will include the following fields:
46+
47+
- `message` - The log message and data
48+
- `level` - The level of the log, for example `error`, `info`, etc.
49+
- `timestamp` - The time the log was created (in milliseconds since epoch)
50+
- `service` - The name of the service (defaults to "Zuplo" or custom value
51+
provided)
52+
- `environment` - The deployment name of the Zuplo API
53+
- `environment_type` - Where the Zuplo API is running. Values are `edge`,
54+
`working-copy`, or `local`
55+
- `environment_stage` - If the environment is `working-copy`, `preview`, or
56+
`production`
57+
- `request_id` - The UUID of the request (the value of the `zp-rid` header)
58+
- `atomic_counter` - An atomic number that's used to order logs that have the
59+
same timestamp
60+
- `ray_id` - The network provider identifier (i.e. Cloudflare RayID) of the
61+
request
62+
- `log_source` - The source of the log entry

docs/articles/logging.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ instructions on how to configure logging, see the documentation for each plugin:
1818
- [AWS CloudWatch](./log-plugin-aws-cloudwatch.md)
1919
- [DataDog](./log-plugin-datadog.md)
2020
- [Dynatrace](./log-plugin-dynatrace.md)
21+
- [New Relic](./log-plugin-new-relic.md)
2122
- [Google Cloud Logging](./log-plugin-gcp.md)
2223
- [Loki](./log-plugin-loki.md)
2324
- [Sumo Logic](./log-plugin-sumo.md)

docs/articles/metrics-plugins.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Zuplo supports logging to the following sources:
1010

1111
- DataDog (Beta)
1212
- Dynatrace (Beta)
13+
- New Relic (Beta)
1314

1415
If you would like to log to a different source, reach out to [email protected]
1516
and we'd be happy to work with you to add a new logging plugin.
@@ -201,3 +202,68 @@ export default async function (request: ZuploRequest, context: ZuploContext) {
201202
return "What zup?";
202203
}
203204
```
205+
206+
### New Relic (Beta)
207+
208+
By default, we send all metrics to New Relic. However, you have the option below
209+
to configure which metrics you want to send.
210+
211+
New Relic's Metric API provides a powerful way to monitor your API's performance. The metrics are sent to New Relic's Metric API endpoint (https://metric-api.newrelic.com/metric/v1) by default, but you can customize this if needed.
212+
213+
```ts
214+
import {
215+
RuntimeExtensions,
216+
NewRelicMetricsPlugin,
217+
environment,
218+
} from "@zuplo/runtime";
219+
220+
export function runtimeInit(runtime: RuntimeExtensions) {
221+
runtime.addPlugin(
222+
new NewRelicMetricsPlugin({
223+
apiKey: environment.NEW_RELIC_API_KEY,
224+
// Optional: customize the URL if needed
225+
// url: "https://metric-api.newrelic.com/metric/v1",
226+
// You can add custom attributes to all metrics
227+
attributes: {
228+
service: "my-service-name",
229+
environment: environment.ENVIRONMENT ?? "DEVELOPMENT",
230+
},
231+
metrics: {
232+
latency: true,
233+
requestContentLength: true,
234+
responseContentLength: true,
235+
},
236+
// You can also choose to add additional attributes to include in the metrics
237+
include: {
238+
country: false,
239+
httpMethod: false,
240+
statusCode: false,
241+
path: false,
242+
},
243+
}),
244+
);
245+
}
246+
```
247+
248+
The above configuration applies globally for all metrics sent to New Relic. If you
249+
wish to dynamically configure information for a particular ZuploContext, you can
250+
use the `NewRelicMetricsPlugin` in your code. Currently, the only configuration
251+
you can set is the attributes. The values you set here will be appended to those set
252+
globally in the `zuplo.runtime.ts` file.
253+
254+
```ts
255+
import {
256+
ZuploContext,
257+
ZuploRequest,
258+
NewRelicMetricsPlugin,
259+
} from "@zuplo/runtime";
260+
261+
export default async function (request: ZuploRequest, context: ZuploContext) {
262+
const someValue = "hello";
263+
NewRelicMetricsPlugin.setContext(context, {
264+
attributes: { "my-custom-attribute": someValue },
265+
});
266+
267+
return "What zup?";
268+
}
269+
```

sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const docs: SidebarEntry = [
8181
"articles/log-plugin-aws-cloudwatch",
8282
"articles/log-plugin-datadog",
8383
"articles/log-plugin-dynatrace",
84+
"articles/log-plugin-new-relic",
8485
"articles/log-plugin-sumo",
8586
"articles/custom-logging-example",
8687
"articles/log-export",

0 commit comments

Comments
 (0)