diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a22de05291..ec8af9cba07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Remove testutil.WaitForPort, users can use testify.Eventually (#2926) - Rename `processorhelper.NewTraceProcessor` to `processorhelper.NewTracesProcessor` (#2935) - Rename `exporterhelper.NewTraceExporter` to `exporterhelper.NewTracesExporter` (#2937) +- Remove InitEmptyWithCapacity, add EnsureCapacity and Clear (#2845) ## 💡 Enhancements 💡 diff --git a/consumer/pdata/common.go b/consumer/pdata/common.go index 8b40accf7f5..e16ab622077 100644 --- a/consumer/pdata/common.go +++ b/consumer/pdata/common.go @@ -392,13 +392,20 @@ func (am AttributeMap) InitFromMap(attrMap map[string]AttributeValue) AttributeM return am } -// InitEmptyWithCapacity constructs an empty AttributeMap with predefined slice capacity. -func (am AttributeMap) InitEmptyWithCapacity(cap int) { - if cap == 0 { - *am.orig = []otlpcommon.KeyValue(nil) +// Clear erases any existing entries in this AttributeMap instance. +func (am AttributeMap) Clear() { + *am.orig = nil +} + +// EnsureCapacity increases the capacity of this AttributeMap instance, if necessary, +// to ensure that it can hold at least the number of elements specified by the capacity argument. +func (am AttributeMap) EnsureCapacity(capacity int) { + if capacity <= cap(*am.orig) { return } - *am.orig = make([]otlpcommon.KeyValue, 0, cap) + oldOrig := *am.orig + *am.orig = make([]otlpcommon.KeyValue, 0, capacity) + copy(*am.orig, oldOrig) } // Get returns the AttributeValue associated with the key and true. Returned @@ -685,13 +692,20 @@ func (sm StringMap) InitFromMap(attrMap map[string]string) StringMap { return sm } -// InitEmptyWithCapacity constructs an empty StringMap with predefined slice capacity. -func (sm StringMap) InitEmptyWithCapacity(cap int) { - if cap == 0 { - *sm.orig = []otlpcommon.StringKeyValue(nil) +// Clear erases any existing entries in this StringMap instance. +func (sm StringMap) Clear() { + *sm.orig = nil +} + +// EnsureCapacity increases the capacity of this StringMap instance, if necessary, +// to ensure that it can hold at least the number of elements specified by the capacity argument. +func (sm StringMap) EnsureCapacity(capacity int) { + if capacity <= cap(*sm.orig) { return } - *sm.orig = make([]otlpcommon.StringKeyValue, 0, cap) + oldOrig := *sm.orig + *sm.orig = make([]otlpcommon.StringKeyValue, 0, capacity) + copy(*sm.orig, oldOrig) } // Get returns the StringValue associated with the key and true, diff --git a/consumer/pdata/common_test.go b/consumer/pdata/common_test.go index 1a834484590..c2058e50ed8 100644 --- a/consumer/pdata/common_test.go +++ b/consumer/pdata/common_test.go @@ -669,11 +669,35 @@ func TestAttributeMap_Update(t *testing.T) { assert.EqualValues(t, 123, av2.IntVal()) } -func TestAttributeMap_InitEmptyWithCapacity(t *testing.T) { +func TestAttributeMap_EnsureCapacity_Zero(t *testing.T) { am := NewAttributeMap() - am.InitEmptyWithCapacity(0) - assert.Equal(t, NewAttributeMap(), am) + am.EnsureCapacity(0) assert.Equal(t, 0, am.Len()) + assert.Equal(t, 0, cap(*am.orig)) +} + +func TestAttributeMap_EnsureCapacity(t *testing.T) { + am := NewAttributeMap() + am.EnsureCapacity(5) + assert.Equal(t, 0, am.Len()) + assert.Equal(t, 5, cap(*am.orig)) + am.EnsureCapacity(3) + assert.Equal(t, 0, am.Len()) + assert.Equal(t, 5, cap(*am.orig)) + am.EnsureCapacity(8) + assert.Equal(t, 0, am.Len()) + assert.Equal(t, 8, cap(*am.orig)) +} + +func TestAttributeMap_Clear(t *testing.T) { + am := NewAttributeMap() + assert.Nil(t, *am.orig) + am.Clear() + assert.Nil(t, *am.orig) + am.EnsureCapacity(5) + assert.NotNil(t, *am.orig) + am.Clear() + assert.Nil(t, *am.orig) } func TestNilStringMap(t *testing.T) { @@ -846,11 +870,35 @@ func TestStringMap_CopyTo(t *testing.T) { assert.EqualValues(t, generateTestStringMap(), dest) } -func TestStringMap_InitEmptyWithCapacity(t *testing.T) { +func TestStringMap_EnsureCapacity_Zero(t *testing.T) { sm := NewStringMap() - sm.InitEmptyWithCapacity(0) - assert.Equal(t, NewStringMap(), sm) + sm.EnsureCapacity(0) assert.Equal(t, 0, sm.Len()) + assert.Equal(t, 0, cap(*sm.orig)) +} + +func TestStringMap_EnsureCapacity(t *testing.T) { + sm := NewStringMap() + sm.EnsureCapacity(5) + assert.Equal(t, 0, sm.Len()) + assert.Equal(t, 5, cap(*sm.orig)) + sm.EnsureCapacity(3) + assert.Equal(t, 0, sm.Len()) + assert.Equal(t, 5, cap(*sm.orig)) + sm.EnsureCapacity(8) + assert.Equal(t, 0, sm.Len()) + assert.Equal(t, 8, cap(*sm.orig)) +} + +func TestStringMap_Clear(t *testing.T) { + sm := NewStringMap() + assert.Nil(t, *sm.orig) + sm.Clear() + assert.Nil(t, *sm.orig) + sm.EnsureCapacity(5) + assert.NotNil(t, *sm.orig) + sm.Clear() + assert.Nil(t, *sm.orig) } func TestStringMap_InitFromMap(t *testing.T) { diff --git a/consumer/simple/metrics_test.go b/consumer/simple/metrics_test.go index 81e0f4256ff..5bee31ac9ef 100644 --- a/consumer/simple/metrics_test.go +++ b/consumer/simple/metrics_test.go @@ -504,7 +504,6 @@ func BenchmarkPdataMetrics(b *testing.B) { { dp := dps.At(0) labels := dp.LabelsMap() - labels.InitEmptyWithCapacity(3) labels.Insert("env", "prod") labels.Insert("app", "myapp") labels.Insert("version", "1.0") @@ -514,7 +513,6 @@ func BenchmarkPdataMetrics(b *testing.B) { { dp := dps.At(1) labels := dp.LabelsMap() - labels.InitEmptyWithCapacity(3) labels.Insert("env", "prod") labels.Insert("app", "myapp") labels.Insert("version", "1.0") diff --git a/exporter/opencensusexporter/opencensus_test.go b/exporter/opencensusexporter/opencensus_test.go index 9127ab0751d..a421ebeab50 100644 --- a/exporter/opencensusexporter/opencensus_test.go +++ b/exporter/opencensusexporter/opencensus_test.go @@ -76,14 +76,15 @@ func TestSendTraces(t *testing.T) { sink.Reset() // Sending data no Node. - td.ResourceSpans().At(0).Resource().Attributes().InitEmptyWithCapacity(0) + td.ResourceSpans().At(0).Resource().Attributes().Clear() + td = td.Clone() assert.NoError(t, exp.ConsumeTraces(context.Background(), td)) assert.Eventually(t, func() bool { return len(sink.AllTraces()) == 1 }, 10*time.Second, 5*time.Millisecond) traces = sink.AllTraces() require.Len(t, traces, 1) - assert.Equal(t, td, traces[0]) + assert.EqualValues(t, td, traces[0]) } func TestSendTraces_NoBackend(t *testing.T) { @@ -173,7 +174,7 @@ func TestSendMetrics(t *testing.T) { // Sending data no node. sink.Reset() - md.ResourceMetrics().At(0).Resource().Attributes().InitEmptyWithCapacity(0) + md.ResourceMetrics().At(0).Resource().Attributes().Clear() assert.NoError(t, exp.ConsumeMetrics(context.Background(), md)) assert.Eventually(t, func() bool { return len(sink.AllMetrics()) == 1 diff --git a/processor/resourceprocessor/resource_processor.go b/processor/resourceprocessor/resource_processor.go index a9595f0b243..7b591525074 100644 --- a/processor/resourceprocessor/resource_processor.go +++ b/processor/resourceprocessor/resource_processor.go @@ -29,9 +29,7 @@ type resourceProcessor struct { func (rp *resourceProcessor) ProcessTraces(_ context.Context, td pdata.Traces) (pdata.Traces, error) { rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { - resource := rss.At(i).Resource() - attrs := resource.Attributes() - rp.attrProc.Process(attrs) + rp.attrProc.Process(rss.At(i).Resource().Attributes()) } return td, nil } @@ -40,11 +38,7 @@ func (rp *resourceProcessor) ProcessTraces(_ context.Context, td pdata.Traces) ( func (rp *resourceProcessor) ProcessMetrics(_ context.Context, md pdata.Metrics) (pdata.Metrics, error) { rms := md.ResourceMetrics() for i := 0; i < rms.Len(); i++ { - resource := rms.At(i).Resource() - if resource.Attributes().Len() == 0 { - resource.Attributes().InitEmptyWithCapacity(1) - } - rp.attrProc.Process(resource.Attributes()) + rp.attrProc.Process(rms.At(i).Resource().Attributes()) } return md, nil } @@ -53,9 +47,7 @@ func (rp *resourceProcessor) ProcessMetrics(_ context.Context, md pdata.Metrics) func (rp *resourceProcessor) ProcessLogs(_ context.Context, ld pdata.Logs) (pdata.Logs, error) { rls := ld.ResourceLogs() for i := 0; i < rls.Len(); i++ { - resource := rls.At(i).Resource() - attrs := resource.Attributes() - rp.attrProc.Process(attrs) + rp.attrProc.Process(rls.At(i).Resource().Attributes()) } return ld, nil } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go index d432a7611fc..c49e0b00d97 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go @@ -49,45 +49,25 @@ type commandMetadata struct { func (m *processMetadata) initializeResource(resource pdata.Resource) { attr := resource.Attributes() - attr.InitEmptyWithCapacity(6) - m.insertPid(attr) - m.insertExecutable(attr) - m.insertCommand(attr) - m.insertUsername(attr) -} - -func (m *processMetadata) insertPid(attr pdata.AttributeMap) { + attr.EnsureCapacity(6) attr.InsertInt(conventions.AttributeProcessID, int64(m.pid)) -} - -func (m *processMetadata) insertExecutable(attr pdata.AttributeMap) { attr.InsertString(conventions.AttributeProcessExecutableName, m.executable.name) attr.InsertString(conventions.AttributeProcessExecutablePath, m.executable.path) -} - -func (m *processMetadata) insertCommand(attr pdata.AttributeMap) { - if m.command == nil { - return + if m.command != nil { + attr.InsertString(conventions.AttributeProcessCommand, m.command.command) + if m.command.commandLineSlice != nil { + // TODO insert slice here once this is supported by the data model + // (see https://github.com/open-telemetry/opentelemetry-collector/pull/1142) + attr.InsertString(conventions.AttributeProcessCommandLine, strings.Join(m.command.commandLineSlice, " ")) + } else { + attr.InsertString(conventions.AttributeProcessCommandLine, m.command.commandLine) + } } - - attr.InsertString(conventions.AttributeProcessCommand, m.command.command) - if m.command.commandLineSlice != nil { - // TODO insert slice here once this is supported by the data model - // (see https://github.com/open-telemetry/opentelemetry-collector/pull/1142) - attr.InsertString(conventions.AttributeProcessCommandLine, strings.Join(m.command.commandLineSlice, " ")) - } else { - attr.InsertString(conventions.AttributeProcessCommandLine, m.command.commandLine) + if m.username != "" { + attr.InsertString(conventions.AttributeProcessOwner, m.username) } } -func (m *processMetadata) insertUsername(attr pdata.AttributeMap) { - if m.username == "" { - return - } - - attr.InsertString(conventions.AttributeProcessOwner, m.username) -} - // processHandles provides a wrapper around []*process.Process // to support testing diff --git a/testbed/testbed/data_providers.go b/testbed/testbed/data_providers.go index 3e19dcb69c5..56af7ec2e91 100644 --- a/testbed/testbed/data_providers.go +++ b/testbed/testbed/data_providers.go @@ -128,7 +128,7 @@ func (dp *PerfTestDataProvider) GenerateMetrics() (pdata.Metrics, bool) { md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().Resize(1) if dp.options.Attributes != nil { attrs := md.ResourceMetrics().At(0).Resource().Attributes() - attrs.InitEmptyWithCapacity(len(dp.options.Attributes)) + attrs.EnsureCapacity(len(dp.options.Attributes)) for k, v := range dp.options.Attributes { attrs.UpsertString(k, v) } @@ -168,7 +168,7 @@ func (dp *PerfTestDataProvider) GenerateLogs() (pdata.Logs, bool) { logs.ResourceLogs().At(0).InstrumentationLibraryLogs().Resize(1) if dp.options.Attributes != nil { attrs := logs.ResourceLogs().At(0).Resource().Attributes() - attrs.InitEmptyWithCapacity(len(dp.options.Attributes)) + attrs.EnsureCapacity(len(dp.options.Attributes)) for k, v := range dp.options.Attributes { attrs.UpsertString(k, v) } diff --git a/translator/internaldata/oc_to_metrics.go b/translator/internaldata/oc_to_metrics.go index 3b05489ab46..84d1983e82c 100644 --- a/translator/internaldata/oc_to_metrics.go +++ b/translator/internaldata/oc_to_metrics.go @@ -238,7 +238,7 @@ func setDataPoints(ocMetric *ocmetrics.Metric, metric pdata.Metric) { } } -func setLabelsMap(ocLabelsKeys []*ocmetrics.LabelKey, ocLabelValues []*ocmetrics.LabelValue, labelsMap pdata.StringMap) { +func fillLabelsMap(ocLabelsKeys []*ocmetrics.LabelKey, ocLabelValues []*ocmetrics.LabelValue, labelsMap pdata.StringMap) { if len(ocLabelsKeys) == 0 || len(ocLabelValues) == 0 { return } @@ -250,7 +250,8 @@ func setLabelsMap(ocLabelsKeys []*ocmetrics.LabelKey, ocLabelValues []*ocmetrics lablesCount = len(ocLabelValues) } - labelsMap.InitEmptyWithCapacity(lablesCount) + labelsMap.Clear() + labelsMap.EnsureCapacity(lablesCount) for i := 0; i < lablesCount; i++ { if !ocLabelValues[i].GetHasValue() { continue @@ -280,7 +281,7 @@ func fillIntDataPoint(ocMetric *ocmetrics.Metric, dps pdata.IntDataPointSlice) { dp.SetStartTimestamp(startTimestamp) dp.SetTimestamp(pdata.TimestampFromTime(point.GetTimestamp().AsTime())) - setLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) + fillLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) dp.SetValue(point.GetInt64Value()) } } @@ -308,7 +309,7 @@ func fillDoubleDataPoint(ocMetric *ocmetrics.Metric, dps pdata.DoubleDataPointSl dp.SetStartTimestamp(startTimestamp) dp.SetTimestamp(pdata.TimestampFromTime(point.GetTimestamp().AsTime())) - setLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) + fillLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) dp.SetValue(point.GetDoubleValue()) } } @@ -336,7 +337,7 @@ func fillDoubleHistogramDataPoint(ocMetric *ocmetrics.Metric, dps pdata.Histogra dp.SetStartTimestamp(startTimestamp) dp.SetTimestamp(pdata.TimestampFromTime(point.GetTimestamp().AsTime())) - setLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) + fillLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) distributionValue := point.GetDistributionValue() dp.SetSum(distributionValue.GetSum()) dp.SetCount(uint64(distributionValue.GetCount())) @@ -368,7 +369,7 @@ func fillDoubleSummaryDataPoint(ocMetric *ocmetrics.Metric, dps pdata.SummaryDat dp.SetStartTimestamp(startTimestamp) dp.SetTimestamp(pdata.TimestampFromTime(point.GetTimestamp().AsTime())) - setLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) + fillLabelsMap(ocLabelsKeys, timeseries.LabelValues, dp.LabelsMap()) summaryValue := point.GetSummaryValue() dp.SetSum(summaryValue.GetSum().GetValue()) dp.SetCount(uint64(summaryValue.GetCount().GetValue())) @@ -414,12 +415,13 @@ func exemplarToMetrics(ocExemplar *ocmetrics.DistributionValue_Exemplar, exempla if ocExemplar.GetTimestamp() != nil { exemplar.SetTimestamp(pdata.TimestampFromTime(ocExemplar.GetTimestamp().AsTime())) } - exemplar.SetValue(ocExemplar.GetValue()) - attachments := exemplar.FilteredLabels() ocAttachments := ocExemplar.GetAttachments() - attachments.InitEmptyWithCapacity(len(ocAttachments)) + exemplar.SetValue(ocExemplar.GetValue()) + filteredLabels := exemplar.FilteredLabels() + filteredLabels.Clear() + filteredLabels.EnsureCapacity(len(ocAttachments)) for k, v := range ocAttachments { - attachments.Upsert(k, v) + filteredLabels.Upsert(k, v) } } diff --git a/translator/internaldata/oc_to_resource.go b/translator/internaldata/oc_to_resource.go index 87b9ed87c1e..2e15a428d21 100644 --- a/translator/internaldata/oc_to_resource.go +++ b/translator/internaldata/oc_to_resource.go @@ -80,7 +80,8 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso } attrs := dest.Attributes() - attrs.InitEmptyWithCapacity(maxTotalAttrCount) + attrs.Clear() + attrs.EnsureCapacity(maxTotalAttrCount) if ocNode != nil { // Copy all Attributes. diff --git a/translator/internaldata/oc_to_traces.go b/translator/internaldata/oc_to_traces.go index 866d1909a44..f4457bb1522 100644 --- a/translator/internaldata/oc_to_traces.go +++ b/translator/internaldata/oc_to_traces.go @@ -226,29 +226,24 @@ func ocAttrsToDroppedAttributes(ocAttrs *octrace.Span_Attributes) uint32 { // initAttributeMapFromOC initialize AttributeMap from OC attributes func initAttributeMapFromOC(ocAttrs *octrace.Span_Attributes, dest pdata.AttributeMap) { - if ocAttrs == nil { + if ocAttrs == nil || len(ocAttrs.AttributeMap) == 0 { return } - if len(ocAttrs.AttributeMap) > 0 { - dest.InitEmptyWithCapacity(len(ocAttrs.AttributeMap)) - for key, ocAttr := range ocAttrs.AttributeMap { - switch attribValue := ocAttr.Value.(type) { - case *octrace.AttributeValue_StringValue: - dest.UpsertString(key, attribValue.StringValue.GetValue()) - - case *octrace.AttributeValue_IntValue: - dest.UpsertInt(key, attribValue.IntValue) - - case *octrace.AttributeValue_BoolValue: - dest.UpsertBool(key, attribValue.BoolValue) - - case *octrace.AttributeValue_DoubleValue: - dest.UpsertDouble(key, attribValue.DoubleValue) - - default: - dest.UpsertString(key, "") - } + dest.Clear() + dest.EnsureCapacity(len(ocAttrs.AttributeMap)) + for key, ocAttr := range ocAttrs.AttributeMap { + switch attribValue := ocAttr.Value.(type) { + case *octrace.AttributeValue_StringValue: + dest.UpsertString(key, attribValue.StringValue.GetValue()) + case *octrace.AttributeValue_IntValue: + dest.UpsertInt(key, attribValue.IntValue) + case *octrace.AttributeValue_BoolValue: + dest.UpsertBool(key, attribValue.BoolValue) + case *octrace.AttributeValue_DoubleValue: + dest.UpsertDouble(key, attribValue.DoubleValue) + default: + dest.UpsertString(key, "") } } } diff --git a/translator/trace/jaeger/jaegerproto_to_traces.go b/translator/trace/jaeger/jaegerproto_to_traces.go index 5f11a4a3e1d..5e3f1d9b975 100644 --- a/translator/trace/jaeger/jaegerproto_to_traces.go +++ b/translator/trace/jaeger/jaegerproto_to_traces.go @@ -102,11 +102,12 @@ func jProcessToInternalResource(process *model.Process, dest pdata.Resource) { } attrs := dest.Attributes() + attrs.Clear() if serviceName != "" { - attrs.InitEmptyWithCapacity(len(tags) + 1) + attrs.EnsureCapacity(len(tags) + 1) attrs.UpsertString(conventions.AttributeServiceName, serviceName) } else { - attrs.InitEmptyWithCapacity(len(tags)) + attrs.EnsureCapacity(len(tags)) } jTagsToInternalAttributes(tags, attrs) @@ -176,7 +177,8 @@ func jSpanToInternal(span *model.Span) (pdata.Span, instrumentationLibrary) { } attrs := dest.Attributes() - attrs.InitEmptyWithCapacity(len(span.Tags)) + attrs.Clear() + attrs.EnsureCapacity(len(span.Tags)) jTagsToInternalAttributes(span.Tags, attrs) setInternalSpanStatus(attrs, dest.Status()) if spanKindAttr, ok := attrs.Get(tracetranslator.TagSpanKind); ok { @@ -332,7 +334,8 @@ func jLogsToSpanEvents(logs []model.Log, dest pdata.SpanEventSlice) { } attrs := event.Attributes() - attrs.InitEmptyWithCapacity(len(log.Fields)) + attrs.Clear() + attrs.EnsureCapacity(len(log.Fields)) jTagsToInternalAttributes(log.Fields, attrs) if name, ok := attrs.Get(tracetranslator.TagMessage); ok { event.SetName(name.StringVal()) diff --git a/translator/trace/jaeger/jaegerthrift_to_traces.go b/translator/trace/jaeger/jaegerthrift_to_traces.go index f097f25e710..2898ebf7d50 100644 --- a/translator/trace/jaeger/jaegerthrift_to_traces.go +++ b/translator/trace/jaeger/jaegerthrift_to_traces.go @@ -64,11 +64,12 @@ func jThriftProcessToInternalResource(process *jaeger.Process, dest pdata.Resour } attrs := dest.Attributes() + attrs.Clear() if serviceName != "" { - attrs.InitEmptyWithCapacity(len(tags) + 1) + attrs.EnsureCapacity(len(tags) + 1) attrs.UpsertString(conventions.AttributeServiceName, serviceName) } else { - attrs.InitEmptyWithCapacity(len(tags)) + attrs.EnsureCapacity(len(tags)) } jThriftTagsToInternalAttributes(tags, attrs) @@ -110,7 +111,8 @@ func jThriftSpanToInternal(span *jaeger.Span, dest pdata.Span) { } attrs := dest.Attributes() - attrs.InitEmptyWithCapacity(len(span.Tags)) + attrs.Clear() + attrs.EnsureCapacity(len(span.Tags)) jThriftTagsToInternalAttributes(span.Tags, attrs) setInternalSpanStatus(attrs, dest.Status()) if spanKindAttr, ok := attrs.Get(tracetranslator.TagSpanKind); ok { @@ -163,7 +165,8 @@ func jThriftLogsToSpanEvents(logs []*jaeger.Log, dest pdata.SpanEventSlice) { } attrs := event.Attributes() - attrs.InitEmptyWithCapacity(len(log.Fields)) + attrs.Clear() + attrs.EnsureCapacity(len(log.Fields)) jThriftTagsToInternalAttributes(log.Fields, attrs) if name, ok := attrs.Get(tracetranslator.TagMessage); ok { event.SetName(name.StringVal()) diff --git a/translator/trace/zipkin/zipkinv2_to_traces.go b/translator/trace/zipkin/zipkinv2_to_traces.go index 185099160b5..6627767515a 100644 --- a/translator/trace/zipkin/zipkinv2_to_traces.go +++ b/translator/trace/zipkin/zipkinv2_to_traces.go @@ -143,7 +143,8 @@ func zSpanToInternal(zspan *zipkinmodel.SpanModel, tags map[string]string, dest } attrs := dest.Attributes() - attrs.InitEmptyWithCapacity(len(tags)) + attrs.Clear() + attrs.EnsureCapacity(len(tags)) if err := zTagsToInternalAttrs(zspan, tags, attrs, parseStringTags); err != nil { return err } diff --git a/translator/trace/zipkin/zipkinv2_to_traces_test.go b/translator/trace/zipkin/zipkinv2_to_traces_test.go index c8417703f23..90530ce5661 100644 --- a/translator/trace/zipkin/zipkinv2_to_traces_test.go +++ b/translator/trace/zipkin/zipkinv2_to_traces_test.go @@ -131,7 +131,6 @@ func generateTraceSingleSpanNoResourceOrInstrLibrary() pdata.Traces { span.SetKind(pdata.SpanKindCLIENT) span.SetStartTimestamp(1596911098294000000) span.SetEndTimestamp(1596911098295000000) - span.Attributes().InitEmptyWithCapacity(0) return td } @@ -139,7 +138,6 @@ func generateTraceSingleSpanMinmalResource() pdata.Traces { td := generateTraceSingleSpanNoResourceOrInstrLibrary() rs := td.ResourceSpans().At(0) rsc := rs.Resource() - rsc.Attributes().InitEmptyWithCapacity(1) rsc.Attributes().UpsertString(conventions.AttributeServiceName, "SoleAttr") return td } @@ -159,7 +157,6 @@ func generateTraceSingleSpanErrorStatus() pdata.Traces { span.SetKind(pdata.SpanKindCLIENT) span.SetStartTimestamp(1596911098294000000) span.SetEndTimestamp(1596911098295000000) - span.Attributes().InitEmptyWithCapacity(0) span.Status().SetCode(pdata.StatusCodeError) return td }