Skip to content

Commit c701da7

Browse files
authoredNov 28, 2023
feat: add 'apmClientHeaders' config option for custom headers in APM server comms (#3760)
Closes: #3759
1 parent f590ef6 commit c701da7

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed
 

‎CHANGELOG.asciidoc

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ See the <<upgrade-to-v4>> guide.
4141
[float]
4242
===== Features
4343
44+
* Add the <<apm-client-headers>> config option, to allow adding custom headers
45+
to HTTP requests made to APM server by the APM agent. ({issues}3759[#3759])
46+
4447
[float]
4548
===== Bug fixes
4649

‎docs/configuration.asciidoc

+26
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,32 @@ option. That will likely result in healthy requests being aborted prematurely.
942942
The value should include a time suffix ('m' for minutes, 's' for seconds, or
943943
'ms' for milliseconds), but defaults to seconds if no suffix is given.
944944

945+
[[apm-client-headers]]
946+
==== `apmClientHeaders`
947+
948+
[small]#Added in: REPLACEME#
949+
950+
* *Type:* Object
951+
* *Env:* `ELASTIC_APM_APM_CLIENT_HEADERS`
952+
953+
Specify custom headers to be included in HTTP requests by the APM agent to
954+
APM Server. Generally this should not be required for normal usage.
955+
956+
Examples:
957+
958+
[source,bash]
959+
----
960+
ELASTIC_APM_APM_CLIENT_HEADERS="foo=bar,spam=eggs"
961+
----
962+
963+
[source,js]
964+
----
965+
require('elastic-apm-node').start({
966+
apmClientHeaders: { foo: 'bar', spam: 'eggs' },
967+
// ...
968+
})
969+
----
970+
945971

946972
[[sanitize-field-names]]
947973
==== `sanitizeFieldNames`

‎examples/trace-http-request.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ function makeARequest(url, opts, cb) {
4545
// an HTTP server, we manually start a transaction. More details at:
4646
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
4747
const t0 = apm.startTransaction('t0');
48-
makeARequest(
49-
'http://httpstat.us/200',
50-
{ headers: { accept: '*/*' } },
51-
function () {
52-
t0.end();
53-
},
54-
);
48+
makeARequest('http://google.com/', { headers: { accept: '*/*' } }, function () {
49+
t0.end();
50+
});

‎lib/apm-client/apm-client.js

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function getHttpClientConfig(conf, agent) {
166166
serverCaCert: loadServerCaCertFile(conf.serverCaCertFile),
167167
rejectUnauthorized: conf.verifyServerCert,
168168
serverTimeout: conf.serverTimeout * 1000,
169+
headers: maybePairsToObject(conf.apmClientHeaders),
169170

170171
// APM Agent Configuration via Kibana:
171172
centralConfig: conf.centralConfig,

‎lib/config/schema.js

+6
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ const CONFIG_SCHEMA = [
590590
defaultValue: [],
591591
deps: ['ignoreUserAgents'],
592592
},
593+
{
594+
name: 'apmClientHeaders',
595+
configType: 'stringKeyValuePairs',
596+
defaultValue: undefined,
597+
envVar: 'ELASTIC_APM_APM_CLIENT_HEADERS',
598+
},
593599
// Special options that
594600
// - may afect the whole config
595601
// - change the behavior of thelogger

0 commit comments

Comments
 (0)
Please sign in to comment.