Skip to content

Commit

Permalink
[translator/opencensus]: Change usage of Insert to Upsert, always ins…
Browse files Browse the repository at this point in the history
…ert in new map (#13859)

Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Sep 6, 2022
1 parent abc4f70 commit 676a326
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions pkg/translator/opencensus/oc_to_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,23 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso
}

attrs := dest.Attributes()
attrs.Clear()
attrs.EnsureCapacity(maxTotalAttrCount)

if ocNode != nil {
// Copy all Attributes.
for k, v := range ocNode.Attributes {
attrs.InsertString(k, v)
// Copy all resource Labels and Node attributes.
for k, v := range ocResource.GetLabels() {
switch k {
case resourcekeys.CloudKeyZone:
attrs.UpsertString(conventions.AttributeCloudAvailabilityZone, v)
default:
attrs.UpsertString(k, v)
}
}
for k, v := range ocNode.GetAttributes() {
attrs.UpsertString(k, v)
}

// Add all special fields.
// Add all special fields that should overwrite any resource label or node attribute.
if ocNode != nil {
if ocNode.ServiceInfo != nil {
if ocNode.ServiceInfo.Name != "" {
attrs.UpsertString(conventions.AttributeServiceName, ocNode.ServiceInfo.Name)
Expand Down Expand Up @@ -121,18 +128,7 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso
}
}
}

if ocResource != nil {
// Copy resource Labels.
for k, v := range ocResource.Labels {
switch k {
case resourcekeys.CloudKeyZone:
attrs.InsertString(conventions.AttributeCloudAvailabilityZone, v)
default:
attrs.InsertString(k, v)
}
}
// Add special fields.
if ocResource.Type != "" {
attrs.UpsertString(occonventions.AttributeResourceType, ocResource.Type)
}
Expand Down

0 comments on commit 676a326

Please sign in to comment.