Skip to content

Commit 1f182a4

Browse files
authored
Deprecate addError functions (#447)
In PR #446 we removed the `addError` helper and renamed it `setError` without leaving in place a placeholder function for `addError` that prints a deprecation warning. Without this placeholder function users could run into an error when calling a function that does not exist. I've readded the `addError` function and made it print a deprecation warning. I've updated the `setError` function to print the same deprecation warning. The types package has been updated to include the `addError` function again on the Span interface.
1 parent ad40d9d commit 1f182a4

File tree

10 files changed

+55
-25
lines changed

10 files changed

+55
-25
lines changed

package-lock.json

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"packages/*"
1313
],
1414
"devDependencies": {
15-
"@appsignal/types": "^2.1.2",
15+
"@appsignal/types": "^2.1.3",
1616
"@types/jest": "^26.0.19",
1717
"husky": "^4.3.6",
1818
"jest": "^26.6.3",

packages/apollo-server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index",
66
"license": "MIT",
77
"dependencies": {
8-
"@appsignal/types": "^2.1.2",
8+
"@appsignal/types": "^2.1.3",
99
"apollo-server-plugin-base": "^0.10.3",
1010
"tslib": "^2.0.3"
1111
},

packages/express/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index",
66
"license": "MIT",
77
"dependencies": {
8-
"@appsignal/types": "^2.1.2",
8+
"@appsignal/types": "^2.1.3",
99
"tslib": "^2.0.3"
1010
},
1111
"peerDependencies": {

packages/koa/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index",
66
"license": "MIT",
77
"dependencies": {
8-
"@appsignal/types": "^2.1.2",
8+
"@appsignal/types": "^2.1.3",
99
"shimmer": "^1.2.1",
1010
"tslib": "^2.0.3"
1111
},

packages/nextjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index",
66
"license": "MIT",
77
"dependencies": {
8-
"@appsignal/types": "^2.1.2",
8+
"@appsignal/types": "^2.1.3",
99
"tslib": "^2.0.3"
1010
},
1111
"peerDependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
bump: "patch"
3+
---
4+
5+
Deprecate the addError function on the Span interface. Instead use the Tracer's `setError` function to set the error on the root span.

packages/nodejs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@appsignal/core": "^1.1.4",
12-
"@appsignal/types": "^2.1.2",
12+
"@appsignal/types": "^2.1.3",
1313
"require-in-the-middle": "^5.1.0",
1414
"semver": "^7.3.4",
1515
"shimmer": "^1.2.1",

packages/nodejs/src/noops/span.ts

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export class NoopSpan implements NodeSpan {
1717
return new NoopSpan()
1818
}
1919

20+
public addError(error: Error): this {
21+
console.warn(
22+
"DEPRECATED: Please use the `tracer.setError` helper instead to set the error on the root span."
23+
)
24+
return this
25+
}
26+
2027
public setError(error: Error): this {
2128
return this
2229
}

packages/nodejs/src/span.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,30 @@ export class BaseSpan implements NodeSpan {
143143
return this
144144
}
145145

146+
/**
147+
* Add a given `Error` object to the current `Span`.
148+
* Use `tracer.setError()` instead.
149+
*
150+
* @deprecated since Node.js version 2.1.0
151+
*/
152+
public addError(error: Error): this {
153+
console.warn(
154+
"DEPRECATED: Please use the `tracer.setError` helper instead to set the error on the root span."
155+
)
156+
157+
return this
158+
}
159+
146160
/**
147161
* Set a given `Error` object to the current `Span`.
148-
* Use tracer.setError() instead.
162+
* Use `tracer.setError()` instead.
163+
*
164+
* @deprecated since Node.js version 2.1.0
149165
*/
150166
public setError(error: Error): this {
151-
console.warn("setError() can only be called from a RootSpan object")
167+
console.warn(
168+
"DEPRECATED: Please use the `tracer.setError` helper instead to set the error on the root span."
169+
)
152170

153171
return this
154172
}

0 commit comments

Comments
 (0)