-
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.
chore: Added url obfuscation example (#292)
- Loading branch information
Showing
8 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Sample URL Obfuscation Application | ||
|
||
This example provides an application that applies a url obfuscation rule to scrub email adddresses from external http calls using `fetch`. | ||
|
||
## Getting Started | ||
|
||
1. Clone or fork this repository. | ||
2. Navigate to this example's sub directory | ||
``` | ||
cd newrelic-node-examples/custom-instrumentation/url-obfuscation | ||
``` | ||
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 | ||
``` | ||
4. The application will make a call to `https://httpbin.org/anything/[email protected]` | ||
5. It will apply the url obfuscation rules from newrelic.js | ||
|
||
```js | ||
url_obfuscation: { | ||
enabled: true, | ||
regex: { | ||
pattern: '[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}', | ||
replacement: '***' | ||
} | ||
} | ||
``` | ||
|
||
6. This will obfuscate the email address from both the span name and the `http.url` span attribute. | ||
|
||
This shows the span name obfuscates the email from the span name: | ||
|
||
![span-name](./images/span-name.png) | ||
|
||
|
||
This shows the `http.url` span attribute obfuscates the email: | ||
|
||
![span-attr](./images/span-attr.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 @@ | ||
NEW_RELIC_LICENSE_KEY= |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
'use strict' | ||
const newrelic = require('newrelic') | ||
|
||
|
||
async function main() { | ||
await newrelic.startBackgroundTransaction('bg-tx', async() => { | ||
const { status } = await fetch('https://httpbin.org/anything/[email protected]') | ||
console.log(`Done making request, status code: ${status}`) | ||
}) | ||
newrelic.shutdown({ collectPendingData: true }, () => process.exit(0)) | ||
} | ||
|
||
main() |
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,59 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
/** | ||
* New Relic agent configuration. | ||
* | ||
* See lib/config/default.js in the agent distribution for a more complete | ||
* description of configuration variables and their potential values. */ | ||
|
||
exports.config = { | ||
app_name: ['Example Url Obfuscation App'], | ||
logging: { | ||
/** | ||
* Level at which to log. 'trace' is most useful to New Relic when diagnosing | ||
* issues with the agent, 'info' and higher will impose the least overhead on | ||
* production applications. | ||
*/ | ||
level: 'trace' | ||
}, | ||
/** | ||
* When true, all request headers except for those listed in attributes.exclude | ||
* will be captured for all traces, unless otherwise specified in a destination's | ||
* attributes include/exclude lists. | ||
*/ | ||
url_obfuscation: { | ||
enabled: true, | ||
regex: { | ||
pattern: '[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}', | ||
replacement: '***' | ||
} | ||
}, | ||
allow_all_headers: true, | ||
attributes: { | ||
/** | ||
* Prefix of attributes to exclude from all destinations. Allows * as wildcard | ||
* at end. | ||
* | ||
* NOTE: If excluding headers, they must be in camelCase form to be filtered. | ||
* | ||
* @env NEW_RELIC_ATTRIBUTES_EXCLUDE | ||
*/ | ||
exclude: [ | ||
'request.headers.cookie', | ||
'request.headers.authorization', | ||
'request.headers.proxyAuthorization', | ||
'request.headers.setCookie*', | ||
'request.headers.x*', | ||
'response.headers.cookie', | ||
'response.headers.authorization', | ||
'response.headers.proxyAuthorization', | ||
'response.headers.setCookie*', | ||
'response.headers.x*' | ||
] | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"name": "url-obfuscation", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node -r newrelic --env-file .env index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"dependencies": { | ||
"newrelic": "^12.3.0" | ||
} | ||
} |