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

Escape pipes in tags sent to datadog #1

Merged
merged 3 commits into from
Nov 2, 2017

Conversation

colin-alexa
Copy link

@colin-alexa colin-alexa commented Nov 2, 2017

datadog uses pipe characters ("|") to delimit different portions of information in log messages. Unescaped pipes in tag text can cause parsing errors (see AppPress#6)

Escape pipes using regular str.replace

Colin-Alexa Robinson added 2 commits November 1, 2017 13:41
datadog splits data from type annotations using a '|' character.
Node/express allows pipe characters in routes (regexes). To avoid
errors, escape pipe characters before sending statsd data
lib/index.js Outdated
@@ -9,6 +9,10 @@ module.exports = function (options) {
let base_url = options.base_url || false;
let response_code = options.response_code || false;

function escapePipes(str) {
return str.replace(/\|/g, "\\|");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this might get call for every single request, let's declare the regex outside of the function. What do you think? (it is a small performance suggestion).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also to be super safe, let's make sure str does exist str && str.replace(pattern, '\\|');

@colin-alexa colin-alexa merged commit 965c32b into CondeNast:master Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants