pino-datadog
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -45,1 +45,19 @@ # API | ||
The number of log messages to send as a single batch (defaults to 1). | ||
#### ddsource | ||
Type: `String` *(optional)* | ||
Set a default source to all the logs sent to datadog | ||
#### service | ||
Type: `String` *(optional)* | ||
Set a default service to all the logs sent to datadog | ||
#### hostname | ||
Type: `String` *(optional)* | ||
Set a default hostname to all the logs sent to datadog |
@@ -19,11 +19,15 @@ # CLI | ||
You can pass the following options via cli arguments: | ||
You can pass the following options via cli arguments or use the environment variable associated: | ||
| Short command | Full command | Description | | ||
| Short command | Full command | Environment variable | Description | | ||
| ------------- | ------------ |-------------| | ||
| -V | --version | Output the version number | | ||
| -k | --key <apikey> | The API key that can be found in your DataDog account | | ||
| -b | --batch <size> | The number of log messages to send as a single batch (defaults to 1) | | ||
| -h | --help | Output usage information | | ||
| -V | --version | | Output the version number | | ||
| -k | --key <apikey> | DD_API_KEY | The API key that can be found in your DataDog account | | ||
| -d | --ddsource <source> | DD_SOURCE | Default source for the logs | | ||
| -s, --service <service> | DD_SERVICE | Default service for the logs | | ||
| | --hostname <hostname> | DD_HOSTNAME | Default hostname for the logs | | ||
| -e | --eu | DD_EU | Use Datadog EU site | | ||
| -b | --batch <size> | | The number of log messages to send as a single batch (defaults to 1) | | ||
| -h | --help | | Output usage information | | ||
See the [API](./API.md) documentation for details. |
{ | ||
"name": "pino-datadog", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "A transport for pino that sends messages to DataDog", | ||
@@ -13,3 +13,4 @@ "homepage": "https://github.com/ovhemert/pino-datadog", | ||
"posttest": "tap --coverage --coverage-report=lcovonly", | ||
"snyk-protect": "snyk protect" | ||
"snyk-protect": "snyk protect", | ||
"prepare": "npm run snyk-protect" | ||
}, | ||
@@ -39,14 +40,14 @@ "bin": { | ||
"devDependencies": { | ||
"pino-multi-stream": "^4.1.0", | ||
"sinon": "^7.4.0", | ||
"standard": "^13.1.0", | ||
"tap": "^14.6.1" | ||
"pino-multi-stream": "^4.2.0", | ||
"sinon": "^7.5.0", | ||
"standard": "^14.3.1", | ||
"tap": "^14.9.1" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.19.0", | ||
"batch2": "^1.0.5", | ||
"commander": "^2.20.0", | ||
"batch2": "^1.0.6", | ||
"commander": "^3.0.2", | ||
"fast-json-parse": "^1.0.3", | ||
"pumpify": "^2.0.0", | ||
"snyk": "^1.208.0", | ||
"pumpify": "^2.0.1", | ||
"snyk": "^1.240.2", | ||
"split2": "^3.1.1", | ||
@@ -53,0 +54,0 @@ "stream": "0.0.2", |
@@ -13,8 +13,18 @@ #!/usr/bin/env node | ||
.option('-k, --key <key>', 'DataDog API Key') | ||
.action(async ({ key }) => { | ||
.option('-d, --ddsource <source>', 'Default source for the logs') | ||
.option('-s, --service <service>', 'Default service for the logs') | ||
.option('--hostname <hostname>', 'Default hostname for the logs') | ||
.option('-e, --eu', 'Use Datadog EU site') | ||
.action(async options => { | ||
try { | ||
const apiKey = key || process.env.DD_API_KEY | ||
const writeStream = await pinoDataDog.createWriteStream({ apiKey }) | ||
const config = { | ||
apiKey: options.key || process.env.DD_API_KEY, | ||
ddsource: options.ddsource || process.env.DD_SOURCE, | ||
service: options.service || process.env.DD_SERVICE, | ||
hostname: options.hostname || process.env.DD_HOSTNAME, | ||
eu: options.eu || !!process.env.DD_EU | ||
} | ||
const writeStream = await pinoDataDog.createWriteStream(config) | ||
process.stdin.pipe(writeStream) | ||
console.info('logging') | ||
process.stdin.pipe(process.stdout) | ||
} catch (error) { | ||
@@ -21,0 +31,0 @@ console.log(error.message) |
@@ -8,3 +8,3 @@ 'use strict' | ||
constructor (options = {}) { | ||
this._apiKey = options.apiKey | ||
this._options = options | ||
} | ||
@@ -14,9 +14,26 @@ | ||
const data = Array.isArray(items) ? items : [items] | ||
if (data.length <= 0) { return } | ||
if (data.length <= 0) { | ||
return | ||
} | ||
try { | ||
const url = `https://http-intake.logs.datadoghq.com/v1/input/${this._apiKey}` | ||
const result = await axios.post(url, data) | ||
const domain = this._options.eu | ||
? 'https://http-intake.logs.datadoghq.eu' | ||
: 'https://http-intake.logs.datadoghq.com' | ||
const params = {} | ||
if (this._options.ddsource) { | ||
params.ddsource = this._options.ddsource | ||
} | ||
if (this._options.service) { | ||
params.service = this._options.service | ||
} | ||
if (this._options.hostname) { | ||
params.hostname = this._options.hostname | ||
} | ||
const url = `${domain}/v1/input/${this._options.apiKey}` | ||
const result = await axios.post(url, data, { params }) | ||
return result | ||
} catch (err) { | ||
throw Error(err.message) | ||
console.error('The previous log have not been saved') | ||
console.error(`${err.message}\n${err.stack}`) | ||
} | ||
@@ -27,5 +44,13 @@ } | ||
const self = this | ||
const writeStream = new stream.Writable({ objectMode: true, highWaterMark: 1 }) | ||
const writeStream = new stream.Writable({ | ||
objectMode: true, | ||
highWaterMark: 1 | ||
}) | ||
writeStream._write = function (chunk, encoding, callback) { | ||
self.insert(chunk).then(() => { callback(null) }).catch(callback) | ||
self | ||
.insert(chunk) | ||
.then(() => { | ||
callback(null) | ||
}) | ||
.catch(callback) | ||
} | ||
@@ -32,0 +57,0 @@ return writeStream |
@@ -9,8 +9,2 @@ 'use strict' | ||
test('creates client', t => { | ||
const client = new tested.Client({ apiKey: '1234567890' }) | ||
t.equals(client._apiKey, '1234567890') | ||
t.end() | ||
}) | ||
test('calls insert without document', t => { | ||
@@ -24,3 +18,3 @@ const client = new tested.Client() | ||
test('errors on failed insert', async t => { | ||
test('does not error on invalid insert', async t => { | ||
const client = new tested.Client() | ||
@@ -30,3 +24,3 @@ const stubPost = sinon.stub(axios, 'post').rejects() | ||
try { | ||
await t.rejects(insert) | ||
await t.resolves(insert) | ||
} finally { | ||
@@ -52,10 +46,16 @@ stubPost.restore() | ||
const stubPost = sinon.stub(axios, 'post').resolvesArg(1) | ||
client.insert([{ message: 'test 1' }, { message: 'test 2' }, { message: 'test 3' }]).then(data => { | ||
t.equals(data.length, 3) | ||
t.equals(data[0].message, 'test 1') | ||
t.equals(data[1].message, 'test 2') | ||
t.equals(data[2].message, 'test 3') | ||
stubPost.restore() | ||
t.end() | ||
}) | ||
client | ||
.insert([ | ||
{ message: 'test 1' }, | ||
{ message: 'test 2' }, | ||
{ message: 'test 3' } | ||
]) | ||
.then(data => { | ||
t.equals(data.length, 3) | ||
t.equals(data[0].message, 'test 1') | ||
t.equals(data[1].message, 'test 2') | ||
t.equals(data[2].message, 'test 3') | ||
stubPost.restore() | ||
t.end() | ||
}) | ||
}) | ||
@@ -70,3 +70,69 @@ | ||
t.ok(stubPost.called) | ||
stubPost.restore() | ||
t.end() | ||
}) | ||
test('inserts sends com url and api key', async t => { | ||
const client = new tested.Client({ apiKey: '1234567890' }) | ||
const stubPost = sinon.stub(axios, 'post') | ||
const items = [{ message: 'hello world !' }] | ||
await client.insert(items) | ||
t.ok(stubPost.called) | ||
t.ok( | ||
stubPost.calledWithMatch( | ||
'https://http-intake.logs.datadoghq.com/v1/input/1234567890', | ||
items, | ||
{ params: {} } | ||
) | ||
) | ||
stubPost.restore() | ||
t.end() | ||
}) | ||
test('inserts sends eu url and api key', async t => { | ||
const client = new tested.Client({ apiKey: '1234567890', eu: true }) | ||
const stubPost = sinon.stub(axios, 'post') | ||
const items = [{ message: 'hello world !' }] | ||
await client.insert(items) | ||
t.ok(stubPost.called) | ||
t.ok( | ||
stubPost.calledWithMatch( | ||
'https://http-intake.logs.datadoghq.eu/v1/input/1234567890', | ||
items, | ||
{ params: {} } | ||
) | ||
) | ||
stubPost.restore() | ||
t.end() | ||
}) | ||
test('inserts sends extra parameters ', async t => { | ||
const client = new tested.Client({ | ||
apiKey: '1234567890', | ||
ddsource: 'source', | ||
service: 'service', | ||
hostname: 'foobar.com' | ||
}) | ||
const stubPost = sinon.stub(axios, 'post') | ||
const items = [{ message: 'hello world !' }] | ||
await client.insert(items) | ||
t.ok(stubPost.called) | ||
t.ok( | ||
stubPost.calledWithMatch( | ||
'https://http-intake.logs.datadoghq.com/v1/input/1234567890', | ||
items, | ||
{ | ||
params: { | ||
ddsource: 'source', | ||
service: 'service', | ||
hostname: 'foobar.com' | ||
} | ||
} | ||
) | ||
) | ||
stubPost.restore() | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30693
372
6
+ Addedcommander@3.0.2(transitive)
- Removedcommander@2.20.3(transitive)
Updatedbatch2@^1.0.6
Updatedcommander@^3.0.2
Updatedpumpify@^2.0.1
Updatedsnyk@^1.240.2