Skip to content

Commit

Permalink
attrs prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanth-tatina-groww committed Jul 10, 2023
1 parent 8649f0b commit 5bc9aaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions otlp/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const (
gRPCAcceptEncodingHeader = "grpc-accept-encoding"
defaultServiceName = "unknown_service"
unknownLogSource = "unknown_log_source"
resourceAttrsPrefix = "resource."
scopeAttrsPrefix = "scope."
spanAttrsPrefix = "span."
seventAttrsPrefix = "sevent."
slinkAttrsPrefix = "slink."
)

// fieldSizeMax is the maximum size of a field that will be accepted by honeycomb.
Expand Down Expand Up @@ -192,14 +197,14 @@ func getValueFromMetadata(md metadata.MD, key string) string {
return ""
}

func addAttributesToMap(attrs map[string]interface{}, attributes []*common.KeyValue) {
func addAttributesToMap(prefix string, attrs map[string]interface{}, attributes []*common.KeyValue) {
for _, attr := range attributes {
// ignore entries if the key is empty or value is nil
if attr.Key == "" || attr.Value == nil {
continue
}
if val, truncatedBytes := getValue(attr.Value); val != nil {
attrs[attr.Key] = val
attrs[prefix+attr.Key] = val
if truncatedBytes != 0 {
// if we trim a field, add telemetry about it; because we trim at 64K and
// a whole span can't be more than 100K, this can't happen more than once
Expand All @@ -215,7 +220,7 @@ func addAttributesToMap(attrs map[string]interface{}, attributes []*common.KeyVa
func getResourceAttributes(resource *resource.Resource) map[string]interface{} {
attrs := map[string]interface{}{}
if resource != nil {
addAttributesToMap(attrs, resource.Attributes)
addAttributesToMap(resourceAttrsPrefix, attrs, resource.Attributes)
}
return attrs
}
Expand All @@ -232,7 +237,7 @@ func getScopeAttributes(scope *common.InstrumentationScope) map[string]interface
if scope.Version != "" {
attrs["library.version"] = scope.Version
}
addAttributesToMap(attrs, scope.Attributes)
addAttributesToMap(scopeAttrsPrefix,attrs, scope.Attributes)
}
return attrs
}
Expand Down
6 changes: 3 additions & 3 deletions otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TranslateTraceRequest(request *collectorTrace.ExportTraceServiceRequest, ri
eventAttrs[k] = v
}
if span.Attributes != nil {
addAttributesToMap(eventAttrs, span.Attributes)
addAttributesToMap(spanAttrsPrefix,eventAttrs, span.Attributes)
}

// get sample rate after resource and scope attributes have been added
Expand Down Expand Up @@ -116,7 +116,7 @@ func TranslateTraceRequest(request *collectorTrace.ExportTraceServiceRequest, ri
}

if sevent.Attributes != nil {
addAttributesToMap(attrs, sevent.Attributes)
addAttributesToMap(seventAttrsPrefix,attrs, sevent.Attributes)
}
if isError {
attrs["error"] = true
Expand Down Expand Up @@ -172,7 +172,7 @@ func TranslateTraceRequest(request *collectorTrace.ExportTraceServiceRequest, ri
}

if slink.Attributes != nil {
addAttributesToMap(attrs, slink.Attributes)
addAttributesToMap(slinkAttrsPrefix,attrs, slink.Attributes)
}
if isError {
attrs["error"] = true
Expand Down

0 comments on commit 5bc9aaa

Please sign in to comment.