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

feature(backend): updating metadata fields to match semantic conventions #2717

Conversation

xoscar
Copy link
Collaborator

@xoscar xoscar commented Jun 12, 2023

This PR updates the tracetest metadata attributes to match the semantic conventions

Changes

  • Creates MetadataFields type for tracetest related stuff
  • Implements usage of constant types for spans
  • Updates FE to use new fields

Fixes

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

https://www.loom.com/share/f78af5a0e33f4a1e9e812acb5115c856

@xoscar xoscar added the backend label Jun 12, 2023
@xoscar xoscar self-assigned this Jun 12, 2023
@xoscar xoscar linked an issue Jun 12, 2023 that may be closed by this pull request
@xoscar xoscar marked this pull request as ready for review June 12, 2023 22:58
Copy link
Collaborator

@schoren schoren left a comment

Choose a reason for hiding this comment

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

this looks great! the constants make the code nicer. I think there might be a typo on one of the keys, and also this is changing one of the keys, not sure if that's intentional or not

@@ -9,6 +9,18 @@ import (
"go.opentelemetry.io/otel/trace"
)

type TracetestMetadataField string
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we really need this type? it seems that all the references to values for this convert it to string, and no other operation is done. Given that this is just a constant to avoid repetition, and it's very unlikely that we'd want to attach methods to it, does it make sense to keep it as a simple "string"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done 😄

TracetestMetadataFieldDuration TracetestMetadataField = "tracetest.span.duration"
TracetestMetadataFieldType TracetestMetadataField = "tracetest.span.type"
TracetestMetadataFieldName TracetestMetadataField = "tracetest.span.name"
TracetestMetadataFieldParentID TracetestMetadataField = "tracetest.span.parent_uid"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this field renamed to parent_Uid intentionally or is it a typo?

Suggested change
TracetestMetadataFieldParentID TracetestMetadataField = "tracetest.span.parent_uid"
TracetestMetadataFieldParentID TracetestMetadataField = "tracetest.span.parent_id"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was definitely a fat finger

@@ -25,7 +25,7 @@ func NewTrace(traceID string, spans []Span) Trace {

rootSpans := make([]*Span, 0)
for _, span := range spanMap {
parentID := span.Attributes["parent_id"]
parentID := span.Attributes[string(TracetestMetadataFieldParentID)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

this values are not the same. the original key is parent_id, but the value defined in the constant is tracetest.span.parent_uid. Is this intentional? Doesn't this changes the key?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

@@ -57,6 +57,7 @@ func (m OpenAPI) Span(in model.Span) openapi.Span {
EndTime: in.EndTime.UnixMilli(),
Attributes: attributes,
Children: m.Spans(in.Children),
Name: in.Name,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just found this bug we have had for a while now haha

@@ -21,10 +25,24 @@ func (ds AttributeDataStore) Source() string {
return "attr"
}

func (ds AttributeDataStore) getFromAlias(name string) (string, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding alias check, in this case we only support name for the moment

@xoscar xoscar requested a review from schoren June 13, 2023 16:39
Copy link
Collaborator

@schoren schoren left a comment

Choose a reason for hiding this comment

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

left 2 suggestions that IMO might make the code cleaner, other than that it looks great!

Comment on lines 30 to 37
if found {
value := ds.Span.Attributes.Get(alias)
if value == "" {
return "", fmt.Errorf(`attribute "%s" not found`, alias)
}

return value, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can reduce nesting here:

Suggested change
if found {
value := ds.Span.Attributes.Get(alias)
if value == "" {
return "", fmt.Errorf(`attribute "%s" not found`, alias)
}
return value, nil
}
if !found {
return "", fmt.Errorf(`attribute "%s" not found`, alias)
}
value := ds.Span.Attributes.Get(alias)
if value == "" {
return "", fmt.Errorf(`attribute "%s" not found`, alias)
}
return value, nil

@@ -13,6 +13,10 @@ type DataStore interface {
Get(name string) (string, error)
}

var AttributeAlias = map[string]string{
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be unexported?

Copy link
Contributor

@jorgeepc jorgeepc left a comment

Choose a reason for hiding this comment

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

Tested it, looks good!

@xoscar xoscar merged commit 84f4e11 into main Jun 13, 2023
24 checks passed
@xoscar xoscar deleted the 2713-analyzer-results-fix-validations-for-tracetest-custom-attributes branch June 13, 2023 18:22
mathnogueira pushed a commit that referenced this pull request Jun 14, 2023
…ons (#2717)

* feature(backend): updating metadata fields to match semantic conventions

* feature(backend): PR improvements and aliases for attributes

* feature(backend): fixing unit tests

* feature(backend): PR improvements

* feature(backend): fixing error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Analyzer Results] Fix validations for Tracetest custom attributes
4 participants