Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
v11.3.1; default to sending activation_method field if APM server v…
Browse files Browse the repository at this point in the history
…ersion is not (yet) known (#198)

Optimistically assume the APM server version is not v8.7.0. This allows
typically avoiding the v8.7.0 bug (which isn't that severe) with still
sending the `activation_method` for intake requests before the APM
server version fetch completes -- e.g. for fast first serverless
invocations.

Refs: elastic/apm#781
  • Loading branch information
trentm authored Apr 3, 2023
1 parent 75b2006 commit 4f03ca7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# elastic-apm-http-client changelog

## v11.3.1

- Tweak logic to only exclude `metadata.service.agent.activation_method` when
the APM server version is known to be 8.7.0 -- i.e. optimistically assume
it is a version that is fine. The APM server 8.7.0 issue isn't so severe that
we want a fast first serverless function invocation to not send the field.
(https://github.com/elastic/apm/pull/783)

## v11.3.0

- Ensure `metadata.service.agent.activation_method` is only sent for APM
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ or the version could not be fetched.

This method returns a boolean indicating whether the remote APM Server (per
the configured `serverUrl`) is of a version that supports the
`metadata.service.agent.activation_method` field.

This defaults to `false` if the remote APM server version is not known.
`metadata.service.agent.activation_method` field. This is true for APM server
versions >=8.7.1. It defaults to true if the APM server version is not (yet)
known.

### `client.addMetadataFilter(fn)`

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,10 +1138,10 @@ Client.prototype.supportsKeepingUnsampledTransaction = function () {
}
}
Client.prototype.supportsActivationMethodField = function () {
// APM server 8.7.0 had a bug where sending `activation_method` is *harmful*,
// therefore, if we don't *know* we are >=8.7.1, then assume no.
// APM server 8.7.0 had a bug where continuing to send `activation_method` is
// harmful.
if (!this._apmServerVersion) {
return false
return true // Optimistically assume APM server isn't v8.7.0.
} else {
return semver.gte(this._apmServerVersion, '8.7.1')
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elastic-apm-http-client",
"version": "11.3.0",
"version": "11.3.1",
"description": "A low-level HTTP client for communicating with the Elastic APM intake API",
"main": "index.js",
"directories": {
Expand Down
20 changes: 10 additions & 10 deletions test/apm-server-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ test('APM server version fetch works for "6.6.0"', function (t) {
'client._apmServerVersion is undefined immediately after client creation')
t.equal(client.supportsKeepingUnsampledTransaction(), true,
'client.supportsKeepingUnsampledTransaction() defaults to true before fetch')
t.equal(client.supportsActivationMethodField(), false,
'client.supportsActivationMethodField() defaults to false before fetch')
t.equal(client.supportsActivationMethodField(), true,
'client.supportsActivationMethodField() defaults to true before fetch')

// Currently there isn't a mechanism to wait for the fetch request, so for
// now just wait a bit.
Expand Down Expand Up @@ -149,10 +149,10 @@ test('APM server version fetch works for "8.7.0"', function (t) {
t.strictEqual(client._apmServerVersion, undefined,
'client._apmServerVersion is undefined immediately after client creation')
t.equal(client._conf.agentActivationMethod, 'env-attach', '_conf.agentActivationMethod')
t.equal(client.supportsActivationMethodField(), false,
'client.supportsActivationMethodField() defaults to false before fetch')
t.equal(JSON.parse(client._encodedMetadata).metadata.service.agent.activation_method, undefined,
'metadata does not include "activation_method" before fetch')
t.equal(client.supportsActivationMethodField(), true,
'client.supportsActivationMethodField() defaults to true before fetch')
t.ok('activation_method' in JSON.parse(client._encodedMetadata).metadata.service.agent,
'metadata includes "activation_method" before fetch')

// Currently there isn't a mechanism to wait for the fetch request, so for
// now just wait a bit.
Expand Down Expand Up @@ -190,10 +190,10 @@ test('APM server version fetch works for "8.7.1"', function (t) {
t.strictEqual(client._apmServerVersion, undefined,
'client._apmServerVersion is undefined immediately after client creation')
t.equal(client._conf.agentActivationMethod, 'env-attach', '_conf.agentActivationMethod')
t.equal(client.supportsActivationMethodField(), false,
'client.supportsActivationMethodField() defaults to false before fetch')
t.equal(JSON.parse(client._encodedMetadata).metadata.service.agent.activation_method, undefined,
'metadata does not include "activation_method" before fetch')
t.equal(client.supportsActivationMethodField(), true,
'client.supportsActivationMethodField() defaults to true before fetch')
t.ok('activation_method' in JSON.parse(client._encodedMetadata).metadata.service.agent,
'metadata includes "activation_method" before fetch')

// Currently there isn't a mechanism to wait for the fetch request, so for
// now just wait a bit.
Expand Down

0 comments on commit 4f03ca7

Please sign in to comment.