-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 { 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
})
registerInstrumentations({
- tracerProvider: tracerProvider,
+ tracerProvider,
instrumentations: [
new PgInstrumentation({
enhancedDatabaseReporting: true
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
}