Skip to content

Commit

Permalink
Implement sendSessionData config option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luismiramirez committed Jan 7, 2022
1 parent d01609f commit d2defeb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 30 additions & 2 deletions packages/nodejs/src/__tests__/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
})
})
4 changes: 3 additions & 1 deletion packages/nodejs/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ export class BaseSpan implements Span {
HashMapValue | Array<HashMapValue> | HashMap<HashMapValue> | 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))
Expand Down

0 comments on commit d2defeb

Please sign in to comment.