Skip to content

Commit

Permalink
Update Span type used in ScopeManager (#587)
Browse files Browse the repository at this point in the history
We changed the types used in PR #451. We no longer rely on the
`@appsignal/types` package for this, but define it in the package
itself.

The ScopeManager appears to not have been updated to match and is the
only place in which the `NodeSpan` from the types package is still
used. If we update this usage we can remove all Node.js types from the
types package.
  • Loading branch information
tombruijn authored Feb 1, 2022
1 parent e0901fd commit 7a7e5c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "change"
---

Update the expected Span type in ScopeManager to `Span` from the `@appsignal/nodejs` package, rather than the `NodeSpan` from the `@appsignal/types` package. The type definition is the same, but now all Span types used by the Node.js integration are defined in the `@appsigna/nodejs` package.
15 changes: 8 additions & 7 deletions packages/nodejs/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* Copyright 2018, Google LLC
*/

import { NodeSpan, Func } from "@appsignal/types"
import { Func } from "@appsignal/types"
import { Span } from "./interfaces/span"
import * as asyncHooks from "async_hooks"
import { EventEmitter } from "events"
import shimmer from "shimmer"
Expand All @@ -32,8 +33,8 @@ type ContextWrapped<T> = T & { [WRAPPED]?: boolean }
* @class
*/
export class ScopeManager {
#roots: Map<number, NodeSpan | undefined>
#scopes: Map<number, NodeSpan | undefined>
#roots: Map<number, Span | undefined>
#scopes: Map<number, Span | undefined>
#asyncHook: asyncHooks.AsyncHook

constructor() {
Expand Down Expand Up @@ -105,31 +106,31 @@ export class ScopeManager {
/**
* Returns the current active `Span`.
*/
public active(): NodeSpan | undefined {
public active(): Span | undefined {
const uid = asyncHooks.executionAsyncId()
return this.#scopes.get(uid)
}

/**
* Sets the root `Span`
*/
public setRoot(rootSpan: NodeSpan) {
public setRoot(rootSpan: Span) {
const uid = asyncHooks.executionAsyncId()
this.#roots.set(uid, rootSpan)
}

/*
* Returns the current root `Span`.
*/
public root(): NodeSpan | undefined {
public root(): Span | undefined {
const uid = asyncHooks.executionAsyncId()
return this.#roots.get(uid)
}

/**
* Executes a given function within the context of a given `Span`.
*/
public withContext<T>(span: NodeSpan, fn: (s: NodeSpan) => T): T {
public withContext<T>(span: Span, fn: (s: Span) => T): T {
const uid = asyncHooks.executionAsyncId()
const oldScope = this.#scopes.get(uid)
const rootSpan = this.#roots.get(uid)
Expand Down

0 comments on commit 7a7e5c5

Please sign in to comment.