Skip to content
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/spanmetrics] spanmetrics connector support exemplar #20772

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/k8sattribute-missing-attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# 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: fix spanmetrics connector to support adding exemplar to metric

# One or more tracking issues related to the change
issues: [20771]

# (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:
12 changes: 10 additions & 2 deletions connector/spanmetricsconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type span struct {
name string
kind ptrace.SpanKind
statusCode ptrace.StatusCode
traceID [16]byte
spanID [8]byte
}

// verifyConsumeMetricsInputCumulative expects one accumulation of metrics, and marked as cumulative
Expand Down Expand Up @@ -299,11 +301,15 @@ func buildSampleTrace() ptrace.Traces {
name: "/ping",
kind: ptrace.SpanKindServer,
statusCode: ptrace.StatusCodeOk,
traceID: [16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10},
spanID: [8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18},
},
{
name: "/ping",
kind: ptrace.SpanKindClient,
statusCode: ptrace.StatusCodeOk,
traceID: [16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10},
spanID: [8]byte{0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x10},
},
},
}, traces.ResourceSpans().AppendEmpty())
Expand All @@ -315,6 +321,8 @@ func buildSampleTrace() ptrace.Traces {
name: "/ping",
kind: ptrace.SpanKindServer,
statusCode: ptrace.StatusCodeError,
traceID: [16]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x10},
spanID: [8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18},
},
},
}, traces.ResourceSpans().AppendEmpty())
Expand Down Expand Up @@ -351,8 +359,8 @@ func initSpan(span span, s ptrace.Span) {
s.Attributes().PutEmpty(nullAttrName)
s.Attributes().PutEmptyMap(mapAttrName)
s.Attributes().PutEmptySlice(arrayAttrName)
s.SetTraceID(pcommon.TraceID([16]byte{byte(42)}))
s.SetSpanID(pcommon.SpanID([8]byte{byte(42)}))
s.SetTraceID(pcommon.TraceID(span.traceID))
s.SetSpanID(pcommon.SpanID(span.spanID))
}

func explicitHistogramsConfig() HistogramConfig {
Expand Down
10 changes: 6 additions & 4 deletions connector/spanmetricsconnector/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ func (m *explicitHistogramMetrics) BuildMetrics(
dp.BucketCounts().FromRaw(h.bucketCounts)
dp.SetCount(h.count)
dp.SetSum(h.sum)
for i := 0; i < dp.Exemplars().Len(); i++ {
dp.Exemplars().At(i).SetTimestamp(timestamp)
for i := 0; i < h.exemplars.Len(); i++ {
h.exemplars.At(i).SetTimestamp(timestamp)
}
h.exemplars.CopyTo(dp.Exemplars())
h.attributes.CopyTo(dp.Attributes())
}
}
Expand Down Expand Up @@ -162,9 +163,10 @@ func (m *exponentialHistogramMetrics) BuildMetrics(
dp.SetStartTimestamp(start)
dp.SetTimestamp(timestamp)
expoHistToExponentialDataPoint(m.histogram, dp)
for i := 0; i < dp.Exemplars().Len(); i++ {
dp.Exemplars().At(i).SetTimestamp(timestamp)
for i := 0; i < m.exemplars.Len(); i++ {
m.exemplars.At(i).SetTimestamp(timestamp)
}
m.exemplars.CopyTo(dp.Exemplars())
m.attributes.CopyTo(dp.Attributes())
}
}
Expand Down