Skip to content

Commit

Permalink
fix(backend): validate required event & span attributes
Browse files Browse the repository at this point in the history
fixes #1589

Signed-off-by: detj <[email protected]>
  • Loading branch information
detj committed Dec 10, 2024
1 parent 07dc742 commit d40c478
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
20 changes: 20 additions & 0 deletions backend/api/event/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@ func (a Attribute) Validate() error {
return fmt.Errorf(`%q does not contain a valid platform value`, `attribute.platform`)
}

if a.InstallationID == uuid.Nil {
return fmt.Errorf(`%q must not be empty`, `attribute.installation_id`)
}

if a.MeasureSDKVersion == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.measure_sdk_version`)
}

if a.AppVersion == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.app_version`)
}

if a.AppBuild == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.app_build`)
}

if a.AppUniqueID == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.app_unique_id`)
}

if len(a.AppVersion) > maxAppVersionChars {
return fmt.Errorf(`%q exceeds maximum allowed characters of %d`, `attribute.app_version`, maxAppVersionChars)
}
Expand Down
26 changes: 24 additions & 2 deletions backend/api/span/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ func (s *SpanField) Validate() error {
return fmt.Errorf(`%q must be a valid ISO 8601 timestamp`, `end_time`)
}

if s.Attributes.InstallationID == uuid.Nil {
return fmt.Errorf(`%q must be a valid UUID`, `attribute.installation_id`)
}

if s.Attributes.MeasureSDKVersion == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.measure_sdk_version`)
}

if s.Attributes.AppVersion == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.app_version`)
}

if s.Attributes.AppBuild == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.app_build`)
}

if s.Attributes.AppUniqueID == "" {
return fmt.Errorf(`%q must not be empty`, `attribute.app_unique_id`)
}

if len(s.Attributes.AppUniqueID) > maxAppUniqueIDChars {
return fmt.Errorf(`%q exceeds maximum allowed characters of %d`, `attrubute.app_unique_id`, maxAppUniqueIDChars)
}
Expand Down Expand Up @@ -234,8 +254,10 @@ func (s *SpanField) Validate() error {
return fmt.Errorf(`%q exceeds maximum allowed characters of %d`, `platform`, maxPlatformChars)
}

if s.Attributes.Platform != platform.Android && s.Attributes.Platform != platform.IOS {
return fmt.Errorf(`%q does not contain a valid platform value`, `platform`)
switch s.Attributes.Platform {
case platform.Android, platform.IOS:
default:
return fmt.Errorf(`%q does not contain a valid platform value`, `attribute.platform`)
}

if len(s.Attributes.ThreadName) > maxThreadNameChars {
Expand Down

0 comments on commit d40c478

Please sign in to comment.