Repository navigation
fix: stop tracing the internals of Nest's validation pipes and ConfigService - #78
Merged
Merged
Conversation
validate on Nest's validation pipes
kamilmysliwiec
force-pushed
the
fix/enhancer-entry-spans
branch
2 times, most recently
from
November 7, 2026 08:37
5a972f8 to
00c4c23
Compare
…Service `ValidationPipe` runs once per handler argument, and each run was three spans of a few microseconds: `transform`, `toValidate` and `transformPrimitive`. Across the hosted platform 82% of runs never reached `validate`, and the pipe was the busiest class after `pg`. Each `ConfigService.get` likewise made four or five spans of private helpers, 2.7M of its 4.6M a day. Folding can't reach either, because each repeats only a few times under its parent. On `ValidationPipe`, `StandardSchemaValidationPipe` and `ParseFilePipe` only `validate` is a span now, and on `ConfigService` only its public methods. What an application adds or overrides in a subclass is still traced, and so is everything on guards, interceptors, filters, Nest's other pipes and the classes an application wrote.
validate on Nest's validation pipes
kamilmysliwiec
force-pushed
the
fix/enhancer-entry-spans
branch
from
November 7, 2026 09:07
00c4c23 to
8ace666
Compare
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.
Two library classes make a burst of spans nobody reads.
ValidationPiperuns once per handler argument, and the agent made a span for every method it calls:transform,toValidateandtransformPrimitive, a few microseconds each and each one billed. On 11-06 it was the busiest class afterpg: 12.5M of 241.7M class-attributed calls (5.2%), in 297 of 638 projects.validatewas reached on only 649k of 3.54M runs. On one REST app, 404,552 of 404,652 runs never reached it, and the pipe made about 40% of that app's class spans.ConfigService(@nestjs/config) made 4.6M calls that day, in 220 projects. 2.7M of them were its private helpers (getFromInternalConfig,getFromValidatedEnv,isGetOptionsObject,getFromProcessEnv,setInCacheIfDefined,getFromCache), four or five behind eachget.Folding can't reach either, because it needs the same method more than 20 times under one parent. Together this removes about 14.5M spans a day, about 6% of class-attributed calls.
The change
ValidationPipe,StandardSchemaValidationPipeandParseFilePipe, onlyvalidateis a span. A run that validates nothing makes no span at all.ConfigService, only its public methods are spans:get,getOrThrow,setandsetEnvFilePaths. AgetOrThrowstill shows thegetit calls.Everything else is traced as before: guards, interceptors, filters, Nest's other pipes (such as
ParseIntPipe) and any class an application wrote.flattenValidationErrors,formatIssueMessages,validateFilesOrFile,getFromValidatedEnv).StandardSchemaValidationPipeisn't in every supported@nestjs/common, and an app may carry a second copy of a package.ValidationPipe, and plenty of apps have aConfigServiceof their own. Those must keep all their spans.this.validate()insidetransformmakes its span, including from a subclass.Tested
ValidationPipe,ParseFilePipeandStandardSchemaValidationPipe(skipped where it doesn't exist);ConfigServicewith @nestjs/config 4's shape;ValidationPipeand an app's ownConfigService;ParseIntPipe, a guard and an interceptor, unchanged.ConfigService: checked against the real @nestjs/config 4.0.2 with the built decorator.getandgetOrThrowwere the only spans. The SDK doesn't depend on that package, so this check isn't committed.src/instrument/validating-pipe-spans.int-spec.tsruns a real app with a globalValidationPipeand a guard, and fails without the fix.http-capture-scenarios, which uses none of these classes and passed 3 out of 3 reruns of that file alone. The same file flaked once in an earlier run.EADDRINUSEin the gRPC OpenTelemetry e2e spec.