Repository navigation
perf(tracing): make exporter and sampler configurable, sanitize db spans, and flush on shutdown - #1637
Open
comandanto wants to merge 2 commits into
Open
perf(tracing): make exporter and sampler configurable, sanitize db spans, and flush on shutdown#1637comandanto wants to merge 2 commits into
comandanto wants to merge 2 commits into
Conversation
…nant budget and per-pool maps Closes CredenceOrg#1601 - Removed duplicate pg import on lines 1-2 - Rewrote withTenantConnectionBudget to support callback form of connect() needed by pg-pool query() - Synchronously reserve budget slot before connect to avoid concurrency race condition - Guaranteed release() idempotency with per-client flag and rollback on connect rejection - Isolated connection budget maps per pool instance (pool, workerPool, replicaPool) - Extended __poolTestHooks to support per-pool tenant count introspection - Added comprehensive unit test suite in src/db/pool.tenantBudget.test.ts
…ans, and flush on shutdown Closes CredenceOrg#1627 - Add OTEL_TRACES_EXPORTER ('none' | 'console' | 'otlp'), OTEL_EXPORTER_OTLP_ENDPOINT, and OTEL_TRACES_SAMPLER_RATIO config with zod validation - Support data-driven exporter (OTLPTraceExporter, ConsoleSpanExporter, none) and ParentBasedSampler in initTracing() - Sanitize database spans: truncate db.statement to 1024 chars, exception.message to 256 chars, and strip stacktrace/detail - Register tracer provider shutdown in GracefulShutdownManager with a 2000ms timeout race - Add comprehensive test coverage across tracer, config, query tracing, and graceful shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1627
This PR replaces hardcoded stdout tracing with data-driven exporter and sampler configuration, sanitizes database span attributes against data leakage, and ensures in-flight spans flush cleanly during graceful shutdown.
Key Changes
src/config/index.ts):OTEL_TRACES_EXPORTER:'none' | 'console' | 'otlp'. Default:'none'in production (NODE_ENV === 'production'),'console'in dev/test.OTEL_EXPORTER_OTLP_ENDPOINT: URL required whenOTEL_TRACES_EXPORTER === 'otlp'(enforced via.superRefine).OTEL_TRACES_SAMPLER_RATIO: Float[0.0, 1.0]. Default:0.1in production,1.0in dev/test.src/tracing/tracer.ts):OTLPTraceExporter(@opentelemetry/exporter-trace-otlp-http@^0.57.0) andConsoleSpanExporter.'none', registers zero span processors so span operations remain zero-overhead no-ops.ParentBasedSamplerwrappingTraceIdRatioBasedSampler(ratio).src/db/pool.ts):db.statementto 1,024 characters.exceptionevents to only include SQLSTATEcode(or error name) asexception.typeandexception.messagetruncated to 256 characters.exception.stacktraceand stripped Postgres query parameters/detail to avoid sensitive parameter exposure.src/gracefulShutdown.ts,src/index.ts):tracing_shutdownphase inGracefulShutdownManagerinvokingprovider.shutdown()with a 2,000 ms timeout race.initTracing()provider intoGracefulShutdownManager.Verification & Test Output
All 4 test suites (46 tests total) pass cleanly:
Production Mode Sample (Zero Span Dumps to Stdout)
No spans, SQL statements, or exception stack traces are written to stdout in production mode.