-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[connector/spanmetricsconnector] add separate additional dimensions for calls and duration metrics #39134
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
[connector/spanmetricsconnector] add separate additional dimensions for calls and duration metrics #39134
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: spanmetricsconnector | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Separate Dimensions for calls and duration metrics | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36805] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
Add two new fields to the settings: `histogram.dimensions` and `calls_dimensions`. | ||
Use them to add independent dimensions to the duration and calls metrics. | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -74,6 +74,12 @@ type connectorImp struct { | |||
// Event dimensions to add to the events metric. | ||||
eDimensions []utilattri.Dimension | ||||
|
||||
// Calls dimensions to add to the events metric. | ||||
callsDimensions []utilattri.Dimension | ||||
|
||||
// duration dimensions to add to the events metric. | ||||
durationDimensions []utilattri.Dimension | ||||
|
||||
events EventsConfig | ||||
|
||||
// Tracks the last TimestampUnixNano for delta metrics so that they represent an uninterrupted series. Unused for cumulative span metrics. | ||||
|
@@ -144,6 +150,8 @@ func newConnector(logger *zap.Logger, config component.Config, clock clockwork.C | |||
ticker: clock.NewTicker(cfg.MetricsFlushInterval), | ||||
done: make(chan struct{}), | ||||
eDimensions: newDimensions(cfg.Events.Dimensions), | ||||
callsDimensions: newDimensions(cfg.CallsDimensions), | ||||
durationDimensions: newDimensions(cfg.Histogram.Dimensions), | ||||
events: cfg.Events, | ||||
}, nil | ||||
} | ||||
|
@@ -390,9 +398,11 @@ func (p *connectorImp) aggregateMetrics(traces ptrace.Traces) { | |||
duration = float64(endTime-startTime) / float64(unitDivider) | ||||
} | ||||
|
||||
key := p.buildKey(serviceName, span, p.dimensions, resourceAttr) | ||||
callsDimensions := p.dimensions | ||||
callsDimensions = append(callsDimensions, p.callsDimensions...) | ||||
key := p.buildKey(serviceName, span, callsDimensions, resourceAttr) | ||||
attributesFun := func() pcommon.Map { | ||||
return p.buildAttributes(serviceName, span, resourceAttr, p.dimensions, ils.Scope()) | ||||
return p.buildAttributes(serviceName, span, resourceAttr, callsDimensions, ils.Scope()) | ||||
} | ||||
|
||||
// aggregate sums metrics | ||||
|
@@ -404,7 +414,13 @@ func (p *connectorImp) aggregateMetrics(traces ptrace.Traces) { | |||
|
||||
// aggregate histogram metrics | ||||
if !p.config.Histogram.Disable { | ||||
h, durationLimitReached := histograms.GetOrCreate(key, attributesFun, startTimestamp) | ||||
durationDimensions := p.dimensions | ||||
durationDimensions = append(durationDimensions, p.durationDimensions...) | ||||
durationKey := p.buildKey(serviceName, span, durationDimensions, resourceAttr) | ||||
attributesFun = func() pcommon.Map { | ||||
return p.buildAttributes(serviceName, span, resourceAttr, durationDimensions, ils.Scope()) | ||||
} | ||||
h, durationLimitReached := histograms.GetOrCreate(durationKey, attributesFun, startTimestamp) | ||||
if !durationLimitReached && p.config.Exemplars.Enabled && !span.TraceID().IsEmpty() { | ||||
p.addExemplar(span, duration, h) | ||||
} | ||||
|
@@ -422,9 +438,9 @@ func (p *connectorImp) aggregateMetrics(traces ptrace.Traces) { | |||
|
||||
rscAndEventAttrs.EnsureCapacity(resourceAttr.Len() + event.Attributes().Len()) | ||||
resourceAttr.CopyTo(rscAndEventAttrs) | ||||
// We cannot use CopyTo because it overrides the existing keys. | ||||
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 think we should keep this comment because what cannot be done is to do 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. Note that On the other hand, using A better alternative is to use For a similar use case:
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 agree with your comments and fine changing this from The reason why I would like to preserve the comment is because I don't want somebody in the future replace this: event.Attributes().Range(func(k string, v pcommon.Value) bool {
v.CopyTo(rscAndEventAttrs.PutEmpty(k))
return true
}) with this: event.Attributes().CopyTo(rscAdnEventAttrs) and introduce a regression. Because it is not obvious that |
||||
// We cannot use event.Attributes().CopyTo(rscAdnEventAttrs) because it overrides the existing keys. | ||||
event.Attributes().Range(func(k string, v pcommon.Value) bool { | ||||
rscAndEventAttrs.PutStr(k, v.Str()) | ||||
v.CopyTo(rscAndEventAttrs.PutEmpty(k)) | ||||
return true | ||||
}) | ||||
|
||||
|
Uh oh!
There was an error while loading. Please reload this page.