Skip to content

Commit

Permalink
Implement sendParams config option
Browse files Browse the repository at this point in the history
The `sendParams` config option allows the users to decide if they want
to send request params to AppSignal. Its default value is `true`.

`Span#setSampleData()` now checks if the `sendParams` option is enabled
when sending `params` to decide if they're going to be sent to AppSignal
or not.
  • Loading branch information
luismiramirez committed Dec 29, 2021
1 parent 35dc748 commit 118ae05
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: "patch"
type: "add"
---

The `sendParams` config option is now available. When set to `false`, it prevents the integration
from sending request params to AppSignal.
44 changes: 44 additions & 0 deletions packages/nodejs/src/__tests__/span.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ChildSpan, RootSpan } from "../span"
import { span } from "../extension_wrapper"
import { BaseClient } from "../client"
import { Data } from "../internal/data"

type SpanData = {
closed: boolean
Expand Down Expand Up @@ -178,3 +181,44 @@ describe("ChildSpan", () => {
expect(internal.closed).toBeTruthy()
})
})

describe(".setSampleData()", () => {
const name = "TEST APP"
const pushApiKey = "TEST_API_KEY"
const DEFAULT_OPTS = { name, pushApiKey, enableMinutelyProbes: false }
const sampleData = { foo: "bar" }

beforeEach(() => {
jest.clearAllMocks()
})

it("calls the extension with the desired data if sendParams is active", () => {
new BaseClient({ ...DEFAULT_OPTS })

const rootSpan = new RootSpan()
const spanMock = jest
.spyOn(span, "setSpanSampleData")
.mockImplementation(() => {})

rootSpan.setSampleData("params", sampleData)

expect(spanMock).toHaveBeenCalledWith(
{},
"params",
Data.generate(sampleData)
)
})

it("does not call the extension with the desired data if sendParams is inactive", () => {
new BaseClient({ ...DEFAULT_OPTS, sendParams: false })

const rootSpan = new RootSpan()
const spanMock = jest
.spyOn(span, "setSpanSampleData")
.mockImplementation(() => {})

rootSpan.setSampleData("params", sampleData)

expect(spanMock).not.toHaveBeenCalled()
})
})
2 changes: 2 additions & 0 deletions packages/nodejs/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Span, SpanOptions, SpanContext } from "./interfaces"
import { span } from "./extension_wrapper"
import { Data } from "./internal/data"
import { getAgentTimestamps } from "./utils"
import { BaseClient } from "./client"

/**
* The `Span` object represents a length of time in the flow of execution
Expand Down Expand Up @@ -125,6 +126,7 @@ export class BaseSpan implements Span {
>
): this {
if (!key || !data) return this
if (key == "params" && !BaseClient.config.data.sendParams) return this

try {
span.setSpanSampleData(this._ref, key, Data.generate(data))
Expand Down

0 comments on commit 118ae05

Please sign in to comment.