diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-11 14:10:18 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-11 14:10:18 +0200 |
commit | 2a95b88477a547c319108c0bab8692624df6804c (patch) | |
tree | f464c7bb0a774b8d4b672edf023b9a8126787c91 /server/lib/opentelemetry | |
parent | ab08ab4e284ad145de64ff9e1c9cf8149f701e29 (diff) | |
download | PeerTube-2a95b88477a547c319108c0bab8692624df6804c.tar.gz PeerTube-2a95b88477a547c319108c0bab8692624df6804c.tar.zst PeerTube-2a95b88477a547c319108c0bab8692624df6804c.zip |
Add spans for AP signature checkers
Diffstat (limited to 'server/lib/opentelemetry')
-rw-r--r-- | server/lib/opentelemetry/tracing.ts | 17 |
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 @@ | |||
1 | import { SequelizeInstrumentation } from 'opentelemetry-instrumentation-sequelize' | 1 | import { SequelizeInstrumentation } from 'opentelemetry-instrumentation-sequelize' |
2 | import { diag, DiagLogLevel, trace } from '@opentelemetry/api' | 2 | import { context, diag, DiagLogLevel, trace } from '@opentelemetry/api' |
3 | import { JaegerExporter } from '@opentelemetry/exporter-jaeger' | 3 | import { JaegerExporter } from '@opentelemetry/exporter-jaeger' |
4 | import { registerInstrumentations } from '@opentelemetry/instrumentation' | 4 | import { registerInstrumentations } from '@opentelemetry/instrumentation' |
5 | import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns' | 5 | import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns' |
@@ -15,6 +15,8 @@ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' | |||
15 | import { logger } from '@server/helpers/logger' | 15 | import { logger } from '@server/helpers/logger' |
16 | import { CONFIG } from '@server/initializers/config' | 16 | import { CONFIG } from '@server/initializers/config' |
17 | 17 | ||
18 | const tracer = trace.getTracer('peertube') | ||
19 | |||
18 | function registerOpentelemetryTracing () { | 20 | function 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 | ||
78 | const tracer = trace.getTracer('peertube') | 80 | async 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 | ||
80 | export { | 90 | export { |
81 | registerOpentelemetryTracing, | 91 | registerOpentelemetryTracing, |
82 | tracer | 92 | tracer, |
93 | wrapWithSpanAndContext | ||
83 | } | 94 | } |