aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-11 14:10:18 +0200
committerChocobozzz <me@florianbigard.com>2022-08-11 14:10:18 +0200
commit2a95b88477a547c319108c0bab8692624df6804c (patch)
treef464c7bb0a774b8d4b672edf023b9a8126787c91 /server/lib
parentab08ab4e284ad145de64ff9e1c9cf8149f701e29 (diff)
downloadPeerTube-2a95b88477a547c319108c0bab8692624df6804c.tar.gz
PeerTube-2a95b88477a547c319108c0bab8692624df6804c.tar.zst
PeerTube-2a95b88477a547c319108c0bab8692624df6804c.zip
Add spans for AP signature checkers
Diffstat (limited to 'server/lib')
-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}