Skip to content

Commit

Permalink
feat(realtime): add tracing filter (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi authored Mar 21, 2024
1 parent 5f4c165 commit 70bda11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions realtime/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ for (const subModule in allFunctions) {
allFunctions[subModule][fn] = wrapAsyncToRunInSpan({
namespace: `app.${subModule.toLowerCase()}`,
fn: allFunctions[subModule][fn],
root: true,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions realtime/src/config/process.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const tracingConfig = {
otelServiceName: process.env.OTEL_SERVICE_NAME || "galoy-price-dev",
enableFilter: process.env.TRACING_ENABLE_FILTER === "true",
}
6 changes: 4 additions & 2 deletions realtime/src/domain/primitives/errors.ts
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions realtime/src/services/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 70bda11

Please sign in to comment.