From d2defeb1910999bca3d39c724e583079999d55ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luismi=20Ram=C3=ADrez?= Date: Wed, 5 Jan 2022 09:38:35 +0100 Subject: [PATCH] Implement sendSessionData config option The `sendSessionData` config option allows the user to decide if they want to send session data to AppSignal. Its default value is `true`. `Span#setSampleData()` now checks if the `sendSessionData` option is enabled when sending `session_data` to decide if they're going to be sent to AppSignal or not. --- ...sessiondata-config-opt-is-now-available.md | 7 ++++ packages/nodejs/src/__tests__/span.test.ts | 32 +++++++++++++++++-- packages/nodejs/src/span.ts | 4 ++- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 packages/nodejs/.changesets/skipsessiondata-config-opt-is-now-available.md diff --git a/packages/nodejs/.changesets/skipsessiondata-config-opt-is-now-available.md b/packages/nodejs/.changesets/skipsessiondata-config-opt-is-now-available.md new file mode 100644 index 00000000..a4699b2d --- /dev/null +++ b/packages/nodejs/.changesets/skipsessiondata-config-opt-is-now-available.md @@ -0,0 +1,7 @@ +--- +bump: "patch" +type: "add" +--- + +The `sendSessionData` config option is now available. When set to `false`, it prevents the +integration from sending session data to AppSignal. diff --git a/packages/nodejs/src/__tests__/span.test.ts b/packages/nodejs/src/__tests__/span.test.ts index 4390c447..75f0da75 100644 --- a/packages/nodejs/src/__tests__/span.test.ts +++ b/packages/nodejs/src/__tests__/span.test.ts @@ -192,7 +192,7 @@ describe(".setSampleData()", () => { jest.clearAllMocks() }) - it("calls the extension with the desired data if sendParams is active", () => { + it("calls the extension with the desired params data if sendParams is active", () => { new BaseClient({ ...DEFAULT_OPTS }) const rootSpan = new RootSpan() @@ -209,7 +209,7 @@ describe(".setSampleData()", () => { ) }) - it("does not call the extension with the desired data if sendParams is inactive", () => { + it("does not call the extension with the desired params data if sendParams is inactive", () => { new BaseClient({ ...DEFAULT_OPTS, sendParams: false }) const rootSpan = new RootSpan() @@ -221,4 +221,32 @@ describe(".setSampleData()", () => { expect(spanMock).not.toHaveBeenCalled() }) + + it("calls the extension with the desired session data if sendSessionData is active", () => { + new BaseClient({ ...DEFAULT_OPTS }) + + const rootSpan = new RootSpan() + const spanMock = jest + .spyOn(span, "setSpanSampleData") + .mockImplementation(() => {}) + + rootSpan.setSampleData("session_data", sampleData) + + expect(spanMock).toHaveBeenCalledWith( + {}, + "session_data", + Data.generate(sampleData) + ) + }) + + it("does not call the extension with the desired session data if sendSessionData is inactive", () => { + new BaseClient({ ...DEFAULT_OPTS, sendSessionData: false }) + + const rootSpan = new RootSpan() + const spanMock = jest.spyOn(span, "setSpanSampleData") + + rootSpan.setSampleData("session_data", sampleData) + + expect(spanMock).not.toHaveBeenCalled() + }) }) diff --git a/packages/nodejs/src/span.ts b/packages/nodejs/src/span.ts index cfbcb377..f25be7d9 100644 --- a/packages/nodejs/src/span.ts +++ b/packages/nodejs/src/span.ts @@ -125,8 +125,10 @@ export class BaseSpan implements Span { HashMapValue | Array | HashMap | undefined > ): this { + const clientConfig = BaseClient.config.data if (!key || !data) return this - if (key == "params" && !BaseClient.config.data.sendParams) return this + if (key == "params" && !clientConfig.sendParams) return this + if (key == "session_data" && !clientConfig.sendSessionData) return this try { span.setSpanSampleData(this._ref, key, Data.generate(data))