From 38f1191cf4eb3b6a1b0bb9eaa185d5cf159cd274 Mon Sep 17 00:00:00 2001 From: Juan P Lopez Date: Thu, 21 Mar 2024 09:31:47 -0500 Subject: [PATCH] feat(realtime): add tracing filter --- realtime/src/app/index.ts | 1 + realtime/src/config/process.ts | 1 + realtime/src/domain/primitives/errors.ts | 6 ++++-- realtime/src/services/tracing.ts | 11 +++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/realtime/src/app/index.ts b/realtime/src/app/index.ts index 020a2ce..13f2855 100644 --- a/realtime/src/app/index.ts +++ b/realtime/src/app/index.ts @@ -11,6 +11,7 @@ for (const subModule in allFunctions) { allFunctions[subModule][fn] = wrapAsyncToRunInSpan({ namespace: `app.${subModule.toLowerCase()}`, fn: allFunctions[subModule][fn], + root: true, }) } } diff --git a/realtime/src/config/process.ts b/realtime/src/config/process.ts index f20c5d9..c8204e7 100644 --- a/realtime/src/config/process.ts +++ b/realtime/src/config/process.ts @@ -1,3 +1,4 @@ export const tracingConfig = { otelServiceName: process.env.OTEL_SERVICE_NAME || "galoy-price-dev", + enableFilter: process.env.TRACING_ENABLE_FILTER === "true", } diff --git a/realtime/src/domain/primitives/errors.ts b/realtime/src/domain/primitives/errors.ts index e3ad105..df957a4 100644 --- a/realtime/src/domain/primitives/errors.ts +++ b/realtime/src/domain/primitives/errors.ts @@ -1,5 +1,7 @@ -import { DomainError } from "@domain/errors" +import { DomainError, ErrorLevel } from "@domain/errors" class PrimitivesError extends DomainError {} -export class InvalidCurrencyError extends PrimitivesError {} +export class InvalidCurrencyError extends PrimitivesError { + level = ErrorLevel.Warn +} diff --git a/realtime/src/services/tracing.ts b/realtime/src/services/tracing.ts index 4501a8b..aaac074 100644 --- a/realtime/src/services/tracing.ts +++ b/realtime/src/services/tracing.ts @@ -64,6 +64,17 @@ class SpanProcessorWrapper extends SimpleSpanProcessor { } super.onStart(span, parentContext) } + + onEnd(span: SdkSpan) { + if (tracingConfig.enableFilter) { + const errorLevel = span.attributes["error.level"] + if (!errorLevel || errorLevel === ErrorLevel.Info) { + return // Ignore the span if it has no error or if error is info level + } + } + + super.onEnd(span) + } } provider.addSpanProcessor(new SpanProcessorWrapper(new OTLPTraceExporter()))