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
6 changes: 6 additions & 0 deletions .changeset/four-gifts-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@eth-optimism/common-ts': patch
'@eth-optimism/data-transport-layer': patch
---

add environment and network to dtl, move metric init to app from base-service
5 changes: 1 addition & 4 deletions packages/common-ts/src/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class BaseService<T> {
this.name = name
this.options = mergeDefaultOptions(options, optionSettings)
this.logger = new Logger({ name })
this.metrics = new Metrics({ prefix: name })
}

/**
Expand All @@ -39,9 +38,7 @@ export class BaseService<T> {

this.logger.info('Service is initializing...')
await this._init()
this.logger.info('Service has initialized.', {
options: this.options,
})
this.logger.info('Service has initialized.')
this.initialized = true
}

Expand Down
4 changes: 4 additions & 0 deletions packages/data-transport-layer/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# General options
DATA_TRANSPORT_LAYER__NODE_ENV=development
# Leave blank during local development
DATA_TRANSPORT_LAYER__ETH_NETWORK_NAME=
DATA_TRANSPORT_LAYER__DB_PATH=./db
DATA_TRANSPORT_LAYER__ADDRESS_MANAGER=
DATA_TRANSPORT_LAYER__POLLING_INTERVAL=5000
Expand Down Expand Up @@ -26,3 +29,4 @@ DATA_TRANSPORT_LAYER__LEGACY_SEQUENCER_COMPATIBILITY=false
# Monitoring
# Leave the SENTRY_DSN variable unset during local development
DATA_TRANSPORT_LAYER__SENTRY_DSN=
DATA_TRANSPORT_LAYER__SENTRY_TRACE_RATE=
4 changes: 4 additions & 0 deletions packages/data-transport-layer/src/services/main/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { validators } from '../../utils'
import { L2IngestionService } from '../l2-ingestion/service'

export interface L1DataTransportServiceOptions {
nodeEnv: string
ethNetworkName?: 'mainnet' | 'kovan' | 'goerli'
release: string
addressManager: string
confirmations: number
dangerouslyCatchAllErrors?: boolean
Expand All @@ -26,6 +29,7 @@ export interface L1DataTransportServiceOptions {
transactionsPerPollingInterval: number
legacySequencerCompatibility: boolean
sentryDsn?: string
sentryTraceRate?: number
defaultBackend: string
}

Expand Down
6 changes: 6 additions & 0 deletions packages/data-transport-layer/src/services/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ interface Bcfg {
str: (name: string, defaultValue?: string) => string
uint: (name: string, defaultValue?: number) => number
bool: (name: string, defaultValue?: boolean) => boolean
ufloat: (name: string, defaultValue?: number) => number
}

type ethNetwork = 'mainnet' | 'kovan' | 'goerli'
;(async () => {
try {
dotenv.config()
Expand All @@ -23,6 +25,9 @@ interface Bcfg {
})

const service = new L1DataTransportService({
nodeEnv: config.str('node-env', 'development'),
ethNetworkName: config.str('eth-network-name') as ethNetwork,
release: `data-transport-layer@${process.env.npm_package_version}`,
dbPath: config.str('db-path', './db'),
port: config.uint('server-port', 7878),
hostname: config.str('server-hostname', 'localhost'),
Expand All @@ -49,6 +54,7 @@ interface Bcfg {
),
defaultBackend: config.str('default-backend', 'l1'),
sentryDsn: config.str('sentry-dsn'),
sentryTraceRate: config.ufloat('sentry-trace-rate', 0.05),
})

await service.start()
Expand Down
33 changes: 27 additions & 6 deletions packages/data-transport-layer/src/services/server/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Imports: External */
import { BaseService } from '@eth-optimism/common-ts'
import { BaseService, Metrics } from '@eth-optimism/common-ts'
import express, { Request, Response } from 'express'
import promBundle from 'express-prom-bundle'
import cors from 'cors'
Expand Down Expand Up @@ -106,29 +106,50 @@ 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()
}
this.state.app.use(cors())
this._registerAllRoutes()
// Sentry error handling must be after all controllers
// and before other error middleware
if (this.options.ethNetworkName) {
this.state.app.use(Sentry.Handlers.errorHandler())
}
}

/**
* Initialize Sentry and Prometheus metrics for deployed instances
*/
private _initMonitoring() {
// Init Sentry options
Sentry.init({
dsn: this.options.sentryDsn,
release: `data-transport-layer@${process.env.npm_package_version}`,
release: this.options.release,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({
app: this.state.app,
}),
],
tracesSampleRate: 0.05,
tracesSampleRate: this.options.sentryTraceRate,
})
this.state.app.use(Sentry.Handlers.requestHandler())
this.state.app.use(Sentry.Handlers.tracingHandler())
// Init metrics
this.metrics = new Metrics({
prefix: this.name,
labels: {
environment: this.options.nodeEnv,
network: this.options.ethNetworkName,
release: this.options.release,
},
})
const metricsMiddleware = promBundle({
includeMethod: true,
includePath: true,
})
this.state.app.use(metricsMiddleware)
this.state.app.use(cors())
this._registerAllRoutes()
this.state.app.use(Sentry.Handlers.errorHandler())
}

/**
Expand Down