Skip to content

Commit 92d1d56

Browse files
committed
docs(evp-proxy): explain receiver discovery
1 parent 6bf1846 commit 92d1d56

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

packages/dd-trace/src/evp_proxy/discovery.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
'use strict'
22

33
const { fetchAgentInfo } = require('../agent/info')
4+
const log = require('../log')
45

56
const TRAILING_SLASHES = /\/+$/
67

8+
/**
9+
* Receiver discovery contract
10+
*
11+
* The tracer sends `GET /info` to its configured local Agent URL. An
12+
* Agent-compatible trace receiver produces the response. The tracer does not.
13+
*
14+
* The full Agent and serverless-init embed the same trace receiver. A future
15+
* in-process receiver can expose the same contract. Callers can therefore
16+
* select capabilities without detecting the receiver implementation.
17+
*
18+
* For EVP discovery, `endpoints` advertises registered proxy paths.
19+
* `evp_proxy_allowed_headers` advertises headers that the proxy forwards to
20+
* intake. It does not include routing headers that the proxy consumes, such as
21+
* `X-Datadog-EVP-Subdomain`.
22+
*
23+
* An advertised route is not a health check. The receiver can register an EVP
24+
* route while configuration disables its handler. The request then returns
25+
* `405`. The `/info` version also identifies the embedded Agent code, not a
26+
* serverless-init image or deployment type.
27+
*
28+
* This module only discovers a candidate route. A missing or unresponsive
29+
* `/info` endpoint returns an error through the shared request timeout and
30+
* retry policy. A valid response without a compatible path returns no route.
31+
* Discovery sends no events, so the caller can safely select direct intake
32+
* after either result. The caller also owns later delivery failures. It can
33+
* switch future batches after an ambiguous timeout or reset, but it must not
34+
* replay the current batch because the first receiver might have accepted it.
35+
*
36+
* Reference implementations:
37+
*
38+
* Agent `/info` and EVP proxy:
39+
* https://github.com/DataDog/datadog-agent/tree/main/pkg/trace/api
40+
*
41+
* serverless-init entry point and embedded trace receiver:
42+
* https://github.com/DataDog/datadog-agent/blob/main/cmd/serverless-init/main.go
43+
* https://github.com/DataDog/datadog-agent/blob/main/pkg/serverless/trace/trace.go
44+
*/
45+
746
/**
847
* Selects the first advertised EVP proxy path that the caller supports.
948
*
@@ -82,6 +121,7 @@ function discoverEVPProxy (url, options, callback) {
82121
return
83122
}
84123

124+
log.debug('EVP proxy route %s discovered through the configured local receiver', basePath)
85125
callback(null, { url, basePath })
86126
})
87127
}

packages/dd-trace/test/evp_proxy/discovery.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ describe('EVP proxy discovery', () => {
1515

1616
let discoverEVPProxy
1717
let fetchAgentInfo
18+
let log
1819
let selectEVPProxyPath
1920

2021
beforeEach(() => {
2122
fetchAgentInfo = sinon.stub()
23+
log = { debug: sinon.stub() }
2224

2325
const discovery = proxyquire('../../src/evp_proxy/discovery', {
2426
'../agent/info': { fetchAgentInfo },
27+
'../log': log,
2528
})
2629

2730
discoverEVPProxy = discovery.discoverEVPProxy
@@ -97,6 +100,11 @@ describe('EVP proxy discovery', () => {
97100
basePath: '/evp_proxy/v2',
98101
})
99102
sinon.assert.calledOnceWithExactly(fetchAgentInfo, url, sinon.match.func)
103+
sinon.assert.calledOnceWithExactly(
104+
log.debug,
105+
'EVP proxy route %s discovered through the configured local receiver',
106+
'/evp_proxy/v2'
107+
)
100108
done()
101109
})
102110
})
@@ -107,6 +115,7 @@ describe('EVP proxy discovery', () => {
107115
discoverEVPProxy(url, options, (error, route) => {
108116
assert.ifError(error)
109117
assert.strictEqual(route, undefined)
118+
sinon.assert.notCalled(log.debug)
110119
done()
111120
})
112121
})
@@ -118,6 +127,7 @@ describe('EVP proxy discovery', () => {
118127
discoverEVPProxy(url, options, (error, route) => {
119128
assert.strictEqual(error, expectedError)
120129
assert.strictEqual(route, undefined)
130+
sinon.assert.notCalled(log.debug)
121131
done()
122132
})
123133
})

0 commit comments

Comments
 (0)