-
Notifications
You must be signed in to change notification settings - Fork 13
Additional Support for setting fields #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,8 @@ type SpanTemplate struct { | |
| Service string `js:"service"` | ||
| // Name represents the name of the span. If empty, the name will be randomly generated. | ||
| Name *string `js:"name"` | ||
| // Status string sets the span status. "error", "ok" or "unset" are supported | ||
| Status *string `js:"status"` | ||
| // ParentIDX defines the index of the parent span in TraceTemplate.Spans. ParentIDX must be smaller than the | ||
| // own index. If empty, the parent is the span with the position directly before this span in TraceTemplate.Spans. | ||
| ParentIDX *int `js:"parentIdx"` | ||
|
|
@@ -105,6 +107,8 @@ type Link struct { | |
| type Event struct { | ||
| // Name of event | ||
| Name string `js:"name"` | ||
| // PercentageOfSpan if set controls where in the span the event is generated. If missing, the event is generated randomly | ||
| PercentageOfSpan float32 `js:"percentageOfSpan"` | ||
| // Attributes for this event | ||
| Attributes map[string]interface{} `js:"attributes"` | ||
| // Generate random attributes for this event | ||
|
|
@@ -154,6 +158,7 @@ type internalSpanTemplate struct { | |
| parent *internalSpanTemplate | ||
| name string | ||
| kind ptrace.SpanKind | ||
| status *ptrace.StatusCode | ||
| duration *Range | ||
| attributeSemantics *OTelSemantics | ||
| attributes map[string]interface{} | ||
|
|
@@ -178,6 +183,7 @@ type internalLinkTemplate struct { | |
|
|
||
| type internalEventTemplate struct { | ||
| rate float32 | ||
| percentageOfSpan float32 | ||
|
Comment on lines
185
to
+186
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| exceptionOnError bool | ||
| name string | ||
| attributes map[string]interface{} | ||
|
|
@@ -311,7 +317,13 @@ func (g *TemplatedGenerator) generateSpan(scopeSpans ptrace.ScopeSpans, tmpl *in | |
| event.Attributes().EnsureCapacity(len(e.attributes) + len(e.randomAttributes)) | ||
|
|
||
| event.SetName(e.name) | ||
| eventTime := start.Add(random.Duration(0, duration)) | ||
|
|
||
| var eventTime time.Time | ||
| if e.percentageOfSpan > 0 { | ||
| eventTime = start.Add(time.Duration(float64(duration) * float64(e.percentageOfSpan))) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be missing something here, but could you explain the rationale behind |
||
| } else { | ||
| eventTime = start.Add(random.Duration(0, duration)) | ||
| } | ||
| event.SetTimestamp(pcommon.NewTimestampFromTime(eventTime)) | ||
|
|
||
| for k, v := range e.attributes { | ||
|
|
@@ -322,6 +334,10 @@ func (g *TemplatedGenerator) generateSpan(scopeSpans ptrace.ScopeSpans, tmpl *in | |
| } | ||
| } | ||
|
|
||
| if tmpl.status != nil { | ||
| span.Status().SetCode(*tmpl.status) | ||
| } | ||
|
|
||
| // generate links | ||
| span.Links().EnsureCapacity(len(tmpl.links)) | ||
| for _, l := range tmpl.links { | ||
|
|
@@ -530,6 +546,20 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat | |
| } | ||
| span.attributes = util.MergeMaps(defaults.Attributes, tmpl.Attributes) | ||
|
|
||
| // set status | ||
| if tmpl.Status != nil { | ||
| var status ptrace.StatusCode | ||
| switch *tmpl.Status { | ||
| case "error": | ||
| status = ptrace.StatusCodeError | ||
| case "ok": | ||
| status = ptrace.StatusCodeOk | ||
| case "unset": | ||
| status = ptrace.StatusCodeUnset | ||
| } | ||
| span.status = &status | ||
| } | ||
|
|
||
| // set span name | ||
| if tmpl.Name != nil { | ||
| span.name = *tmpl.Name | ||
|
|
@@ -637,6 +667,7 @@ func (g *TemplatedGenerator) initializeEvents(tmplEvents []Event, randomEvents, | |
| event := internalEventTemplate{ | ||
| name: e.Name, | ||
| attributes: e.Attributes, | ||
| percentageOfSpan: e.PercentageOfSpan, | ||
| randomAttributes: initializeRandomAttributes(e.RandomAttributes), | ||
| } | ||
| internalEvents = append(internalEvents, event) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a couple of potential improvements here:
PercentageOfSpanis not setRateorEventRatefor clarity?