Skip to content

Commit

Permalink
fix 2 task processing errors (#8762)
Browse files Browse the repository at this point in the history
## Summary

* fix console message attribute unmarshalling
* fix network payload integer overflow.

## How did you test this change?

![Screenshot from 2024-06-14
12-18-23](https://github.com/highlight/highlight/assets/1351531/c1869df1-1cc9-4d5c-a80d-d726775c1f1d)

<img width="1778" alt="Screenshot 2024-06-13 at 11 14 06"
src="https://github.com/highlight/highlight/assets/1351531/1794395c-d78b-4135-a4a5-217377bb3677">

<img width="1794" alt="Screenshot 2024-06-13 at 11 13 36"
src="https://github.com/highlight/highlight/assets/1351531/4f331471-0401-4c7e-8211-cddf4732be97">


## Are there any deployment considerations?

no

## Does this work require review from our design team?

no
  • Loading branch information
Vadman97 committed Jun 15, 2024
1 parent bd3ee37 commit 072137b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
51 changes: 30 additions & 21 deletions backend/public-graph/graph/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ type FieldData struct {
}

type Request struct {
ID string `json:"id"`
URL string `json:"url"`
Method string `json:"verb"`
Headers map[string]string `json:"headers"`
Body any `json:"body"`
ID string `json:"id"`
URL string `json:"url"`
Method string `json:"verb"`
HeadersRaw any `json:"headers"`
Body any `json:"body"`
}

type Response struct {
Status float64 `json:"status"`
Size float64 `json:"size"`
Headers map[string]string `json:"headers"`
Body any `json:"body"`
Status float64 `json:"status"`
Size float64 `json:"size"`
HeadersRaw any `json:"headers"`
Body any `json:"body"`
}

type RequestResponsePairs struct {
Expand Down Expand Up @@ -175,9 +175,9 @@ type NetworkResource struct {
ResponseStartAbs float64 `json:"responseStartAbs"`
SecureConnectionStartAbs float64 `json:"secureConnectionStartAbs"`
WorkerStartAbs float64 `json:"workerStartAbs"`
DecodedBodySize int64 `json:"decodedBodySize"`
TransferSize int64 `json:"transferSize"`
EncodedBodySize int64 `json:"encodedBodySize"`
DecodedBodySize float64 `json:"decodedBodySize"`
TransferSize float64 `json:"transferSize"`
EncodedBodySize float64 `json:"encodedBodySize"`
NextHopProtocol string `json:"nextHopProtocol"`
InitiatorType string `json:"initiatorType"`
Name string `json:"name"`
Expand Down Expand Up @@ -3123,6 +3123,9 @@ func (r *Resolver) submitFrontendNetworkMetric(ctx context.Context, sessionObj *
if url, err := url2.Parse(re.Name); err == nil && url.Host == "pub.highlight.io" {
continue
}
requestHeaders, _ := re.RequestResponsePairs.Request.HeadersRaw.(map[string]interface{})
responseHeaders, _ := re.RequestResponsePairs.Response.HeadersRaw.(map[string]interface{})
userAgent, _ := requestHeaders["User-Agent"].(string)
requestBody, ok := re.RequestResponsePairs.Request.Body.(string)
if !ok {
bdBytes, err := json.Marshal(requestBody)
Expand Down Expand Up @@ -3153,15 +3156,15 @@ func (r *Resolver) submitFrontendNetworkMetric(ctx context.Context, sessionObj *
semconv.HTTPURL(re.Name),
attribute.String("http.request.body", requestBody),
attribute.String("http.response.body", responseBody),
attribute.Int64("http.response.encoded.size", re.EncodedBodySize),
attribute.Int64("http.response.decoded.size", re.DecodedBodySize),
attribute.Int64("http.response.transfer.size", re.TransferSize),
attribute.Float64("http.response.encoded.size", re.EncodedBodySize),
attribute.Float64("http.response.decoded.size", re.DecodedBodySize),
attribute.Float64("http.response.transfer.size", re.TransferSize),
semconv.HTTPRequestContentLength(len(requestBody)),
semconv.HTTPResponseContentLength(int(re.RequestResponsePairs.Response.Size)),
semconv.HTTPStatusCode(int(re.RequestResponsePairs.Response.Status)),
semconv.HTTPMethod(method),
semconv.HTTPUserAgent(re.RequestResponsePairs.Request.Headers["User-Agent"]),
semconv.UserAgentOriginal(re.RequestResponsePairs.Request.Headers["User-Agent"]),
semconv.HTTPUserAgent(userAgent),
semconv.UserAgentOriginal(userAgent),
attribute.String(privateModel.NetworkRequestAttributeInitiatorType.String(), re.InitiatorType),
attribute.Float64(privateModel.NetworkRequestAttributeLatency.String(), float64(end.Sub(start).Nanoseconds())),
attribute.Float64(privateModel.NetworkRequestAttributeConnectLatency.String(), (re.ConnectEndAbs-re.ConnectStartAbs)*1e6),
Expand All @@ -3171,11 +3174,17 @@ func (r *Resolver) submitFrontendNetworkMetric(ctx context.Context, sessionObj *
if u, err := url2.Parse(re.Name); err == nil {
attributes = append(attributes, semconv.HTTPScheme(u.Scheme), semconv.HTTPTarget(u.Path))
}
for requestHeader, requestHeaderValue := range re.RequestResponsePairs.Request.Headers {
attributes = append(attributes, attribute.String(fmt.Sprintf("http.request.header.%s", requestHeader), requestHeaderValue))
for requestHeader, requestHeaderValue := range requestHeaders {
str, ok := requestHeaderValue.(string)
if ok {
attributes = append(attributes, attribute.String(fmt.Sprintf("http.request.header.%s", requestHeader), str))
}
}
for responseHeader, responseHeaderValue := range re.RequestResponsePairs.Response.Headers {
attributes = append(attributes, attribute.String(fmt.Sprintf("http.response.header.%s", responseHeader), responseHeaderValue))
for responseHeader, responseHeaderValue := range responseHeaders {
str, ok := responseHeaderValue.(string)
if ok {
attributes = append(attributes, attribute.String(fmt.Sprintf("http.response.header.%s", responseHeader), str))
}
}
requestBodyJson := make(map[string]interface{})
// if the request body is json and contains the graphql key operationName, treat it as an operation
Expand Down
33 changes: 19 additions & 14 deletions sdk/highlight-go/log/console_messages_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hlog
import (
"encoding/json"
e "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"strconv"
)

Expand All @@ -15,12 +16,12 @@ type MessageTrace struct {
}

type Message struct {
Type string `json:"type"`
Trace []MessageTrace `json:"trace"`
Value []string `json:"value"`
AttributesString string `json:"attributes"`
Time int64 `json:"time"`
Attributes map[string]any
Type string `json:"type"`
Trace []MessageTrace `json:"trace"`
Value []string `json:"value"`
AttributesRaw any `json:"attributes"`
Time int64 `json:"time"`
Attributes map[string]any
}

type Messages struct {
Expand All @@ -36,16 +37,20 @@ func ParseConsoleMessages(messages string) ([]*Message, error) {
var rows []*Message
for _, message := range messagesParsed.Messages {
msg := &Message{
Type: message.Type,
Trace: message.Trace,
Time: message.Time,
AttributesString: message.AttributesString,
Attributes: map[string]any{},
Type: message.Type,
Trace: message.Trace,
Time: message.Time,
AttributesRaw: message.AttributesRaw,
Attributes: map[string]any{},
}
if message.AttributesString != "" {
if err := json.Unmarshal([]byte(msg.AttributesString), &msg.Attributes); err != nil {
return nil, e.Wrap(err, "error decoding message attributes")
if attrString, ok := message.AttributesRaw.(string); ok && attrString != "" {
if err := json.Unmarshal([]byte(attrString), &msg.Attributes); err != nil {
log.WithField("attributes.raw", message.AttributesRaw).WithError(err).Warn("error decoding message attributes")
message.Attributes["attributes.raw"] = message.AttributesRaw
}
} else {
log.WithField("attributes.raw", message.AttributesRaw).Warn("unknown console message attribute format")
message.Attributes["attributes.raw"] = message.AttributesRaw
}
var messageValue []string
for _, v := range message.Value {
Expand Down

0 comments on commit 072137b

Please sign in to comment.