Skip to content

Commit ac44497

Browse files
committed
percentage of span
Signed-off-by: Joe Elliott <number101010@gmail.com>
1 parent 495050b commit ac44497

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pkg/tracegen/templated.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ type Link struct {
107107
type Event struct {
108108
// Name of event
109109
Name string `js:"name"`
110+
// PercentageOfSpan if set controls where in the span the event is generated. If missing, the event is generated randomly
111+
PercentageOfSpan float32 `js:"percentageOfSpan"`
110112
// Attributes for this event
111113
Attributes map[string]interface{} `js:"attributes"`
112114
// Generate random attributes for this event
@@ -181,6 +183,7 @@ type internalLinkTemplate struct {
181183

182184
type internalEventTemplate struct {
183185
rate float32
186+
percentageOfSpan float32
184187
exceptionOnError bool
185188
name string
186189
attributes map[string]interface{}
@@ -314,7 +317,13 @@ func (g *TemplatedGenerator) generateSpan(scopeSpans ptrace.ScopeSpans, tmpl *in
314317
event.Attributes().EnsureCapacity(len(e.attributes) + len(e.randomAttributes))
315318

316319
event.SetName(e.name)
317-
eventTime := start.Add(random.Duration(0, duration))
320+
321+
var eventTime time.Time
322+
if e.percentageOfSpan > 0 {
323+
eventTime = start.Add(time.Duration(float64(duration) * float64(e.percentageOfSpan)))
324+
} else {
325+
eventTime = start.Add(random.Duration(0, duration))
326+
}
318327
event.SetTimestamp(pcommon.NewTimestampFromTime(eventTime))
319328

320329
for k, v := range e.attributes {
@@ -658,6 +667,7 @@ func (g *TemplatedGenerator) initializeEvents(tmplEvents []Event, randomEvents,
658667
event := internalEventTemplate{
659668
name: e.Name,
660669
attributes: e.Attributes,
670+
percentageOfSpan: e.PercentageOfSpan,
661671
randomAttributes: initializeRandomAttributes(e.RandomAttributes),
662672
}
663673
internalEvents = append(internalEvents, event)

0 commit comments

Comments
 (0)