feat(tracing): add type-state builder pattern for configuration#259
Draft
feat(tracing): add type-state builder pattern for configuration#259
Conversation
6c10672 to
4e67cc8
Compare
Implements a fluent builder pattern with compile-time guarantees for configuring tracing/logging features. Key improvements: - Type-state pattern ensures mutually exclusive telemetry backends (OTLP vs Google Cloud) - Compile-time validation of configuration flow - Support for custom service names in telemetry - Flexible filter configuration (custom, env var, or defaults) - Maintains backward compatibility with existing init() function The builder enforces single-direction configuration flow and prevents invalid combinations at compile time, making the API more intuitive and error-proof. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unnecessary configure() method from TracingBuilder
- Make telemetry methods (otlp() and gcloud()) directly available on TracingBuilder
- Simplify the API flow for better developer experience
- Remove unused type-state markers and PhantomData since they're no longer needed
- Update examples to reflect the cleaner API
The new API is more intuitive:
TracingBuilder::new()
.with_service_name("my-service")
.otlp()
.with_endpoint("http://localhost:4317")
.build()
Instead of:
TracingBuilder::new()
.with_service_name("my-service")
.configure()
.with_telemetry()
.otlp()
.with_endpoint("http://localhost:4317")
.build()
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Implement compile-time enforcement for log format selection using type-state pattern:
- Log format must now be chosen first via .json() or .full() methods
- Filter and service configuration only available after format is selected
- Telemetry methods (otlp/gcloud) only accessible after format is set
- Maintains backward compatibility through internal with_format() helper
This ensures users cannot accidentally build without specifying a format,
catching configuration errors at compile time rather than runtime.
Example:
TracingBuilder::new()
.json() // Must choose format first
.with_service_name("my-service")
.build()
The compiler will reject:
TracingBuilder::new()
.with_service_name("my-service") // Error: method not found
.build()
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
34dfd8b to
81752a6
Compare
e3bd68b to
e897bbb
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.
Summary
Implements a fluent builder pattern with compile-time guarantees for configuring tracing/logging features in the
katana-tracingcrate.Motivation
The current tracing initialization uses a single
init()function that takes all configuration at once. This PR introduces a type-state builder pattern that:Changes
TracingBuilderwith type-state pattern for compile-time safetyinit()function to use builder internally (backward compatible)API Usage
Type-State Pattern Benefits
Testing
examples/builder_usage.rsBackward Compatibility
The existing
init()function is preserved and now uses the builder internally, ensuring no breaking changes for existing code.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com