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

[translator/zipkin]: Change usage of Insert to Upsert, always insert in new map #13860

Merged
merged 1 commit into from
Sep 5, 2022
Merged
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
26 changes: 13 additions & 13 deletions pkg/translator/zipkin/zipkinv2/to_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ func populateSpanEvents(zspan *zipkinmodel.SpanModel, events ptrace.SpanEventSli
func jsonMapToAttributeMap(attrs map[string]interface{}, dest pcommon.Map) error {
for key, val := range attrs {
if s, ok := val.(string); ok {
dest.InsertString(key, s)
dest.UpsertString(key, s)
} else if d, ok := val.(float64); ok {
if math.Mod(d, 1.0) == 0.0 {
dest.InsertInt(key, int64(d))
dest.UpsertInt(key, int64(d))
} else {
dest.InsertDouble(key, d)
dest.UpsertDouble(key, d)
}
} else if b, ok := val.(bool); ok {
dest.InsertBool(key, b)
dest.UpsertBool(key, b)
}
}
return nil
Expand All @@ -311,24 +311,24 @@ func zTagsToInternalAttrs(zspan *zipkinmodel.SpanModel, tags map[string]string,
parseErr := tagsToAttributeMap(tags, dest, parseStringTags)
if zspan.LocalEndpoint != nil {
if zspan.LocalEndpoint.IPv4 != nil {
dest.InsertString(conventions.AttributeNetHostIP, zspan.LocalEndpoint.IPv4.String())
dest.UpsertString(conventions.AttributeNetHostIP, zspan.LocalEndpoint.IPv4.String())
}
if zspan.LocalEndpoint.IPv6 != nil {
dest.InsertString(conventions.AttributeNetHostIP, zspan.LocalEndpoint.IPv6.String())
dest.UpsertString(conventions.AttributeNetHostIP, zspan.LocalEndpoint.IPv6.String())
}
if zspan.LocalEndpoint.Port > 0 {
dest.UpsertInt(conventions.AttributeNetHostPort, int64(zspan.LocalEndpoint.Port))
}
}
if zspan.RemoteEndpoint != nil {
if zspan.RemoteEndpoint.ServiceName != "" {
dest.InsertString(conventions.AttributePeerService, zspan.RemoteEndpoint.ServiceName)
dest.UpsertString(conventions.AttributePeerService, zspan.RemoteEndpoint.ServiceName)
}
if zspan.RemoteEndpoint.IPv4 != nil {
dest.InsertString(conventions.AttributeNetPeerIP, zspan.RemoteEndpoint.IPv4.String())
dest.UpsertString(conventions.AttributeNetPeerIP, zspan.RemoteEndpoint.IPv4.String())
}
if zspan.RemoteEndpoint.IPv6 != nil {
dest.InsertString(conventions.AttributeNetPeerIP, zspan.RemoteEndpoint.IPv6.String())
dest.UpsertString(conventions.AttributeNetPeerIP, zspan.RemoteEndpoint.IPv6.String())
}
if zspan.RemoteEndpoint.Port > 0 {
dest.UpsertInt(conventions.AttributeNetPeerPort, int64(zspan.RemoteEndpoint.Port))
Expand Down Expand Up @@ -371,15 +371,15 @@ func populateResourceFromZipkinSpan(tags map[string]string, localServiceName str
}

if len(tags) == 0 {
resource.Attributes().InsertString(conventions.AttributeServiceName, localServiceName)
resource.Attributes().UpsertString(conventions.AttributeServiceName, localServiceName)
return
}

snSource := tags[zipkin.TagServiceNameSource]
if snSource == "" {
resource.Attributes().InsertString(conventions.AttributeServiceName, localServiceName)
resource.Attributes().UpsertString(conventions.AttributeServiceName, localServiceName)
} else {
resource.Attributes().InsertString(snSource, localServiceName)
resource.Attributes().UpsertString(snSource, localServiceName)
}
delete(tags, zipkin.TagServiceNameSource)

Expand Down Expand Up @@ -442,7 +442,7 @@ func setTimestampsV2(zspan *zipkinmodel.SpanModel, dest ptrace.Span, destAttrs p
dest.SetStartTimestamp(unixTimeZero)
dest.SetEndTimestamp(zeroPlusDuration)

destAttrs.InsertBool(zipkin.StartTimeAbsent, true)
destAttrs.UpsertBool(zipkin.StartTimeAbsent, true)
} else {
dest.SetStartTimestamp(pcommon.NewTimestampFromTime(zspan.Timestamp))
dest.SetEndTimestamp(pcommon.NewTimestampFromTime(zspan.Timestamp.Add(zspan.Duration)))
Expand Down