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 ...@@ -28,5 +28,8 @@ DATA_TRANSPORT_LAYER__LEGACY_SEQUENCER_COMPATIBILITY=false
# Monitoring # Monitoring
# Leave the SENTRY_DSN variable unset during local development # Leave the SENTRY_DSN variable unset during local development
DATA_TRANSPORT_LAYER__USE_SENTRY=
DATA_TRANSPORT_LAYER__SENTRY_DSN= DATA_TRANSPORT_LAYER__SENTRY_DSN=
DATA_TRANSPORT_LAYER__SENTRY_TRACE_RATE= DATA_TRANSPORT_LAYER__SENTRY_TRACE_RATE=
DATA_TRANSPORT_LAYER__ENABLE_METRICS=
...@@ -28,8 +28,10 @@ export interface L1DataTransportServiceOptions { ...@@ -28,8 +28,10 @@ export interface L1DataTransportServiceOptions {
syncFromL2?: boolean syncFromL2?: boolean
transactionsPerPollingInterval: number transactionsPerPollingInterval: number
legacySequencerCompatibility: boolean legacySequencerCompatibility: boolean
useSentry?: boolean
sentryDsn?: string sentryDsn?: string
sentryTraceRate?: number sentryTraceRate?: number
enableMetrics?: boolean
defaultBackend: string defaultBackend: string
} }
......
...@@ -46,8 +46,10 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli' ...@@ -46,8 +46,10 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli'
false false
), ),
defaultBackend: config.str('default-backend', 'l1'), defaultBackend: config.str('default-backend', 'l1'),
useSentry: config.bool('use-sentry', false),
sentryDsn: config.str('sentry-dsn'), sentryDsn: config.str('sentry-dsn'),
sentryTraceRate: config.ufloat('sentry-trace-rate', 0.05), sentryTraceRate: config.ufloat('sentry-trace-rate', 0.05),
enableMetrics: config.bool('enable-metrics', false),
}) })
await service.start() await service.start()
......
...@@ -106,26 +106,29 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> { ...@@ -106,26 +106,29 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
private _initializeApp() { private _initializeApp() {
// TODO: Maybe pass this in as a parameter instead of creating it here? // TODO: Maybe pass this in as a parameter instead of creating it here?
this.state.app = express() this.state.app = express()
if (this.options.ethNetworkName) { if (this.options.useSentry) {
this._initMonitoring() this._initSentry()
}
if (this.options.enableMetrics) {
this._initMetrics()
} }
this.state.app.use(cors()) this.state.app.use(cors())
this._registerAllRoutes() this._registerAllRoutes()
// Sentry error handling must be after all controllers // Sentry error handling must be after all controllers
// and before other error middleware // and before other error middleware
if (this.options.ethNetworkName) { if (this.options.useSentry) {
this.state.app.use(Sentry.Handlers.errorHandler()) this.state.app.use(Sentry.Handlers.errorHandler())
} }
} }
/** /**
* Initialize Sentry and Prometheus metrics for deployed instances * Initialize Sentry and related middleware
*/ */
private _initMonitoring() { private _initSentry() {
// Init Sentry options
Sentry.init({ Sentry.init({
dsn: this.options.sentryDsn, dsn: this.options.sentryDsn,
release: this.options.release, release: this.options.release,
environment: this.options.ethNetworkName,
integrations: [ integrations: [
new Sentry.Integrations.Http({ tracing: true }), new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({ new Tracing.Integrations.Express({
...@@ -136,7 +139,12 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> { ...@@ -136,7 +139,12 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
}) })
this.state.app.use(Sentry.Handlers.requestHandler()) this.state.app.use(Sentry.Handlers.requestHandler())
this.state.app.use(Sentry.Handlers.tracingHandler()) this.state.app.use(Sentry.Handlers.tracingHandler())
// Init metrics }
/**
* Initialize Prometheus metrics collection and endpoint
*/
private _initMetrics() {
this.metrics = new Metrics({ this.metrics = new Metrics({
prefix: this.name, prefix: this.name,
labels: { 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