Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation warning to instrumentationsLoaded #888

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "deprecate"
---

Add deprecation warning to instrumentationsLoaded helper
18 changes: 4 additions & 14 deletions src/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,13 @@ describe("Helpers", () => {
})
})

describe("instrumentationsLoaded", () => {
it("returns a promise from the globally stored client if found", () => {
const debugMock = jest.spyOn(Client.integrationLogger, "debug")

expect(instrumentationsLoaded()).toBeInstanceOf(Promise)
expect(debugMock).toHaveBeenCalledTimes(0)
})

it("returns an empty promise and logs if the globally stored client is not found", () => {
// Remove the stored client
global.__APPSIGNAL__ = null as any

const debugMock = jest.spyOn(Client.integrationLogger, "debug")
describe("instrumentationsLoaded (deprecated)", () => {
it("returns a promise and a deprecation warning", () => {
const debugMock = jest.spyOn(Client.integrationLogger, "warn")

expect(instrumentationsLoaded()).toBeInstanceOf(Promise)
expect(debugMock).toHaveBeenCalledWith(
"Client is not initialized, cannot get OpenTelemetry instrumentations loaded"
"instrumentationsLoaded() is deprecated, please remove it from your code as it'll be deleted in the next major release."
)
})
})
Expand Down
2 changes: 0 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export class Client {
config: Configuration
readonly integrationLogger: IntegrationLogger
extension: Extension
instrumentationsLoaded: Promise<void>

#metrics: Metrics
#sdk?: NodeSDK
Expand Down Expand Up @@ -142,7 +141,6 @@ export class Client {
this.config = new Configuration(options)
this.extension = new Extension()
this.integrationLogger = this.setUpIntegrationLogger()
this.instrumentationsLoaded = Promise.resolve()
this.storeInGlobal()

if (this.isActive) {
Expand Down
16 changes: 7 additions & 9 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ export function sendError(error: Error, fn: () => void = () => {}) {
}
}

/**
* @deprecated This function is no longer required for manual instrumentation.
*/
export function instrumentationsLoaded(): Promise<void> {
const globallyStoredClient = Client.client
Client.integrationLogger.warn(
"instrumentationsLoaded() is deprecated, please remove it from your code as it'll be deleted in the next major release."
)

if (globallyStoredClient) {
return globallyStoredClient.instrumentationsLoaded
} else {
Client.integrationLogger.debug(
"Client is not initialized, cannot get OpenTelemetry instrumentations loaded"
)
return Promise.resolve()
}
return Promise.resolve()
}