This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 'extraMetadata' config option (#192)
This is a way to provide additional metadata that is merged into the metadata object created from the other individual config options. This is similar to `expectExtraMetadata: true` && `setExtraMetadata(...)`, but is a way to provide the metadata *synchronously*. Refs: elastic/apm-agent-nodejs#3071
- Loading branch information
Showing
5 changed files
with
73 additions
and
9 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
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
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,47 @@ | ||
'use strict' | ||
|
||
// Test usage of `extraMetadata: ...`. | ||
|
||
const test = require('tape') | ||
const utils = require('./lib/utils') | ||
|
||
const APMServer = utils.APMServer | ||
const processIntakeReq = utils.processIntakeReq | ||
|
||
test('extraMetadata', function (t) { | ||
const apmEvents = [] | ||
const extraMetadata = { | ||
foo: 'bar', | ||
service: { | ||
language: { | ||
name: 'spam' | ||
} | ||
} | ||
} | ||
|
||
const server = APMServer(function (req, res) { | ||
const objStream = processIntakeReq(req) | ||
objStream.on('data', function (obj) { | ||
apmEvents.push(obj) | ||
}) | ||
objStream.on('end', function () { | ||
res.statusCode = 202 | ||
res.end() | ||
}) | ||
}).client({ extraMetadata, apmServerVersion: '8.0.0' }, function (client) { | ||
client.sendTransaction({ req: 1 }) | ||
|
||
client.flush(() => { | ||
t.equal(apmEvents.length, 2, 'APM Server got 2 events') | ||
t.ok(apmEvents[0].metadata, 'event 0 is metadata') | ||
t.equal(apmEvents[0].metadata.foo, 'bar', 'extraMetadata added "foo" field') | ||
t.equal(apmEvents[0].metadata.service.language.name, 'spam', | ||
'extraMetadata overrode nested service.language.name field properly') | ||
t.ok(apmEvents[1].transaction, 'event 1 is a transaction') | ||
|
||
client.end() | ||
server.close() | ||
t.end() | ||
}) | ||
}) | ||
}) |