Skip to content

Commit 7fc5e40

Browse files
authored
Make noop object initialization consistent (#595)
Move the `NoopTracer` initialization to the initializer. That way it's only initialized once and not every time the tracer is called.
1 parent f100935 commit 7fc5e40

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: "patch"
3+
type: "change"
4+
---
5+
6+
Improve memory usage when extension is not initialized. It will no longer initialize a new empty Tracer object when the extension is not loaded or AppSignal is not active.

packages/nodejs/src/client.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class BaseClient implements Client {
2525
extension: Extension
2626
instrumentation: Instrumentation
2727

28-
#tracer: Tracer = new BaseTracer()
28+
#tracer: Tracer
2929
#metrics: Metrics
3030

3131
/**
@@ -52,8 +52,10 @@ export class BaseClient implements Client {
5252
if (this.isActive) {
5353
this.extension.start()
5454
this.#metrics = new BaseMetrics()
55+
this.#tracer = new BaseTracer()
5556
} else {
5657
this.#metrics = new NoopMetrics()
58+
this.#tracer = new NoopTracer()
5759
}
5860

5961
this.instrumentation = new Instrumentation(this.tracer(), this.metrics())
@@ -110,10 +112,6 @@ export class BaseClient implements Client {
110112
* returns a `NoopTracer`, which will do nothing.
111113
*/
112114
public tracer(): Tracer {
113-
if (!this.isActive) {
114-
return new NoopTracer()
115-
}
116-
117115
return this.#tracer
118116
}
119117

0 commit comments

Comments
 (0)