diff --git a/internal/goldendataset/generator_commons.go b/internal/goldendataset/generator_commons.go index cbfc44ea12a..a4e31175ce6 100644 --- a/internal/goldendataset/generator_commons.go +++ b/internal/goldendataset/generator_commons.go @@ -16,49 +16,10 @@ package goldendataset import ( "encoding/csv" - "io" "os" "path/filepath" - - "github.com/spf13/cast" - - "go.opentelemetry.io/collector/consumer/pdata" ) -func convertMapToAttributeMap(attrsMap map[string]interface{}) *pdata.AttributeMap { - attributeMap := pdata.NewAttributeMap() - if attrsMap == nil { - return nil - } - for key, value := range attrsMap { - attributeMap.Insert(key, convertToAttributeValue(value)) - } - return &attributeMap -} - -func convertToAttributeValue(value interface{}) pdata.AttributeValue { - var newValue pdata.AttributeValue - switch val := value.(type) { - case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: - newValue = pdata.NewAttributeValueInt(cast.ToInt64(val)) - case float32, float64: - newValue = pdata.NewAttributeValueDouble(cast.ToFloat64(val)) - case bool: - newValue = pdata.NewAttributeValueBool(cast.ToBool(val)) - case pdata.AttributeMap: - newValue = pdata.NewAttributeValueMap() - val.CopyTo(newValue.MapVal()) - case pdata.AnyValueArray: - newValue = pdata.NewAttributeValueArray() - val.CopyTo(newValue.ArrayVal()) - case pdata.AttributeValue: - newValue = val - default: - newValue = pdata.NewAttributeValueString(val.(string)) - } - return newValue -} - func loadPictOutputFile(fileName string) ([][]string, error) { file, err := os.Open(filepath.Clean(fileName)) if err != nil { @@ -76,21 +37,3 @@ func loadPictOutputFile(fileName string) ([][]string, error) { return reader.ReadAll() } - -func generatePDataTraceID(random io.Reader) pdata.TraceID { - var r [16]byte - _, err := random.Read(r[:]) - if err != nil { - panic(err) - } - return pdata.NewTraceID(r) -} - -func generatePDataSpanID(random io.Reader) pdata.SpanID { - var r [8]byte - _, err := random.Read(r[:]) - if err != nil { - panic(err) - } - return pdata.NewSpanID(r) -} diff --git a/internal/goldendataset/pict_tracing_input_defs.go b/internal/goldendataset/pict_tracing_input_defs.go index 32ef38ff956..4d45fb27f09 100644 --- a/internal/goldendataset/pict_tracing_input_defs.go +++ b/internal/goldendataset/pict_tracing_input_defs.go @@ -27,7 +27,6 @@ const ( type PICTInputResource string const ( - ResourceNil PICTInputResource = "Nil" ResourceEmpty PICTInputResource = "Empty" ResourceVMOnPrem PICTInputResource = "VMOnPrem" ResourceVMCloud PICTInputResource = "VMCloud" @@ -112,7 +111,6 @@ const ( type PICTInputAttributes string const ( - SpanAttrNil PICTInputAttributes = "Nil" SpanAttrEmpty PICTInputAttributes = "Empty" SpanAttrDatabaseSQL PICTInputAttributes = "DatabaseSQL" SpanAttrDatabaseNoSQL PICTInputAttributes = "DatabaseNoSQL" @@ -135,7 +133,6 @@ const ( type PICTInputSpanChild string const ( - SpanChildCountNil PICTInputSpanChild = "Nil" SpanChildCountEmpty PICTInputSpanChild = "Empty" SpanChildCountOne PICTInputSpanChild = "One" SpanChildCountTwo PICTInputSpanChild = "Two" diff --git a/internal/goldendataset/resource_generator.go b/internal/goldendataset/resource_generator.go index 396242e628d..37d3d19a872 100644 --- a/internal/goldendataset/resource_generator.go +++ b/internal/goldendataset/resource_generator.go @@ -22,140 +22,110 @@ import ( // GenerateResource generates a PData Resource object with representative attributes for the // underlying resource type specified by the rscID input parameter. func GenerateResource(rscID PICTInputResource) pdata.Resource { - var attrs map[string]interface{} + resource := pdata.NewResource() switch rscID { - case ResourceNil: - attrs = generateNilAttributes() case ResourceEmpty: - attrs = generateEmptyAttributes() + break case ResourceVMOnPrem: - attrs = generateOnpremVMAttributes() + appendOnpremVMAttributes(resource.Attributes()) case ResourceVMCloud: - attrs = generateCloudVMAttributes() + appendCloudVMAttributes(resource.Attributes()) case ResourceK8sOnPrem: - attrs = generateOnpremK8sAttributes() + appendOnpremK8sAttributes(resource.Attributes()) case ResourceK8sCloud: - attrs = generateCloudK8sAttributes() + appendCloudK8sAttributes(resource.Attributes()) case ResourceFaas: - attrs = generateFassAttributes() + appendFassAttributes(resource.Attributes()) case ResourceExec: - attrs = generateExecAttributes() - default: - attrs = generateEmptyAttributes() - } - resource := pdata.NewResource() - attributeMap := convertMapToAttributeMap(attrs) - if attributeMap != nil { - attributeMap.CopyTo(resource.Attributes()) + appendExecAttributes(resource.Attributes()) } return resource } -func generateNilAttributes() map[string]interface{} { - return nil -} - -func generateEmptyAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - return attrMap -} - -func generateOnpremVMAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeServiceName] = "customers" - attrMap[conventions.AttributeServiceNamespace] = "production" - attrMap[conventions.AttributeServiceVersion] = "semver:0.7.3" - subMap := pdata.NewAttributeMap() - subMap.InsertString("public", "tc-prod9.internal.example.com") - subMap.InsertString("internal", "172.18.36.18") - attrMap[conventions.AttributeHostName] = subMap - attrMap[conventions.AttributeHostImageID] = "661ADFA6-E293-4870-9EFA-1AA052C49F18" - attrMap[conventions.AttributeTelemetrySDKLanguage] = conventions.AttributeSDKLangValueJava - attrMap[conventions.AttributeTelemetrySDKName] = "opentelemetry" - attrMap[conventions.AttributeTelemetrySDKVersion] = "0.3.0" - return attrMap +func appendOnpremVMAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeServiceName, "customers") + attrMap.UpsertString(conventions.AttributeServiceNamespace, "production") + attrMap.UpsertString(conventions.AttributeServiceVersion, "semver:0.7.3") + subMap := pdata.NewAttributeValueMap() + subMap.MapVal().InsertString("public", "tc-prod9.internal.example.com") + subMap.MapVal().InsertString("internal", "172.18.36.18") + attrMap.Upsert(conventions.AttributeHostName, subMap) + attrMap.UpsertString(conventions.AttributeHostImageID, "661ADFA6-E293-4870-9EFA-1AA052C49F18") + attrMap.UpsertString(conventions.AttributeTelemetrySDKLanguage, conventions.AttributeSDKLangValueJava) + attrMap.UpsertString(conventions.AttributeTelemetrySDKName, "opentelemetry") + attrMap.UpsertString(conventions.AttributeTelemetrySDKVersion, "0.3.0") } -func generateCloudVMAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeServiceName] = "shoppingcart" - attrMap[conventions.AttributeServiceName] = "customers" - attrMap[conventions.AttributeServiceNamespace] = "production" - attrMap[conventions.AttributeServiceVersion] = "semver:0.7.3" - attrMap[conventions.AttributeTelemetrySDKLanguage] = conventions.AttributeSDKLangValueJava - attrMap[conventions.AttributeTelemetrySDKName] = "opentelemetry" - attrMap[conventions.AttributeTelemetrySDKVersion] = "0.3.0" - attrMap[conventions.AttributeHostID] = "57e8add1f79a454bae9fb1f7756a009a" - attrMap[conventions.AttributeHostName] = "env-check" - attrMap[conventions.AttributeHostImageID] = "5.3.0-1020-azure" - attrMap[conventions.AttributeHostType] = "B1ms" - attrMap[conventions.AttributeCloudProvider] = "azure" - attrMap[conventions.AttributeCloudAccount] = "2f5b8278-4b80-4930-a6bb-d86fc63a2534" - attrMap[conventions.AttributeCloudRegion] = "South Central US" - return attrMap +func appendCloudVMAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeServiceName, "shoppingcart") + attrMap.UpsertString(conventions.AttributeServiceName, "customers") + attrMap.UpsertString(conventions.AttributeServiceNamespace, "production") + attrMap.UpsertString(conventions.AttributeServiceVersion, "semver:0.7.3") + attrMap.UpsertString(conventions.AttributeTelemetrySDKLanguage, conventions.AttributeSDKLangValueJava) + attrMap.UpsertString(conventions.AttributeTelemetrySDKName, "opentelemetry") + attrMap.UpsertString(conventions.AttributeTelemetrySDKVersion, "0.3.0") + attrMap.UpsertString(conventions.AttributeHostID, "57e8add1f79a454bae9fb1f7756a009a") + attrMap.UpsertString(conventions.AttributeHostName, "env-check") + attrMap.UpsertString(conventions.AttributeHostImageID, "5.3.0-1020-azure") + attrMap.UpsertString(conventions.AttributeHostType, "B1ms") + attrMap.UpsertString(conventions.AttributeCloudProvider, "azure") + attrMap.UpsertString(conventions.AttributeCloudAccount, "2f5b8278-4b80-4930-a6bb-d86fc63a2534") + attrMap.UpsertString(conventions.AttributeCloudRegion, "South Central US") } -func generateOnpremK8sAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeContainerName] = "cert-manager" - attrMap[conventions.AttributeContainerImage] = "quay.io/jetstack/cert-manager-controller:v0.14.2" - attrMap[conventions.AttributeK8sCluster] = "docker-desktop" - attrMap[conventions.AttributeK8sNamespace] = "cert-manager" - attrMap[conventions.AttributeK8sDeployment] = "cm-1-cert-manager" - attrMap[conventions.AttributeK8sPod] = "cm-1-cert-manager-6448b4949b-t2jtd" - attrMap[conventions.AttributeHostName] = "docker-desktop" - return attrMap +func appendOnpremK8sAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeContainerName, "cert-manager") + attrMap.UpsertString(conventions.AttributeContainerImage, "quay.io/jetstack/cert-manager-controller:v0.14.2") + attrMap.UpsertString(conventions.AttributeK8sCluster, "docker-desktop") + attrMap.UpsertString(conventions.AttributeK8sNamespace, "cert-manager") + attrMap.UpsertString(conventions.AttributeK8sDeployment, "cm-1-cert-manager") + attrMap.UpsertString(conventions.AttributeK8sPod, "cm-1-cert-manager-6448b4949b-t2jtd") + attrMap.UpsertString(conventions.AttributeHostName, "docker-desktop") } -func generateCloudK8sAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeContainerName] = "otel-collector" - attrMap[conventions.AttributeContainerImage] = "otel/opentelemetry-collector-contrib" - attrMap[conventions.AttributeContainerTag] = "0.4.0" - attrMap[conventions.AttributeK8sCluster] = "erp-dev" - attrMap[conventions.AttributeK8sNamespace] = "monitoring" - attrMap[conventions.AttributeK8sDeployment] = "otel-collector" - attrMap[conventions.AttributeK8sDeploymentUID] = "4D614B27-EDAF-409B-B631-6963D8F6FCD4" - attrMap[conventions.AttributeK8sReplicaSet] = "otel-collector-2983fd34" - attrMap[conventions.AttributeK8sReplicaSetUID] = "EC7D59EF-D5B6-48B7-881E-DA6B7DD539B6" - attrMap[conventions.AttributeK8sPod] = "otel-collector-6484db5844-c6f9m" - attrMap[conventions.AttributeK8sPodUID] = "FDFD941E-2A7A-4945-B601-88DD486161A4" - attrMap[conventions.AttributeHostID] = "ec2e3fdaffa294348bdf355156b94cda" - attrMap[conventions.AttributeHostName] = "10.99.118.157" - attrMap[conventions.AttributeHostImageID] = "ami-011c865bf7da41a9d" - attrMap[conventions.AttributeHostType] = "m5.xlarge" - attrMap[conventions.AttributeCloudProvider] = "aws" - attrMap[conventions.AttributeCloudAccount] = "12345678901" - attrMap[conventions.AttributeCloudRegion] = "us-east-1" - attrMap[conventions.AttributeCloudAvailabilityZone] = "us-east-1c" - return attrMap +func appendCloudK8sAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeContainerName, "otel-collector") + attrMap.UpsertString(conventions.AttributeContainerImage, "otel/opentelemetry-collector-contrib") + attrMap.UpsertString(conventions.AttributeContainerTag, "0.4.0") + attrMap.UpsertString(conventions.AttributeK8sCluster, "erp-dev") + attrMap.UpsertString(conventions.AttributeK8sNamespace, "monitoring") + attrMap.UpsertString(conventions.AttributeK8sDeployment, "otel-collector") + attrMap.UpsertString(conventions.AttributeK8sDeploymentUID, "4D614B27-EDAF-409B-B631-6963D8F6FCD4") + attrMap.UpsertString(conventions.AttributeK8sReplicaSet, "otel-collector-2983fd34") + attrMap.UpsertString(conventions.AttributeK8sReplicaSetUID, "EC7D59EF-D5B6-48B7-881E-DA6B7DD539B6") + attrMap.UpsertString(conventions.AttributeK8sPod, "otel-collector-6484db5844-c6f9m") + attrMap.UpsertString(conventions.AttributeK8sPodUID, "FDFD941E-2A7A-4945-B601-88DD486161A4") + attrMap.UpsertString(conventions.AttributeHostID, "ec2e3fdaffa294348bdf355156b94cda") + attrMap.UpsertString(conventions.AttributeHostName, "10.99.118.157") + attrMap.UpsertString(conventions.AttributeHostImageID, "ami-011c865bf7da41a9d") + attrMap.UpsertString(conventions.AttributeHostType, "m5.xlarge") + attrMap.UpsertString(conventions.AttributeCloudProvider, "aws") + attrMap.UpsertString(conventions.AttributeCloudAccount, "12345678901") + attrMap.UpsertString(conventions.AttributeCloudRegion, "us-east-1") + attrMap.UpsertString(conventions.AttributeCloudAvailabilityZone, "us-east-1c") } -func generateFassAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeFaasID] = "https://us-central1-dist-system-demo.cloudfunctions.net/env-vars-print" - attrMap[conventions.AttributeFaasName] = "env-vars-print" - attrMap[conventions.AttributeFaasVersion] = "semver:1.0.0" - attrMap[conventions.AttributeCloudProvider] = "gcp" - attrMap[conventions.AttributeCloudAccount] = "opentelemetry" - attrMap[conventions.AttributeCloudRegion] = "us-central1" - attrMap[conventions.AttributeCloudAvailabilityZone] = "us-central1-a" - return attrMap +func appendFassAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeFaasID, "https://us-central1-dist-system-demo.cloudfunctions.net/env-vars-print") + attrMap.UpsertString(conventions.AttributeFaasName, "env-vars-print") + attrMap.UpsertString(conventions.AttributeFaasVersion, "semver:1.0.0") + attrMap.UpsertString(conventions.AttributeCloudProvider, "gcp") + attrMap.UpsertString(conventions.AttributeCloudAccount, "opentelemetry") + attrMap.UpsertString(conventions.AttributeCloudRegion, "us-central1") + attrMap.UpsertString(conventions.AttributeCloudAvailabilityZone, "us-central1-a") } -func generateExecAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeProcessExecutableName] = "otelcol" +func appendExecAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeProcessExecutableName, "otelcol") parts := pdata.NewAttributeValueArray() parts.ArrayVal().Append(pdata.NewAttributeValueString("otelcol")) parts.ArrayVal().Append(pdata.NewAttributeValueString("--config=/etc/otel-collector-config.yaml")) parts.ArrayVal().Append(pdata.NewAttributeValueString("--mem-ballast-size-mib=683")) - attrMap["conventions.AttributeProcessCommandLine"] = parts - attrMap[conventions.AttributeProcessExecutablePath] = "/usr/local/bin/otelcol" - attrMap[conventions.AttributeProcessID] = 2020 - attrMap[conventions.AttributeProcessOwner] = "otel" - attrMap[conventions.AttributeOSType] = "LINUX" - attrMap[conventions.AttributeOSDescription] = - "Linux ubuntu 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux" - return attrMap + attrMap.Upsert(conventions.AttributeProcessCommandLine, parts) + attrMap.UpsertString(conventions.AttributeProcessExecutablePath, "/usr/local/bin/otelcol") + attrMap.UpsertInt(conventions.AttributeProcessID, 2020) + attrMap.UpsertString(conventions.AttributeProcessOwner, "otel") + attrMap.UpsertString(conventions.AttributeOSType, "LINUX") + attrMap.UpsertString(conventions.AttributeOSDescription, + "Linux ubuntu 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux") } diff --git a/internal/goldendataset/resource_generator_test.go b/internal/goldendataset/resource_generator_test.go index 2be3955c250..3aaa977f344 100644 --- a/internal/goldendataset/resource_generator_test.go +++ b/internal/goldendataset/resource_generator_test.go @@ -21,11 +21,10 @@ import ( ) func TestGenerateResource(t *testing.T) { - resourceIds := []PICTInputResource{ResourceNil, ResourceEmpty, ResourceVMOnPrem, ResourceVMCloud, ResourceK8sOnPrem, - ResourceK8sCloud, ResourceFaas, ResourceExec} + resourceIds := []PICTInputResource{ResourceEmpty, ResourceVMOnPrem, ResourceVMCloud, ResourceK8sOnPrem, ResourceK8sCloud, ResourceFaas, ResourceExec} for _, rscID := range resourceIds { rsc := GenerateResource(rscID) - if rscID == ResourceNil || rscID == ResourceEmpty { + if rscID == ResourceEmpty { assert.Equal(t, 0, rsc.Attributes().Len()) } else { assert.True(t, rsc.Attributes().Len() > 0) diff --git a/internal/goldendataset/span_generator.go b/internal/goldendataset/span_generator.go index be93c8b2438..e013f698eb7 100644 --- a/internal/goldendataset/span_generator.go +++ b/internal/goldendataset/span_generator.go @@ -35,24 +35,18 @@ var statusMsgMap = map[PICTInputStatus]string{ SpanStatusError: "Error", } -// GenerateSpans generates a slice of pdata.Span objects with the number of spans specified by the count input -// parameter. The startPos parameter specifies the line in the PICT tool-generated, test parameter -// combination records file specified by the pictFile parameter to start reading from. When the end record -// is reached it loops back to the first record. The random parameter injects the random number generator -// to use in generating IDs and other random values. Using a random number generator with the same seed value -// enables reproducible tests. +// appendSpans appends to the pdata.SpanSlice objects the number of spans specified by the count input +// parameter. The random parameter injects the random number generator to use in generating IDs and other random values. +// Using a random number generator with the same seed value enables reproducible tests. // -// The return values are the slice with the generated spans, the starting position for the next generation -// run and the error which caused the spans generation to fail. If err is not nil, the spans slice will -// have nil values. -func GenerateSpans(count int, startPos int, pictFile string, random io.Reader) ([]pdata.Span, int, error) { +// If err is not nil, the spans slice will have nil values. +func appendSpans(count int, pictFile string, random io.Reader, spanList pdata.SpanSlice) error { pairsData, err := loadPictOutputFile(pictFile) if err != nil { - return nil, 0, err + return err } pairsTotal := len(pairsData) - spanList := make([]pdata.Span, count) - index := startPos + 1 + index := 1 var inputs []string var spanInputs *PICTSpanInputs var traceID pdata.TraceID @@ -73,23 +67,22 @@ func GenerateSpans(count int, startPos int, pictFile string, random io.Reader) ( } switch spanInputs.Parent { case SpanParentRoot: - traceID = generatePDataTraceID(random) + traceID = generateTraceID(random) parentID = pdata.NewSpanID([8]byte{}) case SpanParentChild: // use existing if available if traceID.IsEmpty() { - traceID = generatePDataTraceID(random) + traceID = generateTraceID(random) } if parentID.IsEmpty() { - parentID = generatePDataSpanID(random) + parentID = generateSpanID(random) } } spanName := generateSpanName(spanInputs) - spanList[i] = GenerateSpan(traceID, parentID, spanName, spanInputs, random) - parentID = spanList[i].SpanID() + fillSpan(traceID, parentID, spanName, spanInputs, random, spanList.AppendEmpty()) index++ } - return spanList, index, nil + return nil } func generateSpanName(spanInputs *PICTSpanInputs) string { @@ -97,7 +90,7 @@ func generateSpanName(spanInputs *PICTSpanInputs) string { spanInputs.Attributes, spanInputs.Events, spanInputs.Links, spanInputs.Status) } -// GenerateSpan generates a single pdata.Span based on the input values provided. They are: +// fillSpan generates a single pdata.Span based on the input values provided. They are: // traceID - the trace ID to use, should not be nil // parentID - the parent span ID or nil if it is a root span // spanName - the span name, should not be blank @@ -105,35 +98,23 @@ func generateSpanName(spanInputs *PICTSpanInputs) string { // random - the random number generator to use in generating ID values // // The generated span is returned. -func GenerateSpan(traceID pdata.TraceID, parentID pdata.SpanID, spanName string, spanInputs *PICTSpanInputs, - random io.Reader) pdata.Span { +func fillSpan(traceID pdata.TraceID, parentID pdata.SpanID, spanName string, spanInputs *PICTSpanInputs, random io.Reader, span pdata.Span) { endTime := time.Now().Add(-50 * time.Microsecond) - span := pdata.NewSpan() span.SetTraceID(traceID) - span.SetSpanID(generatePDataSpanID(random)) + span.SetSpanID(generateSpanID(random)) span.SetTraceState(generateTraceState(spanInputs.Tracestate)) span.SetParentSpanID(parentID) span.SetName(spanName) span.SetKind(lookupSpanKind(spanInputs.Kind)) span.SetStartTimestamp(pdata.Timestamp(endTime.Add(-215 * time.Millisecond).UnixNano())) span.SetEndTimestamp(pdata.Timestamp(endTime.UnixNano())) - spanAttributes := generateSpanAttributes(spanInputs.Attributes, spanInputs.Status) - if spanAttributes != nil { - spanAttributes.CopyTo(span.Attributes()) - } + appendSpanAttributes(spanInputs.Attributes, spanInputs.Status, span.Attributes()) span.SetDroppedAttributesCount(0) - spanEvents := generateSpanEvents(spanInputs.Events) - if spanEvents != nil { - spanEvents.CopyTo(span.Events()) - } + appendSpanEvents(spanInputs.Events, span.Events()) span.SetDroppedEventsCount(0) - spanLinks := generateSpanLinks(spanInputs.Links, random) - if spanLinks != nil { - spanLinks.CopyTo(span.Links()) - } + appendSpanLinks(spanInputs.Links, random, span.Links()) span.SetDroppedLinksCount(0) - generateStatus(spanInputs.Status).CopyTo(span.Status()) - return span + fillStatus(spanInputs.Status, span.Status()) } func generateTraceState(tracestate PICTInputTracestate) pdata.TraceState { @@ -168,298 +149,252 @@ func lookupSpanKind(kind PICTInputKind) pdata.SpanKind { } } -func generateSpanAttributes(spanTypeID PICTInputAttributes, statusStr PICTInputStatus) *pdata.AttributeMap { - includeStatus := SpanStatusUnset != statusStr - var attrs map[string]interface{} +func appendSpanAttributes(spanTypeID PICTInputAttributes, statusStr PICTInputStatus, attrMap pdata.AttributeMap) { + includeStatus := statusStr != SpanStatusUnset switch spanTypeID { - case SpanAttrNil: - attrs = nil case SpanAttrEmpty: - attrs = make(map[string]interface{}) + return case SpanAttrDatabaseSQL: - attrs = generateDatabaseSQLAttributes() + appendDatabaseSQLAttributes(attrMap) case SpanAttrDatabaseNoSQL: - attrs = generateDatabaseNoSQLAttributes() + appendDatabaseNoSQLAttributes(attrMap) case SpanAttrFaaSDatasource: - attrs = generateFaaSDatasourceAttributes() + appendFaaSDatasourceAttributes(attrMap) case SpanAttrFaaSHTTP: - attrs = generateFaaSHTTPAttributes(includeStatus) + appendFaaSHTTPAttributes(includeStatus, attrMap) case SpanAttrFaaSPubSub: - attrs = generateFaaSPubSubAttributes() + appendFaaSPubSubAttributes(attrMap) case SpanAttrFaaSTimer: - attrs = generateFaaSTimerAttributes() + appendFaaSTimerAttributes(attrMap) case SpanAttrFaaSOther: - attrs = generateFaaSOtherAttributes() + appendFaaSOtherAttributes(attrMap) case SpanAttrHTTPClient: - attrs = generateHTTPClientAttributes(includeStatus) + appendHTTPClientAttributes(includeStatus, attrMap) case SpanAttrHTTPServer: - attrs = generateHTTPServerAttributes(includeStatus) + appendHTTPServerAttributes(includeStatus, attrMap) case SpanAttrMessagingProducer: - attrs = generateMessagingProducerAttributes() + appendMessagingProducerAttributes(attrMap) case SpanAttrMessagingConsumer: - attrs = generateMessagingConsumerAttributes() + appendMessagingConsumerAttributes(attrMap) case SpanAttrGRPCClient: - attrs = generateGRPCClientAttributes() + appendGRPCClientAttributes(attrMap) case SpanAttrGRPCServer: - attrs = generateGRPCServerAttributes() + appendGRPCServerAttributes(attrMap) case SpanAttrInternal: - attrs = generateInternalAttributes() + appendInternalAttributes(attrMap) case SpanAttrMaxCount: - attrs = generateMaxCountAttributes(includeStatus) + appendMaxCountAttributes(includeStatus, attrMap) default: - attrs = generateGRPCClientAttributes() + appendGRPCClientAttributes(attrMap) } - return convertMapToAttributeMap(attrs) } -func generateStatus(statusStr PICTInputStatus) pdata.SpanStatus { - if SpanStatusUnset == statusStr { - return pdata.NewSpanStatus() +func fillStatus(statusStr PICTInputStatus, spanStatus pdata.SpanStatus) { + if statusStr == SpanStatusUnset { + return } - spanStatus := pdata.NewSpanStatus() spanStatus.SetCode(statusCodeMap[statusStr]) spanStatus.SetMessage(statusMsgMap[statusStr]) - return spanStatus } -func generateDatabaseSQLAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeDBSystem] = "mysql" - attrMap[conventions.AttributeDBConnectionString] = "Server=shopdb.example.com;Database=ShopDb;Uid=billing_user;TableCache=true;UseCompression=True;MinimumPoolSize=10;MaximumPoolSize=50;" - attrMap[conventions.AttributeDBUser] = "billing_user" - attrMap[conventions.AttributeNetHostIP] = "192.0.3.122" - attrMap[conventions.AttributeNetHostPort] = int64(51306) - attrMap[conventions.AttributeNetPeerName] = "shopdb.example.com" - attrMap[conventions.AttributeNetPeerIP] = "192.0.2.12" - attrMap[conventions.AttributeNetPeerPort] = int64(3306) - attrMap[conventions.AttributeNetTransport] = "IP.TCP" - attrMap[conventions.AttributeDBName] = "shopdb" - attrMap[conventions.AttributeDBStatement] = "SELECT * FROM orders WHERE order_id = 'o4711'" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendDatabaseSQLAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeDBSystem, "mysql") + attrMap.UpsertString(conventions.AttributeDBConnectionString, "Server=shopdb.example.com;Database=ShopDb;Uid=billing_user;TableCache=true;UseCompression=True;MinimumPoolSize=10;MaximumPoolSize=50;") + attrMap.UpsertString(conventions.AttributeDBUser, "billing_user") + attrMap.UpsertString(conventions.AttributeNetHostIP, "192.0.3.122") + attrMap.UpsertInt(conventions.AttributeNetHostPort, 51306) + attrMap.UpsertString(conventions.AttributeNetPeerName, "shopdb.example.com") + attrMap.UpsertString(conventions.AttributeNetPeerIP, "192.0.2.12") + attrMap.UpsertInt(conventions.AttributeNetPeerPort, 3306) + attrMap.UpsertString(conventions.AttributeNetTransport, "IP.TCP") + attrMap.UpsertString(conventions.AttributeDBName, "shopdb") + attrMap.UpsertString(conventions.AttributeDBStatement, "SELECT * FROM orders WHERE order_id = 'o4711'") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateDatabaseNoSQLAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeDBSystem] = "mongodb" - attrMap[conventions.AttributeDBUser] = "the_user" - attrMap[conventions.AttributeNetPeerName] = "mongodb0.example.com" - attrMap[conventions.AttributeNetPeerIP] = "192.0.2.14" - attrMap[conventions.AttributeNetPeerPort] = int64(27017) - attrMap[conventions.AttributeNetTransport] = "IP.TCP" - attrMap[conventions.AttributeDBName] = "shopDb" - attrMap[conventions.AttributeDBOperation] = "findAndModify" - attrMap[conventions.AttributeDBMongoDBCollection] = "products" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendDatabaseNoSQLAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeDBSystem, "mongodb") + attrMap.UpsertString(conventions.AttributeDBUser, "the_user") + attrMap.UpsertString(conventions.AttributeNetPeerName, "mongodb0.example.com") + attrMap.UpsertString(conventions.AttributeNetPeerIP, "192.0.2.14") + attrMap.UpsertInt(conventions.AttributeNetPeerPort, 27017) + attrMap.UpsertString(conventions.AttributeNetTransport, "IP.TCP") + attrMap.UpsertString(conventions.AttributeDBName, "shopDb") + attrMap.UpsertString(conventions.AttributeDBOperation, "findAndModify") + attrMap.UpsertString(conventions.AttributeDBMongoDBCollection, "products") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateFaaSDatasourceAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeFaaSTrigger] = conventions.FaaSTriggerDataSource - attrMap[conventions.AttributeFaaSExecution] = "DB85AF51-5E13-473D-8454-1E2D59415EAB" - attrMap[conventions.AttributeFaaSDocumentCollection] = "faa-flight-delay-information-incoming" - attrMap[conventions.AttributeFaaSDocumentOperation] = "insert" - attrMap[conventions.AttributeFaaSDocumentTime] = "2020-05-09T19:50:06Z" - attrMap[conventions.AttributeFaaSDocumentName] = "delays-20200509-13.csv" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendFaaSDatasourceAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeFaaSTrigger, conventions.FaaSTriggerDataSource) + attrMap.UpsertString(conventions.AttributeFaaSExecution, "DB85AF51-5E13-473D-8454-1E2D59415EAB") + attrMap.UpsertString(conventions.AttributeFaaSDocumentCollection, "faa-flight-delay-information-incoming") + attrMap.UpsertString(conventions.AttributeFaaSDocumentOperation, "insert") + attrMap.UpsertString(conventions.AttributeFaaSDocumentTime, "2020-05-09T19:50:06Z") + attrMap.UpsertString(conventions.AttributeFaaSDocumentName, "delays-20200509-13.csv") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateFaaSHTTPAttributes(includeStatus bool) map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeFaaSTrigger] = conventions.FaaSTriggerHTTP - attrMap[conventions.AttributeHTTPMethod] = "POST" - attrMap[conventions.AttributeHTTPScheme] = "https" - attrMap[conventions.AttributeHTTPHost] = "api.opentelemetry.io" - attrMap[conventions.AttributeHTTPTarget] = "/blog/posts" - attrMap[conventions.AttributeHTTPFlavor] = "2" +func appendFaaSHTTPAttributes(includeStatus bool, attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeFaaSTrigger, conventions.FaaSTriggerHTTP) + attrMap.UpsertString(conventions.AttributeHTTPMethod, "POST") + attrMap.UpsertString(conventions.AttributeHTTPScheme, "https") + attrMap.UpsertString(conventions.AttributeHTTPHost, "api.opentelemetry.io") + attrMap.UpsertString(conventions.AttributeHTTPTarget, "/blog/posts") + attrMap.UpsertString(conventions.AttributeHTTPFlavor, "2") if includeStatus { - attrMap[conventions.AttributeHTTPStatusCode] = int64(201) + attrMap.UpsertInt(conventions.AttributeHTTPStatusCode, 201) } - attrMap[conventions.AttributeHTTPUserAgent] = - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap + attrMap.UpsertString(conventions.AttributeHTTPUserAgent, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateFaaSPubSubAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeFaaSTrigger] = conventions.FaaSTriggerPubSub - attrMap[conventions.AttributeMessagingSystem] = "sqs" - attrMap[conventions.AttributeMessagingDestination] = "video-views-au" - attrMap[conventions.AttributeMessagingOperation] = "process" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendFaaSPubSubAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeFaaSTrigger, conventions.FaaSTriggerPubSub) + attrMap.UpsertString(conventions.AttributeMessagingSystem, "sqs") + attrMap.UpsertString(conventions.AttributeMessagingDestination, "video-views-au") + attrMap.UpsertString(conventions.AttributeMessagingOperation, "process") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateFaaSTimerAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeFaaSTrigger] = conventions.FaaSTriggerTimer - attrMap[conventions.AttributeFaaSExecution] = "73103A4C-E22F-4493-BDE8-EAE5CAB37B50" - attrMap[conventions.AttributeFaaSTime] = "2020-05-09T20:00:08Z" - attrMap[conventions.AttributeFaaSCron] = "0/15 * * * *" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendFaaSTimerAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeFaaSTrigger, conventions.FaaSTriggerTimer) + attrMap.UpsertString(conventions.AttributeFaaSExecution, "73103A4C-E22F-4493-BDE8-EAE5CAB37B50") + attrMap.UpsertString(conventions.AttributeFaaSTime, "2020-05-09T20:00:08Z") + attrMap.UpsertString(conventions.AttributeFaaSCron, "0/15 * * * *") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateFaaSOtherAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeFaaSTrigger] = conventions.FaaSTriggerOther - attrMap["processed.count"] = int64(256) - attrMap["processed.data"] = 14.46 - attrMap["processed.errors"] = false - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendFaaSOtherAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeFaaSTrigger, conventions.FaaSTriggerOther) + attrMap.UpsertInt("processed.count", 256) + attrMap.UpsertDouble("processed.data", 14.46) + attrMap.UpsertBool("processed.errors", false) + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateHTTPClientAttributes(includeStatus bool) map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeHTTPMethod] = "GET" - attrMap[conventions.AttributeHTTPURL] = "https://opentelemetry.io/registry/" +func appendHTTPClientAttributes(includeStatus bool, attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeHTTPMethod, "GET") + attrMap.UpsertString(conventions.AttributeHTTPURL, "https://opentelemetry.io/registry/") if includeStatus { - attrMap[conventions.AttributeHTTPStatusCode] = int64(200) - attrMap[conventions.AttributeHTTPStatusText] = "More Than OK" + attrMap.UpsertInt(conventions.AttributeHTTPStatusCode, 200) + attrMap.UpsertString(conventions.AttributeHTTPStatusText, "More Than OK") } - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateHTTPServerAttributes(includeStatus bool) map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeHTTPMethod] = "POST" - attrMap[conventions.AttributeHTTPScheme] = "https" - attrMap[conventions.AttributeHTTPServerName] = "api22.opentelemetry.io" - attrMap[conventions.AttributeNetHostPort] = int64(443) - attrMap[conventions.AttributeHTTPTarget] = "/blog/posts" - attrMap[conventions.AttributeHTTPFlavor] = "2" +func appendHTTPServerAttributes(includeStatus bool, attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeHTTPMethod, "POST") + attrMap.UpsertString(conventions.AttributeHTTPScheme, "https") + attrMap.UpsertString(conventions.AttributeHTTPServerName, "api22.opentelemetry.io") + attrMap.UpsertInt(conventions.AttributeNetHostPort, 443) + attrMap.UpsertString(conventions.AttributeHTTPTarget, "/blog/posts") + attrMap.UpsertString(conventions.AttributeHTTPFlavor, "2") if includeStatus { - attrMap[conventions.AttributeHTTPStatusCode] = int64(201) + attrMap.UpsertInt(conventions.AttributeHTTPStatusCode, 201) } - attrMap[conventions.AttributeHTTPUserAgent] = - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" - attrMap[conventions.AttributeHTTPRoute] = "/blog/posts" - attrMap[conventions.AttributeHTTPClientIP] = "2001:506:71f0:16e::1" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap + attrMap.UpsertString(conventions.AttributeHTTPUserAgent, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36") + attrMap.UpsertString(conventions.AttributeHTTPRoute, "/blog/posts") + attrMap.UpsertString(conventions.AttributeHTTPClientIP, "2001:506:71f0:16e::1") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateMessagingProducerAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeMessagingSystem] = "nats" - attrMap[conventions.AttributeMessagingDestination] = "time.us.east.atlanta" - attrMap[conventions.AttributeMessagingDestinationKind] = "topic" - attrMap[conventions.AttributeMessagingMessageID] = "AA7C5438-D93A-43C8-9961-55613204648F" - attrMap["messaging.sequence"] = int64(1) - attrMap[conventions.AttributeNetPeerIP] = "10.10.212.33" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendMessagingProducerAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeMessagingSystem, "nats") + attrMap.UpsertString(conventions.AttributeMessagingDestination, "time.us.east.atlanta") + attrMap.UpsertString(conventions.AttributeMessagingDestinationKind, "topic") + attrMap.UpsertString(conventions.AttributeMessagingMessageID, "AA7C5438-D93A-43C8-9961-55613204648F") + attrMap.UpsertInt("messaging.sequence", 1) + attrMap.UpsertString(conventions.AttributeNetPeerIP, "10.10.212.33") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateMessagingConsumerAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeMessagingSystem] = "kafka" - attrMap[conventions.AttributeMessagingDestination] = "infrastructure-events-zone1" - attrMap[conventions.AttributeMessagingOperation] = "receive" - attrMap[conventions.AttributeNetPeerIP] = "2600:1700:1f00:11c0:4de0:c223:a800:4e87" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendMessagingConsumerAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeMessagingSystem, "kafka") + attrMap.UpsertString(conventions.AttributeMessagingDestination, "infrastructure-events-zone1") + attrMap.UpsertString(conventions.AttributeMessagingOperation, "receive") + attrMap.UpsertString(conventions.AttributeNetPeerIP, "2600:1700:1f00:11c0:4de0:c223:a800:4e87") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateGRPCClientAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeRPCService] = "PullRequestsService" - attrMap[conventions.AttributeNetPeerIP] = "2600:1700:1f00:11c0:4de0:c223:a800:4e87" - attrMap[conventions.AttributeNetHostPort] = int64(8443) - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendGRPCClientAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeRPCService, "PullRequestsService") + attrMap.UpsertString(conventions.AttributeNetPeerIP, "2600:1700:1f00:11c0:4de0:c223:a800:4e87") + attrMap.UpsertInt(conventions.AttributeNetHostPort, 8443) + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateGRPCServerAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeRPCService] = "PullRequestsService" - attrMap[conventions.AttributeNetPeerIP] = "192.168.1.70" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendGRPCServerAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeRPCService, "PullRequestsService") + attrMap.UpsertString(conventions.AttributeNetPeerIP, "192.168.1.70") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateInternalAttributes() map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap["parameters"] = "account=7310,amount=1817.10" - attrMap[conventions.AttributeEnduserID] = "unittest" - return attrMap +func appendInternalAttributes(attrMap pdata.AttributeMap) { + attrMap.UpsertString("parameters", "account=7310,amount=1817.10") + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") } -func generateMaxCountAttributes(includeStatus bool) map[string]interface{} { - attrMap := make(map[string]interface{}) - attrMap[conventions.AttributeHTTPMethod] = "POST" - attrMap[conventions.AttributeHTTPScheme] = "https" - attrMap[conventions.AttributeHTTPHost] = "api.opentelemetry.io" - attrMap[conventions.AttributeNetHostName] = "api22.opentelemetry.io" - attrMap[conventions.AttributeNetHostIP] = "2600:1700:1f00:11c0:1ced:afa5:fd88:9d48" - attrMap[conventions.AttributeNetHostPort] = int64(443) - attrMap[conventions.AttributeHTTPTarget] = "/blog/posts" - attrMap[conventions.AttributeHTTPFlavor] = "2" +func appendMaxCountAttributes(includeStatus bool, attrMap pdata.AttributeMap) { + attrMap.UpsertString(conventions.AttributeHTTPMethod, "POST") + attrMap.UpsertString(conventions.AttributeHTTPScheme, "https") + attrMap.UpsertString(conventions.AttributeHTTPHost, "api.opentelemetry.io") + attrMap.UpsertString(conventions.AttributeNetHostName, "api22.opentelemetry.io") + attrMap.UpsertString(conventions.AttributeNetHostIP, "2600:1700:1f00:11c0:1ced:afa5:fd88:9d48") + attrMap.UpsertInt(conventions.AttributeNetHostPort, 443) + attrMap.UpsertString(conventions.AttributeHTTPTarget, "/blog/posts") + attrMap.UpsertString(conventions.AttributeHTTPFlavor, "2") if includeStatus { - attrMap[conventions.AttributeHTTPStatusCode] = int64(201) - attrMap[conventions.AttributeHTTPStatusText] = "Created" + attrMap.UpsertInt(conventions.AttributeHTTPStatusCode, 201) + attrMap.UpsertString(conventions.AttributeHTTPStatusText, "Created") } - attrMap[conventions.AttributeHTTPUserAgent] = - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" - attrMap[conventions.AttributeHTTPRoute] = "/blog/posts" - attrMap[conventions.AttributeHTTPClientIP] = "2600:1700:1f00:11c0:1ced:afa5:fd77:9d01" - attrMap[conventions.AttributePeerService] = "IdentifyImageService" - attrMap[conventions.AttributeNetPeerIP] = "2600:1700:1f00:11c0:1ced:afa5:fd77:9ddc" - attrMap[conventions.AttributeNetPeerPort] = int64(39111) - attrMap["ai-sampler.weight"] = 0.07 - attrMap["ai-sampler.absolute"] = false - attrMap["ai-sampler.maxhops"] = int64(6) - attrMap["application.create.location"] = "https://api.opentelemetry.io/blog/posts/806673B9-4F4D-4284-9635-3A3E3E3805BE" + attrMap.UpsertString(conventions.AttributeHTTPUserAgent, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36") + attrMap.UpsertString(conventions.AttributeHTTPRoute, "/blog/posts") + attrMap.UpsertString(conventions.AttributeHTTPClientIP, "2600:1700:1f00:11c0:1ced:afa5:fd77:9d01") + attrMap.UpsertString(conventions.AttributePeerService, "IdentifyImageService") + attrMap.UpsertString(conventions.AttributeNetPeerIP, "2600:1700:1f00:11c0:1ced:afa5:fd77:9ddc") + attrMap.UpsertInt(conventions.AttributeNetPeerPort, 39111) + attrMap.UpsertDouble("ai-sampler.weight", 0.07) + attrMap.UpsertBool("ai-sampler.absolute", false) + attrMap.UpsertInt("ai-sampler.maxhops", 6) + attrMap.UpsertString("application.create.location", "https://api.opentelemetry.io/blog/posts/806673B9-4F4D-4284-9635-3A3E3E3805BE") stages := pdata.NewAttributeValueArray() stages.ArrayVal().Append(pdata.NewAttributeValueString("Launch")) stages.ArrayVal().Append(pdata.NewAttributeValueString("Injestion")) stages.ArrayVal().Append(pdata.NewAttributeValueString("Validation")) - attrMap["application.stages"] = stages - subMap := pdata.NewAttributeMap() - subMap.InsertBool("UIx", false) - subMap.InsertBool("UI4", true) - subMap.InsertBool("flow-alt3", false) - attrMap["application.abflags"] = subMap - attrMap["application.thread"] = "proc-pool-14" - attrMap["application.session"] = "" - attrMap["application.persist.size"] = int64(1172184) - attrMap["application.queue.size"] = int64(0) - attrMap["application.job.id"] = "0E38800B-9C4C-484E-8F2B-C7864D854321" - attrMap["application.service.sla"] = 0.34 - attrMap["application.service.slo"] = 0.55 - attrMap[conventions.AttributeEnduserID] = "unittest" - attrMap[conventions.AttributeEnduserRole] = "poweruser" - attrMap[conventions.AttributeEnduserScope] = "email profile administrator" - return attrMap + attrMap.Upsert("application.stages", stages) + subMap := pdata.NewAttributeValueMap() + subMap.MapVal().InsertBool("UIx", false) + subMap.MapVal().InsertBool("UI4", true) + subMap.MapVal().InsertBool("flow-alt3", false) + attrMap.Upsert("application.abflags", subMap) + attrMap.UpsertString("application.thread", "proc-pool-14") + attrMap.UpsertString("application.session", "") + attrMap.UpsertInt("application.persist.size", 1172184) + attrMap.UpsertInt("application.queue.size", 0) + attrMap.UpsertString("application.job.id", "0E38800B-9C4C-484E-8F2B-C7864D854321") + attrMap.UpsertDouble("application.service.sla", 0.34) + attrMap.UpsertDouble("application.service.slo", 0.55) + attrMap.UpsertString(conventions.AttributeEnduserID, "unittest") + attrMap.UpsertString(conventions.AttributeEnduserRole, "poweruser") + attrMap.UpsertString(conventions.AttributeEnduserScope, "email profile administrator") } -func generateSpanEvents(eventCnt PICTInputSpanChild) *pdata.SpanEventSlice { - spanEvents := pdata.NewSpanEventSlice() - if SpanChildCountNil == eventCnt { - return nil - } +func appendSpanEvents(eventCnt PICTInputSpanChild, spanEvents pdata.SpanEventSlice) { listSize := calculateListSize(eventCnt) for i := 0; i < listSize; i++ { - spanEvents.Append(generateSpanEvent(i)) + appendSpanEvent(i, spanEvents) } - return &spanEvents } -func generateSpanLinks(linkCnt PICTInputSpanChild, random io.Reader) *pdata.SpanLinkSlice { - spanLinks := pdata.NewSpanLinkSlice() - if SpanChildCountNil == linkCnt { - return nil - } +func appendSpanLinks(linkCnt PICTInputSpanChild, random io.Reader, spanLinks pdata.SpanLinkSlice) { listSize := calculateListSize(linkCnt) for i := 0; i < listSize; i++ { - spanLinks.Append(generateSpanLink(random, i)) + appendSpanLink(random, i, spanLinks) } - return &spanLinks } func calculateListSize(listCnt PICTInputSpanChild) int { @@ -477,63 +412,66 @@ func calculateListSize(listCnt PICTInputSpanChild) int { } } -func generateSpanEvent(index int) pdata.SpanEvent { - spanEvent := pdata.NewSpanEvent() +func appendSpanEvent(index int, spanEvents pdata.SpanEventSlice) { + spanEvent := spanEvents.AppendEmpty() t := time.Now().Add(-75 * time.Microsecond) - name, attributes := generateEventNameAndAttributes(index) spanEvent.SetTimestamp(pdata.Timestamp(t.UnixNano())) - spanEvent.SetName(name) - if attributes != nil { - attributes.CopyTo(spanEvent.Attributes()) - } - spanEvent.SetDroppedAttributesCount(0) - return spanEvent -} - -func generateEventNameAndAttributes(index int) (string, *pdata.AttributeMap) { switch index % 4 { case 0, 3: - attrMap := make(map[string]interface{}) + spanEvent.SetName("message") + attrMap := spanEvent.Attributes() if index%2 == 0 { - attrMap[conventions.AttributeMessageType] = "SENT" + attrMap.UpsertString(conventions.AttributeMessageType, "SENT") } else { - attrMap[conventions.AttributeMessageType] = "RECEIVED" + attrMap.UpsertString(conventions.AttributeMessageType, "RECEIVED") } - attrMap[conventions.AttributeMessageID] = int64(index / 4) - attrMap[conventions.AttributeMessageCompressedSize] = int64(17 * index) - attrMap[conventions.AttributeMessageUncompressedSize] = int64(24 * index) - return "message", convertMapToAttributeMap(attrMap) + attrMap.UpsertInt(conventions.AttributeMessageID, int64(index/4)) + attrMap.UpsertInt(conventions.AttributeMessageCompressedSize, int64(17*index)) + attrMap.UpsertInt(conventions.AttributeMessageUncompressedSize, int64(24*index)) case 1: - return "custom", convertMapToAttributeMap(map[string]interface{}{ - "app.inretry": true, - "app.progress": 0.6, - "app.statemap": "14|5|202"}) + spanEvent.SetName("custom") + attrMap := spanEvent.Attributes() + attrMap.UpdateBool("app.inretry", true) + attrMap.UpsertDouble("app.progress", 0.6) + attrMap.UpsertString("app.statemap", "14|5|202") default: - return "annotation", nil + spanEvent.SetName("annotation") } + + spanEvent.SetDroppedAttributesCount(0) } -func generateSpanLink(random io.Reader, index int) pdata.SpanLink { - spanLink := pdata.NewSpanLink() - spanLink.SetTraceID(generatePDataTraceID(random)) - spanLink.SetSpanID(generatePDataSpanID(random)) +func appendSpanLink(random io.Reader, index int, spanLinks pdata.SpanLinkSlice) { + spanLink := spanLinks.AppendEmpty() + spanLink.SetTraceID(generateTraceID(random)) + spanLink.SetSpanID(generateSpanID(random)) spanLink.SetTraceState("") if index%4 != 2 { - generateLinkAttributes(index).CopyTo(spanLink.Attributes()) + attrMap := spanLink.Attributes() + appendMessagingConsumerAttributes(attrMap) + if index%4 == 1 { + attrMap.UpdateBool("app.inretry", true) + attrMap.UpsertDouble("app.progress", 0.6) + attrMap.UpsertString("app.statemap", "14|5|202") + } } spanLink.SetDroppedAttributesCount(0) - return spanLink } -func generateLinkAttributes(index int) *pdata.AttributeMap { - if index%4 == 2 { - return nil +func generateTraceID(random io.Reader) pdata.TraceID { + var r [16]byte + _, err := random.Read(r[:]) + if err != nil { + panic(err) } - attrMap := generateMessagingConsumerAttributes() - if index%4 == 1 { - attrMap["app.inretry"] = true - attrMap["app.progress"] = 0.6 - attrMap["app.statemap"] = "14|5|202" + return pdata.NewTraceID(r) +} + +func generateSpanID(random io.Reader) pdata.SpanID { + var r [8]byte + _, err := random.Read(r[:]) + if err != nil { + panic(err) } - return convertMapToAttributeMap(attrMap) + return pdata.NewSpanID(r) } diff --git a/internal/goldendataset/span_generator_test.go b/internal/goldendataset/span_generator_test.go index 2a1ff8ef4f2..f42fa3d130a 100644 --- a/internal/goldendataset/span_generator_test.go +++ b/internal/goldendataset/span_generator_test.go @@ -25,7 +25,7 @@ import ( func TestGenerateParentSpan(t *testing.T) { random := rand.Reader - traceID := generatePDataTraceID(random) + traceID := generateTraceID(random) spanInputs := &PICTSpanInputs{ Parent: SpanParentRoot, Tracestate: TraceStateEmpty, @@ -35,7 +35,8 @@ func TestGenerateParentSpan(t *testing.T) { Links: SpanChildCountOne, Status: SpanStatusOk, } - span := GenerateSpan(traceID, pdata.NewSpanID([8]byte{}), "/gotest-parent", spanInputs, random) + span := pdata.NewSpan() + fillSpan(traceID, pdata.NewSpanID([8]byte{}), "/gotest-parent", spanInputs, random, span) assert.Equal(t, traceID, span.TraceID()) assert.True(t, span.ParentSpanID().IsEmpty()) assert.Equal(t, 11, span.Attributes().Len()) @@ -44,18 +45,19 @@ func TestGenerateParentSpan(t *testing.T) { func TestGenerateChildSpan(t *testing.T) { random := rand.Reader - traceID := generatePDataTraceID(random) - parentID := generatePDataSpanID(random) + traceID := generateTraceID(random) + parentID := generateSpanID(random) spanInputs := &PICTSpanInputs{ Parent: SpanParentChild, Tracestate: TraceStateEmpty, Kind: SpanKindClient, Attributes: SpanAttrDatabaseSQL, Events: SpanChildCountEmpty, - Links: SpanChildCountNil, + Links: SpanChildCountEmpty, Status: SpanStatusOk, } - span := GenerateSpan(traceID, parentID, "get_test_info", spanInputs, random) + span := pdata.NewSpan() + fillSpan(traceID, parentID, "get_test_info", spanInputs, random, span) assert.Equal(t, traceID, span.TraceID()) assert.Equal(t, parentID, span.ParentSpanID()) assert.Equal(t, 12, span.Attributes().Len()) @@ -65,15 +67,20 @@ func TestGenerateChildSpan(t *testing.T) { func TestGenerateSpans(t *testing.T) { random := rand.Reader count1 := 16 - spans, nextPos, err := GenerateSpans(count1, 0, "testdata/generated_pict_pairs_spans.txt", random) - assert.Nil(t, err) - assert.Equal(t, count1, len(spans)) + spans := pdata.NewSpanSlice() + err := appendSpans(count1, "testdata/generated_pict_pairs_spans.txt", random, spans) + assert.NoError(t, err) + assert.Equal(t, count1, spans.Len()) + count2 := 256 - spans, nextPos, err = GenerateSpans(count2, nextPos, "testdata/generated_pict_pairs_spans.txt", random) - assert.Nil(t, err) - assert.Equal(t, count2, len(spans)) + spans = pdata.NewSpanSlice() + err = appendSpans(count2, "testdata/generated_pict_pairs_spans.txt", random, spans) + assert.NoError(t, err) + assert.Equal(t, count2, spans.Len()) + count3 := 118 - spans, _, err = GenerateSpans(count3, nextPos, "testdata/generated_pict_pairs_spans.txt", random) - assert.Nil(t, err) - assert.Equal(t, count3, len(spans)) + spans = pdata.NewSpanSlice() + err = appendSpans(count3, "testdata/generated_pict_pairs_spans.txt", random, spans) + assert.NoError(t, err) + assert.Equal(t, count3, spans.Len()) } diff --git a/internal/goldendataset/testdata/pict_input_spans.txt b/internal/goldendataset/testdata/pict_input_spans.txt index 9430ce47e3e..f25602987d1 100644 --- a/internal/goldendataset/testdata/pict_input_spans.txt +++ b/internal/goldendataset/testdata/pict_input_spans.txt @@ -1,10 +1,10 @@ Parent: Root, Child Tracestate: Empty, One, Four Kind: Unspecified, Internal, Server, Client, Producer, Consumer -Attributes: Nil, Empty, DatabaseSQL, DatabaseNoSQL, FaaSDatasource, FaaSHTTP, FaaSPubSub, FaaSTimer, FaaSOther, HTTPClient, HTTPServer, MessagingProducer, MessagingConsumer, gRPCClient, gRPCServer, Internal, MaxCount -Events: Nil, Empty, One, Two, Eight -Links: Nil, Empty, One, Two, Eight -Status: Nil, Ok, Cancelled, UnknownError, InvalidArgument, DeadlineExceeded, NotFound, AlreadyExists, PermissionDenied, ResourceExhausted, FailedPrecondition, Aborted, OutOfRange, Unimplemented, InternalError, Unavailable, DataLoss, Unauthenticated +Attributes: Empty, DatabaseSQL, DatabaseNoSQL, FaaSDatasource, FaaSHTTP, FaaSPubSub, FaaSTimer, FaaSOther, HTTPClient, HTTPServer, MessagingProducer, MessagingConsumer, gRPCClient, gRPCServer, Internal, MaxCount +Events: Empty, One, Two, Eight +Links: Empty, One, Two, Eight +Status: Unset, Ok, Error IF [Parent] = "Root" THEN [Kind] in {"Server", "Producer"}; IF [Kind] = "Internal" THEN [Attributes] in {"Nil", "Internal"}; diff --git a/internal/goldendataset/testdata/pict_input_traces.txt b/internal/goldendataset/testdata/pict_input_traces.txt index ea9f40ed8a8..9eb0b9a29c1 100644 --- a/internal/goldendataset/testdata/pict_input_traces.txt +++ b/internal/goldendataset/testdata/pict_input_traces.txt @@ -1,3 +1,3 @@ -Resource: Nil, Empty, VMOnPrem, VMCloud, K8sOnPrem, K8sCloud, Faas, Exec +Resource: Empty, VMOnPrem, VMCloud, K8sOnPrem, K8sCloud, Faas, Exec InstrumentationLibrary: None, One, Two Spans: None, One, Several, All diff --git a/internal/goldendataset/traces_generator.go b/internal/goldendataset/traces_generator.go index 0078060802d..3e7ff540cc2 100644 --- a/internal/goldendataset/traces_generator.go +++ b/internal/goldendataset/traces_generator.go @@ -64,14 +64,16 @@ func GenerateTraces(tracePairsFile string, spanPairsFile string) ([]pdata.Traces func generateResourceSpan(tracingInputs *PICTTracingInputs, spanPairsFile string, random io.Reader) (pdata.ResourceSpans, error) { resourceSpan := pdata.NewResourceSpans() - libSpansSlice, err := generateLibrarySpansArray(tracingInputs, spanPairsFile, random) - libSpansSlice.CopyTo(resourceSpan.InstrumentationLibrarySpans()) + err := appendInstrumentationLibrarySpans(tracingInputs, spanPairsFile, random, resourceSpan.InstrumentationLibrarySpans()) + if err != nil { + return resourceSpan, err + } GenerateResource(tracingInputs.Resource).CopyTo(resourceSpan.Resource()) return resourceSpan, err } -func generateLibrarySpansArray(tracingInputs *PICTTracingInputs, spanPairsFile string, - random io.Reader) (pdata.InstrumentationLibrarySpansSlice, error) { +func appendInstrumentationLibrarySpans(tracingInputs *PICTTracingInputs, spanPairsFile string, + random io.Reader, instrumentationLibrarySpansSlice pdata.InstrumentationLibrarySpansSlice) error { var count int switch tracingInputs.InstrumentationLibrary { case LibraryNone: @@ -81,45 +83,36 @@ func generateLibrarySpansArray(tracingInputs *PICTTracingInputs, spanPairsFile s case LibraryTwo: count = 2 } - var err error - var libSpans *pdata.InstrumentationLibrarySpans - instrumentationLibrarySpansSlice := pdata.NewInstrumentationLibrarySpansSlice() for i := 0; i < count; i++ { - libSpans, err = generateLibrarySpans(tracingInputs, i, spanPairsFile, random) + libSpans, err := generateLibrarySpans(tracingInputs, i, spanPairsFile, random) if err != nil { - instrumentationLibrarySpansSlice.Append(*libSpans) + return err } + instrumentationLibrarySpansSlice.Append(libSpans) } - return instrumentationLibrarySpansSlice, err + return nil } -func generateLibrarySpans(tracingInputs *PICTTracingInputs, index int, spanPairsFile string, - random io.Reader) (*pdata.InstrumentationLibrarySpans, error) { +func generateLibrarySpans(tracingInputs *PICTTracingInputs, index int, spanPairsFile string, random io.Reader) (pdata.InstrumentationLibrarySpans, error) { instrumentationLibrarySpans := pdata.NewInstrumentationLibrarySpans() spanCaseCount, err := countTotalSpanCases(spanPairsFile) if err != nil { - return nil, err + return instrumentationLibrarySpans, err } - var spans []pdata.Span + fillInstrumentationLibrary(tracingInputs, index, instrumentationLibrarySpans.InstrumentationLibrary()) switch tracingInputs.Spans { case LibrarySpansNone: - spans = make([]pdata.Span, 0) + break case LibrarySpansOne: - spans, _, err = GenerateSpans(1, 0, spanPairsFile, random) + err = appendSpans(1, spanPairsFile, random, instrumentationLibrarySpans.Spans()) case LibrarySpansSeveral: - spans, _, err = GenerateSpans(spanCaseCount/4, 0, spanPairsFile, random) + err = appendSpans(spanCaseCount/4, spanPairsFile, random, instrumentationLibrarySpans.Spans()) case LibrarySpansAll: - spans, _, err = GenerateSpans(spanCaseCount, 0, spanPairsFile, random) + err = appendSpans(spanCaseCount, spanPairsFile, random, instrumentationLibrarySpans.Spans()) default: - spans, _, err = GenerateSpans(16, 0, spanPairsFile, random) - } - spanSlice := pdata.NewSpanSlice() - for _, span := range spans { - spanSlice.Append(span) + err = appendSpans(16, spanPairsFile, random, instrumentationLibrarySpans.Spans()) } - generateInstrumentationLibrary(tracingInputs, index).CopyTo(instrumentationLibrarySpans.InstrumentationLibrary()) - spanSlice.CopyTo(instrumentationLibrarySpans.Spans()) - return &instrumentationLibrarySpans, err + return instrumentationLibrarySpans, err } func countTotalSpanCases(spanPairsFile string) (int, error) { @@ -131,18 +124,15 @@ func countTotalSpanCases(spanPairsFile string) (int, error) { return count, err } -func generateInstrumentationLibrary(tracingInputs *PICTTracingInputs, index int) pdata.InstrumentationLibrary { - instrumentationLibrary := pdata.NewInstrumentationLibrary() - if LibraryNone == tracingInputs.InstrumentationLibrary { - return instrumentationLibrary +func fillInstrumentationLibrary(tracingInputs *PICTTracingInputs, index int, instrumentationLibrary pdata.InstrumentationLibrary) { + if tracingInputs.InstrumentationLibrary == LibraryNone { + return } - nameStr := fmt.Sprintf("%s-%s-%s-%d", tracingInputs.Resource, tracingInputs.InstrumentationLibrary, - tracingInputs.Spans, index) + nameStr := fmt.Sprintf("%s-%s-%s-%d", tracingInputs.Resource, tracingInputs.InstrumentationLibrary, tracingInputs.Spans, index) verStr := "semver:1.1.7" if index > 0 { verStr = "" } instrumentationLibrary.SetName(nameStr) instrumentationLibrary.SetVersion(verStr) - return instrumentationLibrary } diff --git a/service/internal/zpages/tmplgen/resources.go b/service/internal/zpages/tmplgen/resources.go index 07ba63457f6..6e15c8c3320 100644 --- a/service/internal/zpages/tmplgen/resources.go +++ b/service/internal/zpages/tmplgen/resources.go @@ -1,17 +1,3 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - // Code generated by "esc -pkg tmplgen -o resources.go -modtime 0 ../templates/"; DO NOT EDIT. package tmplgen diff --git a/translator/internaldata/resource_to_oc_test.go b/translator/internaldata/resource_to_oc_test.go index dc8765ec2c2..113572749cb 100644 --- a/translator/internaldata/resource_to_oc_test.go +++ b/translator/internaldata/resource_to_oc_test.go @@ -192,7 +192,6 @@ func TestInferResourceType(t *testing.T) { func TestResourceToOCAndBack(t *testing.T) { tests := []goldendataset.PICTInputResource{ - goldendataset.ResourceNil, goldendataset.ResourceEmpty, goldendataset.ResourceVMOnPrem, goldendataset.ResourceVMCloud,