Skip to content
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
52 changes: 23 additions & 29 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 @@ -25,7 +25,7 @@
"@bugsnag/js": "^8.2.0",
"@fastify/awilix": "^6.0.1",
"@lokalise/backend-http-client": "^4.1.1",
"@lokalise/fastify-extras": "^25.5.0",
"@lokalise/fastify-extras": "27.2.0",
"@lokalise/node-core": "^13.5.0",
"awilix": "^12.0.5",
"fastify": "^5.2.1",
Expand Down
9 changes: 9 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createErrorHandler,
getRequestIdFastifyAppConfig,
metricsPlugin,
newrelicTransactionManagerPlugin,
} from '@lokalise/fastify-extras'
import { resolveLogger } from '@lokalise/node-core'
import type { FastifyBaseLogger } from 'fastify'
Expand Down Expand Up @@ -56,6 +57,14 @@ export async function getApp(configOverrides: ConfigOverrides = {}) {
app.setValidatorCompiler(validatorCompiler)
app.setSerializerCompiler(serializerCompiler)

/**
* Since DI config relies on having app-scoped NewRelic instance to be set by the plugin,
* we instantiate it earlier than we run the DI initialization.
*/
await app.register(newrelicTransactionManagerPlugin, {
isEnabled: config.vendors.newrelic.isEnabled,
})

await app.register(fastifyAwilixPlugin, { disposeOnClose: true })
registerDependencies(
diContainer,
Expand Down
13 changes: 11 additions & 2 deletions src/infrastructure/diConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { EnvService } from '../modules/env/EnvService.js'
import { PublishService } from '../modules/publish/PublishService.js'
import { TranslateService } from '../modules/translate/TranslateService.js'

import { getConfig } from './config.js'
import type { TransactionObservabilityManager } from '@lokalise/node-core'
import type { Config } from './config.js'
import { getConfig } from './config.js'

export type ExternalDependencies = {
app?: FastifyInstance
Expand All @@ -22,13 +23,20 @@ export type DependencyOverrides = Partial<DiConfig>

export function registerDependencies(
diContainer: AwilixContainer,
_dependencies: ExternalDependencies = {},
dependencies: ExternalDependencies = {},
dependencyOverrides: DependencyOverrides = {},
): void {
const diConfig: DiConfig = {
config: asFunction(() => {
return getConfig()
}, SINGLETON_CONFIG),
transactionObservabilityManager: asFunction(() => {
if (!dependencies.app?.newrelicTransactionManager) {
throw new Error('Observability manager is not set')
}

return dependencies.app?.newrelicTransactionManager
}, SINGLETON_CONFIG),
fakeIntegrationApiClient: asClass(FakeIntegrationApiClient, SINGLETON_CONFIG),
cacheService: asClass(CacheService, SINGLETON_CONFIG),
authService: asClass(AuthService, SINGLETON_CONFIG),
Expand All @@ -48,6 +56,7 @@ type DiConfig = NameAndRegistrationPair<Dependencies>

export interface Dependencies {
config: Config
transactionObservabilityManager: TransactionObservabilityManager
fakeIntegrationApiClient: FakeIntegrationApiClient
cacheService: CacheService
authService: AuthService
Expand Down