Skip to content

Commit ff7ec1d

Browse files
committed
refactor(profiling): make profiling exporter fields private (#9043)
The EventSerializer, AgentExporter, and FileExporter state is read only inside each class, so promote it to #private and let the runtime enforce the boundary instead of the underscore convention. AgentExporter._url stays a plain underscore property: the profiling config spec asserts the resolved intake URL through config.exporters[0]._url, so the field is part of a reachable surface rather than purely internal.
1 parent 0dc86e6 commit ff7ec1d

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

packages/dd-trace/src/profiling/exporters/agent.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,18 @@ function computeRetries (uploadTimeout) {
8888
}
8989

9090
class AgentExporter extends EventSerializer {
91+
#backoffTime
92+
#backoffTries
93+
9194
constructor (config = {}) {
9295
super(config)
9396
const { url, uploadTimeout } = config
9497
this._url = url
9598

9699
const [backoffTries, backoffTime] = computeRetries(uploadTimeout)
97100

98-
this._backoffTime = backoffTime
99-
this._backoffTries = backoffTries
101+
this.#backoffTime = backoffTime
102+
this.#backoffTries = backoffTries
100103
}
101104

102105
export (exportSpec) {
@@ -128,8 +131,8 @@ class AgentExporter extends EventSerializer {
128131
return new Promise((resolve, reject) => {
129132
const operation = retry.operation({
130133
randomize: true,
131-
minTimeout: this._backoffTime,
132-
retries: this._backoffTries,
134+
minTimeout: this.#backoffTime,
135+
retries: this.#backoffTries,
133136
unref: true,
134137
})
135138

@@ -148,7 +151,7 @@ class AgentExporter extends EventSerializer {
148151
'DD-EVP-ORIGIN-VERSION': version,
149152
...form.getHeaders(),
150153
},
151-
timeout: this._backoffTime * 2 ** attempt,
154+
timeout: this.#backoffTime * 2 ** attempt,
152155
}
153156

154157
docker.inject(options.headers)

packages/dd-trace/src/profiling/exporters/event_serializer.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ const { availableParallelism, libuvThreadPoolSize } = require('../libuv-size')
99
const processTags = require('../../process-tags')
1010

1111
class EventSerializer {
12+
#activation
13+
#appVersion
14+
#env
15+
#host
16+
#libraryInjected
17+
#service
18+
1219
constructor ({ env, host, service, version, libraryInjected, activation } = {}) {
13-
this._env = env
14-
this._host = host
15-
this._service = service
16-
this._appVersion = version
17-
this._libraryInjected = libraryInjected
18-
this._activation = activation || 'unknown'
20+
this.#env = env
21+
this.#host = host
22+
this.#service = service
23+
this.#appVersion = version
24+
this.#libraryInjected = libraryInjected
25+
this.#activation = activation || 'unknown'
1926
}
2027

2128
typeToFile (type) {
@@ -43,21 +50,21 @@ class EventSerializer {
4350
endpoint_counts: endpointCounts,
4451
info: {
4552
application: {
46-
env: this._env,
47-
service: this._service,
53+
env: this.#env,
54+
service: this.#service,
4855
start_time: new Date(perf.nodeTiming.nodeStart + perf.timeOrigin).toISOString(),
49-
version: this._appVersion,
56+
version: this.#appVersion,
5057
},
5158
platform: {
52-
hostname: this._host,
59+
hostname: this.#host,
5360
kernel_name: os.type(),
5461
kernel_release: os.release(),
5562
kernel_version: os.version(),
5663
},
5764
profiler: {
58-
activation: this._activation,
65+
activation: this.#activation,
5966
ssi: {
60-
mechanism: this._libraryInjected ? 'injected_agent' : 'none',
67+
mechanism: this.#libraryInjected ? 'injected_agent' : 'none',
6168
},
6269
version,
6370
...infos,

packages/dd-trace/src/profiling/exporters/file.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ function formatDateTime (t) {
1414
}
1515

1616
class FileExporter extends EventSerializer {
17+
#pprofPrefix
18+
1719
constructor (config = {}) {
1820
super(config)
1921
const { pprofPrefix } = config
20-
this._pprofPrefix = pprofPrefix || ''
22+
this.#pprofPrefix = pprofPrefix || ''
2123
}
2224

2325
export (exportSpec) {
2426
const { profiles, end } = exportSpec
2527
const types = Object.keys(profiles)
2628
const dateStr = formatDateTime(end)
2729
const tasks = types.map(type => {
28-
return writeFile(`${this._pprofPrefix}${type}_worker_${threadId}_${dateStr}.pprof`, profiles[type])
30+
return writeFile(`${this.#pprofPrefix}${type}_worker_${threadId}_${dateStr}.pprof`, profiles[type])
2931
})
3032
tasks.push(writeFile(`event_worker_${threadId}_${dateStr}.json`, this.getEventJSON(exportSpec)))
3133
return Promise.all(tasks)

0 commit comments

Comments
 (0)