-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
73 lines (64 loc) · 2.22 KB
/
options.go
File metadata and controls
73 lines (64 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package stepmark
import "time"
// Option configures a tracer created by [New].
type Option func(*tracer)
// WithMaxEvents sets a hard cap on the total number of recorded
// events across all entities and unscoped events. Once the cap is
// reached, subsequent Record and RecordEntity calls are silently
// dropped. Zero (the default) means no limit.
func WithMaxEvents(n int) Option {
return func(t *tracer) {
t.maxEvents = n
}
}
// WithClock overrides the time source used for event timestamps.
// Useful for deterministic tests. The provided function must be
// safe for concurrent use.
func WithClock(fn func() time.Time) Option {
return func(t *tracer) {
t.clock = fn
}
}
// WithTraceMeta attaches metadata to the trace itself, not to any
// specific entity or event. Useful for request-level context like
// request IDs, user IDs, or experiment variants.
//
// ctx := stepmark.New(ctx, stepmark.WithTraceMeta(map[string]any{
// "request_id": reqID,
// "user_id": userID,
// }))
func WithTraceMeta(meta map[string]any) Option {
return func(t *tracer) {
t.meta = cloneMap(meta)
}
}
// EntityFilter decides whether an entity should be traced.
// Return true to trace the entity, false to skip it.
// Unscoped events recorded via [Record] are never filtered.
type EntityFilter func(entityID string) bool
// WithEntityFilter sets a predicate that controls which entities are
// traced. When the filter returns false for an entityID, all [Track],
// [RecordEntity], [StepEntity], and [EnterEntity] calls for that entity
// become no-ops.
//
// ctx := stepmark.New(ctx, stepmark.WithEntityFilter(func(id string) bool {
// return id == targetOrderID
// }))
func WithEntityFilter(fn EntityFilter) Option {
return func(t *tracer) {
t.entityFilter = fn
}
}
// TrackOption configures entity tracking via [Track].
type TrackOption func(*entityState)
// WithKind sets the entity's kind, allowing consumers to group or
// filter entities by type. The kind appears in the collected
// [EntityTrace.Kind] field.
//
// stepmark.Track(ctx, "prod_1", meta, stepmark.WithKind("product"))
// stepmark.Track(ctx, "order_9", meta, stepmark.WithKind("order"))
func WithKind(kind string) TrackOption {
return func(es *entityState) {
es.kind = kind
}
}