From 5bc9aaad3e6295d68a857a76b47aa82d3a4cf8af Mon Sep 17 00:00:00 2001 From: JayanthTatina Date: Mon, 10 Jul 2023 15:53:30 +0530 Subject: [PATCH] attrs prefixes --- otlp/common.go | 13 +++++++++---- otlp/traces.go | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/otlp/common.go b/otlp/common.go index 09c9219..828c1d3 100644 --- a/otlp/common.go +++ b/otlp/common.go @@ -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. @@ -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 @@ -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 } @@ -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 } diff --git a/otlp/traces.go b/otlp/traces.go index 1007bc9..7218473 100644 --- a/otlp/traces.go +++ b/otlp/traces.go @@ -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 @@ -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 @@ -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