Skip to content

Commit

Permalink
Rename addError helpers to setError
Browse files Browse the repository at this point in the history
In order to comply with AppSignal naming rules, we rename the addError
helper to setError
  • Loading branch information
luismiramirez committed Sep 23, 2021
1 parent 590f190 commit 723b98d
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 66 deletions.
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"packages/*"
],
"devDependencies": {
"@appsignal/types": "^2.1.1",
"@appsignal/types": "^2.1.2",
"@types/jest": "^26.0.19",
"husky": "^4.3.6",
"jest": "^26.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"types": "dist/index",
"license": "MIT",
"dependencies": {
"@appsignal/types": "^2.1.1",
"@appsignal/types": "^2.1.2",
"apollo-server-plugin-base": "^0.10.3",
"tslib": "^2.0.3"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const createApolloPlugin = (appsignal: NodeClient, _options = {}) => {

return {
executionDidEnd: err => {
if (err) tracer.addError(err)
if (err) tracer.setError(err)
execSpan.close()
}
}
Expand All @@ -34,7 +34,7 @@ export const createApolloPlugin = (appsignal: NodeClient, _options = {}) => {
const parseSpan = rootSpan.child().setCategory("parse.graphql")

return err => {
if (err) tracer.addError(err)
if (err) tracer.setError(err)
parseSpan.close()
}
},
Expand All @@ -43,7 +43,7 @@ export const createApolloPlugin = (appsignal: NodeClient, _options = {}) => {

return err => {
// take only the first error
if (err) tracer.addError(err[0])
if (err) tracer.setError(err[0])
validateSpan.close()
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"types": "dist/index",
"license": "MIT",
"dependencies": {
"@appsignal/types": "^2.1.1",
"@appsignal/types": "^2.1.2",
"tslib": "^2.0.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/express/src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function expressErrorHandler(
// if there's no `status` property, forward the error
// we also ignore client errors here
if (err && (!err.status || (err.status && err.status >= 500))) {
tracer.addError(err)
tracer.setError(err)
}

return next(err)
Expand Down
4 changes: 1 addition & 3 deletions packages/koa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ const Router = require("@koa/router"); // @koa/router is also supported out of t
app.on("error", (error) => {
appsignal
.tracer()
.currentSpan()
.addError(error)
.close()
.setError(error)
});

const app = new Koa();
Expand Down
2 changes: 1 addition & 1 deletion packages/koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"types": "dist/index",
"license": "MIT",
"dependencies": {
"@appsignal/types": "^2.1.1",
"@appsignal/types": "^2.1.2",
"shimmer": "^1.2.1",
"tslib": "^2.0.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"types": "dist/index",
"license": "MIT",
"dependencies": {
"@appsignal/types": "^2.1.1",
"@appsignal/types": "^2.1.2",
"tslib": "^2.0.3"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
bump: "minor"
---

Add rootSpan and addError helpers.
Add rootSpan and setError helpers.

Errors added to child spans are ignored by the agent. Now the rootSpan is
always accessible from the tracer object as well as addError. The addError
always accessible from the tracer object as well as setError. The setError
function allows to track errors on demand and they will be always attached
to the main current span, so they don't get ignored by the agent.
2 changes: 1 addition & 1 deletion packages/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@appsignal/core": "^1.1.4",
"@appsignal/types": "^2.1.1",
"@appsignal/types": "^2.1.2",
"require-in-the-middle": "^5.1.0",
"semver": "^7.3.4",
"shimmer": "^1.2.1",
Expand Down
14 changes: 6 additions & 8 deletions packages/nodejs/src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ export function demo(tracer: Tracer) {

// error sample
tracer.withSpan(tracer.createSpan(), span => {
span
.setName("GET /demo")
.setCategory("process_request.http")
.addError(
new Error(
"Hello world! This is an error used for demonstration purposes."
)
tracer.setError(
new Error(
"Hello world! This is an error used for demonstration purposes."
)
.close()
)

span.setName("GET /demo").setCategory("process_request.http").close()
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ function outgoingRequestFunction(
try {
req = original.apply(this, [urlOrOptions, ...args])
} catch (err) {
span.addError(err).close()
tracer.setError(err)
span.close()
throw err
}

Expand All @@ -128,7 +129,8 @@ function outgoingRequestFunction(
})

req.on("error", (error: Error) => {
span.addError(error).close()
tracer.setError(error)
span.close()
})

return req
Expand Down
2 changes: 1 addition & 1 deletion packages/nodejs/src/instrumentation/pg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const instrument = (
if (returned instanceof EventEmitter) {
tracer.wrapEmitter(returned)
} else if (typeof returned.then === "function") {
returned = patchPromise(span, returned)
returned = patchPromise(tracer, span, returned)
}
}

Expand Down
14 changes: 10 additions & 4 deletions packages/nodejs/src/instrumentation/pg/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function patchCallback(
callback: Function
) {
return tracer.wrap((err: Error | null, res?) => {
if (err) span.addError(err)
if (err) tracer.setError(err)
span.close()
return callback(err, res)
})
Expand All @@ -31,7 +31,8 @@ export function patchSubmittable(
return tracer.wrap(function (this: Submittable, ...args: any[]): void {
if (!spanEnded) {
const err: Error = args[0]
span.addError(err).close()
tracer.setError(err)
span.close()
spanEnded = true
}

Expand Down Expand Up @@ -60,14 +61,19 @@ export function patchSubmittable(
return submittable
}

export function patchPromise<T>(span: NodeSpan, promise: Promise<T>) {
export function patchPromise<T>(
tracer: Tracer,
span: NodeSpan,
promise: Promise<T>
) {
return promise.then(
res => {
span.close()
return res
},
err => {
span.addError(err).close()
tracer.setError(err)
span.close()
throw err
}
)
Expand Down
2 changes: 1 addition & 1 deletion packages/nodejs/src/instrumentation/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type RedisCallback = <T>(err: Error | null, reply: T) => void
function wrapCallback(tracer: Tracer, span: NodeSpan, done: RedisCallback) {
// @TODO: add results to span here?
const fn = function <T>(err: Error | null, res: T) {
if (err) span.addError(err)
if (err) tracer.setError(err)

span.close()

Expand Down
2 changes: 1 addition & 1 deletion packages/nodejs/src/noops/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class NoopSpan implements NodeSpan {
return new NoopSpan()
}

public addError(error: Error): this {
public setError(error: Error): this {
return this
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nodejs/src/noops/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NoopTracer implements Tracer {
return new NoopSpan()
}

public addError(error: Error): NodeSpan {
public setError(error: Error): NodeSpan {
return new NoopSpan()
}

Expand Down
5 changes: 4 additions & 1 deletion packages/nodejs/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class ScopeManager {

if (this.#scopes.get(currentId)) {
this.#scopes.set(id, this.#scopes.get(currentId))
this.#roots.set(id, this.#roots.get(currentId))
}
} else {
/**
Expand All @@ -62,6 +63,7 @@ export class ScopeManager {
*/
if (this.#scopes.get(triggerId)) {
this.#scopes.set(id, this.#scopes.get(triggerId))
this.#roots.set(id, this.#roots.get(triggerId))
}
}
}
Expand Down Expand Up @@ -137,7 +139,7 @@ export class ScopeManager {
try {
return fn(span)
} catch (err) {
rootSpan?.addError(err)
rootSpan?.setError(err)
throw err
} finally {
// revert to the previous span
Expand All @@ -146,6 +148,7 @@ export class ScopeManager {
this.#roots.delete(uid)
} else {
this.#scopes.set(uid, oldScope)
this.#roots.set(uid, rootSpan)
}
}
}
Expand Down
Loading

0 comments on commit 723b98d

Please sign in to comment.