-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature/improve instrumentation #179
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c2c171
feat: send logs to otel
augusto-draxx 66e10ac
feat: otel tracer provider to send custom span
augusto-draxx 79f48cf
fix: audit vulnerabilities
augusto-draxx 0524ccc
fix: build error
augusto-draxx 07ac153
fix: http-fetch-utils-test adjusting new instrumentation dependency
augusto-draxx dbff849
fix: build erros
augusto-draxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/core/infrastructure/container-registry/observability/otel-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { OtelTracerProvider } from '../../observability/otel-tracer-provider' | ||
import { Container, ContainerModule } from '../../utils/di/container' | ||
|
||
export const OtelModule = new ContainerModule((container: Container) => { | ||
container.bind<OtelTracerProvider>(OtelTracerProvider).toSelf() | ||
}) |
78 changes: 39 additions & 39 deletions
78
src/core/infrastructure/container-registry/use-cases/account-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
import { Container, ContainerModule } from '../../utils/di/container' | ||
|
||
import { | ||
FetchAllAccounts, | ||
FetchAllAccountsUseCase | ||
} from '@/core/application/use-cases/accounts/fetch-all-account-use-case' | ||
import { | ||
CreateAccount, | ||
CreateAccountUseCase | ||
} from '@/core/application/use-cases/accounts/create-account-use-case' | ||
import { | ||
FetchAccountById, | ||
FetchAccountByIdUseCase | ||
} from '@/core/application/use-cases/accounts/fetch-account-by-id-use-case' | ||
import { | ||
UpdateAccount, | ||
UpdateAccountUseCase | ||
} from '@/core/application/use-cases/accounts/update-account-use-case' | ||
import { | ||
DeleteAccount, | ||
DeleteAccountUseCase | ||
} from '@/core/application/use-cases/accounts/delete-account-use-case' | ||
import { | ||
FetchAccountsWithPortfolios, | ||
FetchAccountsWithPortfoliosUseCase | ||
} from '@/core/application/use-cases/accounts-with-portfolios/fetch-accounts-with-portfolios-use-case' | ||
|
||
export const AccountUseCaseModule = new ContainerModule( | ||
(container: Container) => { | ||
container.bind<FetchAllAccounts>(FetchAllAccountsUseCase).toSelf() | ||
container.bind<CreateAccount>(CreateAccountUseCase).toSelf() | ||
container.bind<FetchAccountById>(FetchAccountByIdUseCase).toSelf() | ||
container.bind<UpdateAccount>(UpdateAccountUseCase).toSelf() | ||
container.bind<DeleteAccount>(DeleteAccountUseCase).toSelf() | ||
container | ||
.bind<FetchAccountsWithPortfolios>(FetchAccountsWithPortfoliosUseCase) | ||
.toSelf() | ||
} | ||
) | ||
import { Container, ContainerModule } from '../../utils/di/container' | ||
import { | ||
FetchAllAccounts, | ||
FetchAllAccountsUseCase | ||
} from '@/core/application/use-cases/accounts/fetch-all-account-use-case' | ||
import { | ||
CreateAccount, | ||
CreateAccountUseCase | ||
} from '@/core/application/use-cases/accounts/create-account-use-case' | ||
import { | ||
FetchAccountById, | ||
FetchAccountByIdUseCase | ||
} from '@/core/application/use-cases/accounts/fetch-account-by-id-use-case' | ||
import { | ||
UpdateAccount, | ||
UpdateAccountUseCase | ||
} from '@/core/application/use-cases/accounts/update-account-use-case' | ||
import { | ||
DeleteAccount, | ||
DeleteAccountUseCase | ||
} from '@/core/application/use-cases/accounts/delete-account-use-case' | ||
import { | ||
FetchAccountsWithPortfolios, | ||
FetchAccountsWithPortfoliosUseCase | ||
} from '@/core/application/use-cases/accounts-with-portfolios/fetch-accounts-with-portfolios-use-case' | ||
export const AccountUseCaseModule = new ContainerModule( | ||
(container: Container) => { | ||
container.bind<FetchAllAccounts>(FetchAllAccountsUseCase).toSelf() | ||
container.bind<CreateAccount>(CreateAccountUseCase).toSelf() | ||
container.bind<FetchAccountById>(FetchAccountByIdUseCase).toSelf() | ||
container.bind<UpdateAccount>(UpdateAccountUseCase).toSelf() | ||
container.bind<DeleteAccount>(DeleteAccountUseCase).toSelf() | ||
container | ||
.bind<FetchAccountsWithPortfolios>(FetchAccountsWithPortfoliosUseCase) | ||
.toSelf() | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 37 additions & 25 deletions
62
src/core/infrastructure/observability/instrumentation-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
import { Resource } from '@opentelemetry/resources' | ||
import { | ||
MeterProvider, | ||
PeriodicExportingMetricReader | ||
} from '@opentelemetry/sdk-metrics' | ||
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http' | ||
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http' | ||
import { registerInstrumentations } from '@opentelemetry/instrumentation' | ||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' | ||
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' | ||
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino' | ||
import { RuntimeNodeInstrumentation } from '@opentelemetry/instrumentation-runtime-node' | ||
import { metrics } from '@opentelemetry/api' | ||
|
||
const metricExporter = new OTLPMetricExporter({ | ||
url: process.env.OTEL_URL | ||
}) | ||
|
||
const metricReader = new PeriodicExportingMetricReader({ | ||
exporter: metricExporter, | ||
exportIntervalMillis: 5000 | ||
}) | ||
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici' | ||
import { Resource } from '@opentelemetry/resources' | ||
import { SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs' | ||
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics' | ||
import { NodeSDK } from '@opentelemetry/sdk-node' | ||
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node' | ||
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions' | ||
|
||
const meterProvider = new MeterProvider({ | ||
const sdk = new NodeSDK({ | ||
resource: new Resource({ | ||
'service.name': 'midaz-console' | ||
[ATTR_SERVICE_NAME]: 'midaz-console' | ||
}), | ||
readers: [metricReader] | ||
}) | ||
|
||
metrics.setGlobalMeterProvider(meterProvider) | ||
|
||
registerInstrumentations({ | ||
spanProcessors: [ | ||
new SimpleSpanProcessor( | ||
new OTLPTraceExporter({ | ||
url: process.env.OTEL_URL_TRACES | ||
}) | ||
) | ||
], | ||
metricReader: new PeriodicExportingMetricReader({ | ||
exporter: new OTLPMetricExporter({ | ||
url: process.env.OTEL_URL_METRICS | ||
}), | ||
exportIntervalMillis: 5000 | ||
}), | ||
logRecordProcessors: [ | ||
new SimpleLogRecordProcessor( | ||
new OTLPLogExporter({ | ||
url: process.env.OTEL_URL_LOGS | ||
}) | ||
) | ||
], | ||
instrumentations: [ | ||
new HttpInstrumentation(), | ||
new RuntimeNodeInstrumentation() | ||
new RuntimeNodeInstrumentation(), | ||
new PinoInstrumentation(), | ||
new UndiciInstrumentation() | ||
] | ||
}) | ||
|
||
sdk.start() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using JSON.stringify for logging structured objects may hinder downstream processing that expects structured data. It is recommended to pass the log object directly.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.