Files
PandeyandGitHub 070c294f33 refactor(ledger): extract domain primitives and centralize tracking (#113)
## Summary

- Extract \`DistinctID\`, \`Event\`, and \`Properties\` value objects
from \`internal/ledger\` into \`internal/domain\` so they can be reused
without coupling callers to ledger orchestration. Move the analytics
serializer to \`api/v1alpha1\` as \`Casting.TrackableProperties()\`.
Tighten \`Ledger.Track\` to take \`domain.Event\` and
\`domain.Properties\`.
- Add \`cmd/foundryctl/root.go\` with shared
\`rootLogger\`/\`rootTracker\` initialized via \`PersistentPreRunE\`,
plus \`recoverRunE\` — a wrapper that converts panics to \`TypeFatal\`
errors and centralizes log + ledger tracking of success/failure for
every command. Each \`runX\` collapses to \`(domain.Properties, error)\`
with no in-function tracking.
- Add \`WithStacktrace\` on \`*base\` errors so the recovered panic
stack flows through the existing \`LogAttr\` machinery.
2026-05-04 23:36:04 +05:30

36 lines
752 B
Go

package ledger
// key is the Segment write key, set via ldflags at build time.
// Example: -ldflags "-X github.com/signoz/foundry/internal/ledger.key=<key>".
var key string = "<unset>"
// Config holds ledger configuration.
type Config struct {
Enabled bool
Segment Segment
}
// Segment holds Segment-specific configuration.
type Segment struct {
Key string
}
// NewConfig returns the default ledger configuration.
// The Segment write key is populated from the ldflags-injected value.
func NewConfig() Config {
return Config{
Enabled: true,
Segment: Segment{
Key: key,
},
}
}
// Provider returns the provider name based on the configuration.
func (c Config) Provider() string {
if c.Enabled {
return "segment"
}
return "noop"
}