Skip to content

[SMT-0001]: task-local metrics factory proposal implementation draft#196

Draft
kukushechkin wants to merge 32 commits intoapple:mainfrom
kukushechkin:task-local-factory
Draft

[SMT-0001]: task-local metrics factory proposal implementation draft#196
kukushechkin wants to merge 32 commits intoapple:mainfrom
kukushechkin:task-local-factory

Conversation

@kukushechkin
Copy link
Contributor

Add task-local factory override for metrics to enable testing code that creates and emits metrics without global state
pollution. The factory is captured at metric creation time and used for the metric's entire lifetime.

Motivation:

Testing code that creates and emits metrics currently requires either:

  • Bootstrapping a test factory globally, which prevents parallel test execution and pollutes test state across tests.
  • Passing factory explicitly through the API boundaries, which pollutes API of internal methods and libraries.

Modifications:

Add MetricsSystem.with(factory:) method that binds a factory to task-local context. Metrics created within this
context use the task-local factory instead of the global factory.

Result:

Metrics can be used and tests without global metrics factory bootstrapping and explicit factory propagation though dependency injection.

@kukushechkin kukushechkin added the 🆕 semver/minor Adds new public API. label Feb 16, 2026
@kukushechkin kukushechkin changed the title [SMT-0001]: task-local metric factory proposal implementation draft [SMT-0001]: task-local metrics factory proposal implementation draft Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant