Skip to content

Commit

Permalink
fix(server): Return type for browser spans (#3443)
Browse files Browse the repository at this point in the history
* fix(server): Return  type for browser spans

* adding test

* adding test

* More tests and fixing bugs
  • Loading branch information
xoscar authored Dec 15, 2023
1 parent 228fedc commit c9f1526
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/traces/trace_entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ func getRootSpan(allRoots []*Span) *Span {
return root
}

// TODO: this is temp while we decide what to do with browser spans and how to handle them
func isBrowserSpan(attrs Attributes) bool {
return attrs.Get("event_type") != "" || attrs.Get(TracetestMetadataFieldName) == "documentLoad"
}

func spanType(attrs Attributes) string {
if isBrowserSpan(attrs) {
return "general"
}

// based on https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions
// using the first required attribute for each type
for key := range attrs.Values() {
Expand All @@ -149,6 +158,7 @@ func spanType(attrs Attributes) string {
return "exception"
}
}

return "general"
}

Expand Down
30 changes: 30 additions & 0 deletions server/traces/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,36 @@ func TestUnmarshalLargeTrace(t *testing.T) {
assert.Greater(t, len(trace.Flat), 0)
}

func TestBrowserSpan(t *testing.T) {
span := newSpan("click")
span.Attributes = attributesFromMap(map[string]string{
"event_type": "click",
"http.url": "http://localhost:1663",
})

trace := traces.NewTrace("trace", []traces.Span{span})

assert.Equal(t, trace.Spans()[0].Attributes.Get(traces.TracetestMetadataFieldType), "general")

span2 := newSpan("documentLoad")
span2.Attributes = attributesFromMap(map[string]string{
"http.url": "http://localhost:1663",
})

trace2 := traces.NewTrace("trace", []traces.Span{span2})

assert.Equal(t, trace2.Spans()[0].Attributes.Get(traces.TracetestMetadataFieldType), "general")

span3 := newSpan("GET /api/v1/trace")
span3.Attributes = attributesFromMap(map[string]string{
"http.url": "http://localhost:1663",
})

trace3 := traces.NewTrace("trace", []traces.Span{span3})

assert.Equal(t, trace3.Spans()[0].Attributes.Get(traces.TracetestMetadataFieldType), "http")
}

func attributesFromMap(input map[string]string) traces.Attributes {
attributes := traces.NewAttributes()
for key, value := range input {
Expand Down

0 comments on commit c9f1526

Please sign in to comment.