aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/opentelemetry
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/opentelemetry')
-rw-r--r--server/lib/opentelemetry/tracing.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/server/lib/opentelemetry/tracing.ts b/server/lib/opentelemetry/tracing.ts
index 252a3b664..b1c3bd173 100644
--- a/server/lib/opentelemetry/tracing.ts
+++ b/server/lib/opentelemetry/tracing.ts
@@ -1,5 +1,5 @@
1import { SequelizeInstrumentation } from 'opentelemetry-instrumentation-sequelize' 1import { SequelizeInstrumentation } from 'opentelemetry-instrumentation-sequelize'
2import { diag, DiagLogLevel, trace } from '@opentelemetry/api' 2import { context, diag, DiagLogLevel, trace } from '@opentelemetry/api'
3import { JaegerExporter } from '@opentelemetry/exporter-jaeger' 3import { JaegerExporter } from '@opentelemetry/exporter-jaeger'
4import { registerInstrumentations } from '@opentelemetry/instrumentation' 4import { registerInstrumentations } from '@opentelemetry/instrumentation'
5import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns' 5import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns'
@@ -15,6 +15,8 @@ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
15import { logger } from '@server/helpers/logger' 15import { logger } from '@server/helpers/logger'
16import { CONFIG } from '@server/initializers/config' 16import { CONFIG } from '@server/initializers/config'
17 17
18const tracer = trace.getTracer('peertube')
19
18function registerOpentelemetryTracing () { 20function registerOpentelemetryTracing () {
19 if (CONFIG.OPEN_TELEMETRY.TRACING.ENABLED !== true) return 21 if (CONFIG.OPEN_TELEMETRY.TRACING.ENABLED !== true) return
20 22
@@ -75,9 +77,18 @@ function registerOpentelemetryTracing () {
75 tracerProvider.register() 77 tracerProvider.register()
76} 78}
77 79
78const tracer = trace.getTracer('peertube') 80async function wrapWithSpanAndContext <T> (spanName: string, cb: () => Promise<T>) {
81 const span = tracer.startSpan(spanName)
82 const activeContext = trace.setSpan(context.active(), span)
83
84 const result = await context.with(activeContext, () => cb())
85 span.end()
86
87 return result
88}
79 89
80export { 90export {
81 registerOpentelemetryTracing, 91 registerOpentelemetryTracing,
82 tracer 92 tracer,
93 wrapWithSpanAndContext
83} 94}