-import { diag, DiagLogLevel, trace } from '@opentelemetry/api'
+import { SequelizeInstrumentation } from 'opentelemetry-instrumentation-sequelize'
+import { context, diag, DiagLogLevel, trace } from '@opentelemetry/api'
import { JaegerExporter } from '@opentelemetry/exporter-jaeger'
import { registerInstrumentations } from '@opentelemetry/instrumentation'
import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns'
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'
import FsInstrumentation from '@opentelemetry/instrumentation-fs'
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'
+import { IORedisInstrumentation } from '@opentelemetry/instrumentation-ioredis'
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg'
-import { RedisInstrumentation } from '@opentelemetry/instrumentation-redis-4'
import { Resource } from '@opentelemetry/resources'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'
import { logger } from '@server/helpers/logger'
import { CONFIG } from '@server/initializers/config'
+const tracer = trace.getTracer('peertube')
+
function registerOpentelemetryTracing () {
if (CONFIG.OPEN_TELEMETRY.TRACING.ENABLED !== true) return
new DnsInstrumentation(),
new HttpInstrumentation(),
new ExpressInstrumentation(),
- new RedisInstrumentation({
+ new IORedisInstrumentation({
dbStatementSerializer: function (cmdName, cmdArgs) {
return [ cmdName, ...cmdArgs ].join(' ')
}
}),
- new FsInstrumentation()
+ new FsInstrumentation(),
+ new SequelizeInstrumentation()
]
})
tracerProvider.register()
}
-const tracer = trace.getTracer('peertube')
+async function wrapWithSpanAndContext <T> (spanName: string, cb: () => Promise<T>) {
+ const span = tracer.startSpan(spanName)
+ const activeContext = trace.setSpan(context.active(), span)
+
+ const result = await context.with(activeContext, () => cb())
+ span.end()
+
+ return result
+}
export {
registerOpentelemetryTracing,
- tracer
+ tracer,
+ wrapWithSpanAndContext
}