Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing attribute sent along with the data #40

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cmd/generator/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -49,6 +53,7 @@ type codeGen struct {
TelemetryPackageAlias string
ExportablePackagePrefix string
StructName string
SchemeDataType string
BuildTags string
Fields []codeField
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/generator/tests/data_attributes_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions cmd/generator/tests/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Loading