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

Use node-core TransactionObservabilityManager interface #151

Merged
merged 1 commit into from
May 6, 2024
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
23 changes: 21 additions & 2 deletions lib/plugins/newrelicTransactionManagerPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { TransactionObservabilityManager } from '@lokalise/node-core'
import type { FastifyInstance } from 'fastify'
import fp from 'fastify-plugin'
import type {
Expand Down Expand Up @@ -27,7 +28,7 @@ export interface NewRelicTransactionManagerOptions {
isEnabled: boolean
}

export class NewRelicTransactionManager {
export class NewRelicTransactionManager implements TransactionObservabilityManager {
private readonly isEnabled: boolean
private readonly transactionMap: FifoMap<TransactionHandle>

Expand All @@ -50,7 +51,6 @@ export class NewRelicTransactionManager {
}

/**
*
* @param transactionName - used for grouping similar transactions together
* @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions
*/
Expand All @@ -64,6 +64,25 @@ export class NewRelicTransactionManager {
})
}

/**
* @param transactionName - used for grouping similar transactions together
* @param uniqueTransactionKey - used for identifying specific ongoing transaction. Must be reasonably unique to reduce possibility of collisions *
* @param transactionGroup - group is used for grouping related transactions with different names
*/
public startWithGroup(
transactionName: string,
uniqueTransactionKey: string,
transactionGroup: string,
): void {
if (!this.isEnabled) {
return
}

newrelic.startBackgroundTransaction(transactionName, transactionGroup, () => {
this.transactionMap.set(uniqueTransactionKey, newrelic.getTransaction())
})
}

public stop(uniqueTransactionKey: string): void {
if (!this.isEnabled) {
return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"devDependencies": {
"@fastify/request-context": "^5.1.0",
"@lokalise/node-core": "^9.16.1",
"@lokalise/node-core": "^9.17.0",
"@types/newrelic": "^9.14.3",
"@types/node": "^20.12.7",
"@amplitude/analytics-types": "^2.5.0",
Expand Down
Loading