diff options
Diffstat (limited to 'server/lib')
-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 | } |