diff --git a/cmd/generator/code.go b/cmd/generator/code.go index 2831438..8fe92be 100644 --- a/cmd/generator/code.go +++ b/cmd/generator/code.go @@ -33,6 +33,10 @@ import ( func (d *{{ .StructName }}) Attributes() []attribute.KeyValue { var attrs []attribute.KeyValue + {{- if .SchemeDataType }} + attrs = append(attrs, attribute.String("dataType", "{{ .SchemeDataType }}")) + {{ end }} + {{ range .Fields -}} attrs = append(attrs, {{ .AttributesSource }}) {{ end }} @@ -49,6 +53,7 @@ type codeGen struct { TelemetryPackageAlias string ExportablePackagePrefix string StructName string + SchemeDataType string BuildTags string Fields []codeField } @@ -73,10 +78,11 @@ func getAttributeType(kind types.BasicKind) string { } type codeGenConfig struct { - packagePath string - typeName string - buildTags string - fields []field + packagePath string + typeName string + schemeDataType string + buildTags string + fields []field } func generateCode(writer io.Writer, cfg codeGenConfig) error { @@ -129,6 +135,7 @@ func generateCode(writer io.Writer, cfg codeGenConfig) error { TelemetryPackageAlias: telemetryPkgAlias, TelemetryPackagePath: telemetryPkg, StructName: cfg.typeName, + SchemeDataType: cfg.schemeDataType, Fields: codeFields, BuildTags: cfg.buildTags, } diff --git a/cmd/generator/main.go b/cmd/generator/main.go index eeab66b..44a03bc 100644 --- a/cmd/generator/main.go +++ b/cmd/generator/main.go @@ -92,10 +92,11 @@ func main() { } codeCfg := codeGenConfig{ - packagePath: result.packagePath, - typeName: *typeName, - fields: result.fields, - buildTags: codeGenBuildTags, + packagePath: result.packagePath, + typeName: *typeName, + schemeDataType: *schemeDataFabricDataType, + fields: result.fields, + buildTags: codeGenBuildTags, } if err := generateCode(file, codeCfg); err != nil { diff --git a/cmd/generator/tests/data_attributes_generated.go b/cmd/generator/tests/data_attributes_generated.go index f58e099..62445cb 100644 --- a/cmd/generator/tests/data_attributes_generated.go +++ b/cmd/generator/tests/data_attributes_generated.go @@ -14,6 +14,8 @@ import ( func (d *Data) Attributes() []attribute.KeyValue { var attrs []attribute.KeyValue + attrs = append(attrs, attribute.String("dataType", "ngf-product-telemetry")) + attrs = append(attrs, attribute.String("SomeString", d.SomeString)) attrs = append(attrs, attribute.Int64("SomeInt", d.SomeInt)) diff --git a/cmd/generator/tests/data_test.go b/cmd/generator/tests/data_test.go index ab646e3..860a4cf 100644 --- a/cmd/generator/tests/data_test.go +++ b/cmd/generator/tests/data_test.go @@ -36,6 +36,7 @@ func TestData_Attributes(t *testing.T) { } expectedAttributes := []attribute.KeyValue{ + attribute.String("dataType", "ngf-product-telemetry"), attribute.String("SomeString", "some string"), attribute.Int64("SomeInt", 42), attribute.Float64("SomeFloat", 3.14), @@ -65,6 +66,7 @@ func TestData_AttributesEmpty(t *testing.T) { data := Data{} expectedAttributes := []attribute.KeyValue{ + attribute.String("dataType", "ngf-product-telemetry"), attribute.String("SomeString", ""), attribute.Int64("SomeInt", 0), attribute.Float64("SomeFloat", 0),