Commit e4c3b4b4 authored by Annie Ke's avatar Annie Ke Committed by GitHub

feat[dtl]: add config switches for sentry and metrics (#950)

* feat[dtl]: add config switches for sentry and metrics

* changeset and environment tag
parent e3b138be
---
'@eth-optimism/data-transport-layer': patch
---
Add Sentry and Metrics switches and environment tag to DTL
......@@ -28,5 +28,8 @@ DATA_TRANSPORT_LAYER__LEGACY_SEQUENCER_COMPATIBILITY=false
# Monitoring
# Leave the SENTRY_DSN variable unset during local development
DATA_TRANSPORT_LAYER__USE_SENTRY=
DATA_TRANSPORT_LAYER__SENTRY_DSN=
DATA_TRANSPORT_LAYER__SENTRY_TRACE_RATE=
DATA_TRANSPORT_LAYER__ENABLE_METRICS=
......@@ -28,8 +28,10 @@ export interface L1DataTransportServiceOptions {
syncFromL2?: boolean
transactionsPerPollingInterval: number
legacySequencerCompatibility: boolean
useSentry?: boolean
sentryDsn?: string
sentryTraceRate?: number
enableMetrics?: boolean
defaultBackend: string
}
......
......@@ -46,8 +46,10 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli'
false
),
defaultBackend: config.str('default-backend', 'l1'),
useSentry: config.bool('use-sentry', false),
sentryDsn: config.str('sentry-dsn'),
sentryTraceRate: config.ufloat('sentry-trace-rate', 0.05),
enableMetrics: config.bool('enable-metrics', false),
})
await service.start()
......
......@@ -106,26 +106,29 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
private _initializeApp() {
// TODO: Maybe pass this in as a parameter instead of creating it here?
this.state.app = express()
if (this.options.ethNetworkName) {
this._initMonitoring()
if (this.options.useSentry) {
this._initSentry()
}
if (this.options.enableMetrics) {
this._initMetrics()
}
this.state.app.use(cors())
this._registerAllRoutes()
// Sentry error handling must be after all controllers
// and before other error middleware
if (this.options.ethNetworkName) {
if (this.options.useSentry) {
this.state.app.use(Sentry.Handlers.errorHandler())
}
}
/**
* Initialize Sentry and Prometheus metrics for deployed instances
* Initialize Sentry and related middleware
*/
private _initMonitoring() {
// Init Sentry options
private _initSentry() {
Sentry.init({
dsn: this.options.sentryDsn,
release: this.options.release,
environment: this.options.ethNetworkName,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({
......@@ -136,7 +139,12 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
})
this.state.app.use(Sentry.Handlers.requestHandler())
this.state.app.use(Sentry.Handlers.tracingHandler())
// Init metrics
}
/**
* Initialize Prometheus metrics collection and endpoint
*/
private _initMetrics() {
this.metrics = new Metrics({
prefix: this.name,
labels: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment