@@ -41,7 +41,7 @@ const (
41
41
)
42
42
43
43
// Implements[T any] provides a common structure for components,
44
- // with logging capabilities and a reference to the component's interface.
44
+ // with logging/tracing/metrics capabilities and a reference to the component's interface.
45
45
type Implements [T any ] struct {
46
46
name string
47
47
log * slog.Logger
@@ -54,12 +54,12 @@ func (i *Implements[T]) L(ctx context.Context) *slog.Logger {
54
54
return kslog .LogWithContext (ctx , i .log )
55
55
}
56
56
57
- // T return the associated tracer.
57
+ // Tracer return the associated tracer.
58
58
func (i * Implements [T ]) Tracer (opts ... trace.TracerOption ) trace.Tracer {
59
59
return otel .Tracer (i .name , opts ... )
60
60
}
61
61
62
- // M return the associated meter.
62
+ // Meter return the associated meter.
63
63
func (i * Implements [T ]) Meter (opts ... metric.MeterOption ) metric.Meter {
64
64
return otel .GetMeterProvider ().Meter (i .name , opts ... )
65
65
}
@@ -68,7 +68,7 @@ func (i *Implements[T]) Meter(opts ...metric.MeterOption) metric.Meter {
68
68
// nolint
69
69
func (i * Implements [T ]) setLogger (name string , log * slog.Logger ) {
70
70
i .name = name
71
- i .log = log .With ("component" , name )
71
+ i .log = log .With (slog . String ( "component" , name ) )
72
72
}
73
73
74
74
// implements is a marker method to assert implementation of an interface.
@@ -256,6 +256,12 @@ func WithLogger(logger *slog.Logger) func(*options) {
256
256
}
257
257
}
258
258
259
+ // MustRun is a helper function to run the application with the provided main component and options.
260
+ // It panics if an error occurs during the execution.
261
+ func MustRun [T any , P PointerToMain [T ]](ctx context.Context , run func (context.Context , * T ) error , opts ... func (* options )) {
262
+ lo .Must0 (Run [T , P ](ctx , run , opts ... ))
263
+ }
264
+
259
265
// Run initializes and runs the application with the provided main component and options.
260
266
func Run [T any , _ PointerToMain [T ]](ctx context.Context , run func (context.Context , * T ) error , opts ... func (* options )) error {
261
267
// Create a new Kod instance.
0 commit comments