diff --git a/exporter/ststopologyexporter/exporter.go b/exporter/ststopologyexporter/exporter.go index a907419..f16346f 100644 --- a/exporter/ststopologyexporter/exporter.go +++ b/exporter/ststopologyexporter/exporter.go @@ -13,6 +13,7 @@ import ( "github.com/stackvista/sts-opentelemetry-collector/exporter/ststopologyexporter/internal" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" ) @@ -82,17 +83,37 @@ func (t *topologyExporter) ConsumeMetrics(ctx context.Context, md pmetric.Metric continue } connAttrs := m.Sum().DataPoints().At(0).Attributes() - sts_api_key_value, key_exists := connAttrs.Get("client_sts_api_key") - if !key_exists { - log.Error("Configuration error - no sts_api_key available on servicegraph metric") - return errInternal + client_api_key_value, client_key_exists := connAttrs.Get("client_sts_api_key") + var client_api_key string + if client_key_exists { + client_api_key = client_api_key_value.AsString() + } + server_api_key_value, server_key_exists := connAttrs.Get("server_sts_api_key") + var server_api_key string + if server_key_exists { + server_api_key = server_api_key_value.AsString() + } + if !client_key_exists && !server_key_exists { + log.Warn("No sts_api_key attributes, found:") + connAttrs.Range(func(k string, v pcommon.Value) bool { + log.Warn(" attr", zap.String(k, v.AsString())) + return true + }) + continue } - sts_api_key := sts_api_key_value.AsString() connAttrs.Remove("client_sts_api_key") connAttrs.Remove("server_sts_api_key") - collection := getOrDefault(componentsByApiKey, sts_api_key) - if !collection.AddConnection(&connAttrs) { - log.Warn("Unable to add connection from servicegraphconnector") + if client_key_exists { + collection := getOrDefault(componentsByApiKey, client_api_key) + if !collection.AddConnection(&connAttrs) { + log.Warn("Unable to add connection from servicegraphconnector to client") + } + } + if server_key_exists { + collection := getOrDefault(componentsByApiKey, server_api_key) + if !collection.AddConnection(&connAttrs) { + log.Warn("Unable to add connection from servicegraphconnector to server") + } } } break