Skip to content

Commit

Permalink
feat: Add serverUrlPrefix unit tests and documentation
Browse files Browse the repository at this point in the history
* add serverUrlPrefix documentation to configuration.asciidoc
* add unittest 'should update serverUrlPrefix'

fixes issue elastic#1078
  • Loading branch information
alexbode committed Sep 29, 2021
1 parent af7c310 commit 109681b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ Your Elastic APM service name.

The URL used to make requests to the APM Server.

[float]
[[server-prefix-url]]
=== `serverPrefixUrl`

* *Type:* String
* *Default* `/intake/v${apiVersion}/rum/events`

The server prefix url used to make requests to the APM Server. Some ad blockers block outgoing requests
from the browser if the default server prefix url is being used. Using a custom server prefix url can be used to
evade the ad blocker.

NOTE: If the default server prefix url is overwritten, the reverse proxy that sits between the
APM Server and the rum agent must reroute traffic to `/intake/v${apiVersion}/rum/events`
so the APM Server knows what intake api to use.

[float]
[[service-version]]
=== `serviceVersion`
Expand Down
28 changes: 27 additions & 1 deletion packages/rum-core/test/common/apm-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ describe('ApmServer', function () {
},
language: { name: 'javascript' }
},
labels: { test: 'testlabel' }
labels: {
test: 'testlabel'
}
})

const tr = new Transaction('test-meta-tr', 'test-type', {
Expand Down Expand Up @@ -618,4 +620,28 @@ describe('ApmServer', function () {
testConfig.stackVersion &&
compareVersions(testConfig.stackVersion, '7.10.0') >= 0
)

it('should update serverUrlPrefix', async () => {
const serverUrl = 'http://example.com:1234'
const serverUrlPrefix = '/example/url/prefix'
configService.setConfig({
serviceName: 'test-service',
serverUrlPrefix,
serverUrl
})
const clock = jasmine.clock()
clock.install()
apmServer.init()
spyOn(apmServer, '_postJson')
const trs = generateTransaction(2).map(tr =>
performanceMonitoring.createTransactionDataModel(tr)
)
trs.forEach(apmServer.addTransaction.bind(apmServer))
clock.tick(600)

expect(apmServer._postJson).toHaveBeenCalled()
const finalServerUrl = apmServer._postJson.calls.argsFor(0)[0]
expect(finalServerUrl).toEqual(serverUrl + serverUrlPrefix)
clock.uninstall()
})
})

0 comments on commit 109681b

Please sign in to comment.