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

Add unmarshal for ExporterType #3565

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions trace/exporter_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func (t ExporterType) MarshalJSON() ([]byte, error) {
return []byte(`"` + t.String() + `"`), nil
}

func (t *ExporterType) UnmarshalJSON(b []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, "null" == string(b) should be a noop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some test vectors for marshal and unmarshal?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

exporterTypeStr := strings.Trim(string(b), `"`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be erroring if the quotes are formatted unexpectedly? For instance:

  • grpc
  • "grpc
  • ""grpc
  • ""grpc"""

would all be unmarshalled without issue, but non of them are formatted as expected.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

exporterType, err := ExporterTypeFromString(exporterTypeStr)
if err != nil && !errors.Is(err, errUnknownExporterType) {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional) I think we could remove the special case error check and just return an error on unknown

*t = exporterType
return nil
}

func (t ExporterType) String() string {
switch t {
case GRPC:
Expand Down