sourcegraph / appdash

Application tracing system for Go, based on Google's Dapper.
https://sourcegraph.com
Other
1.72k stars 137 forks source link

why Annotations type is slice , not map[string][]byte? #206

Closed 1046102779 closed 6 years ago

1046102779 commented 6 years ago

Annotations's methods include

func (as Annotations) get(key string) []byte {...}

func (as Annotations) schemas() []string {...}

these method' implementation hasn't consider multiple same keys

keegancsmith commented 6 years ago

Those methods are not exported, and they explicitly document the behaviour. I'm unsure why it isn't a map. Maybe @slimsag remembers why?

1046102779 commented 6 years ago

but the method 'annotationsFromWire' uses pb data to append annotations, if client annotations with SQL, and the server uses the method to append , and it will be occur overide key= "SQL"

slimsag commented 6 years ago

It's been multiple years since I've looked at Appdash code. Unfortunately, I don't remember why this was done this way.

My best guess: It may have just been that Annotations only need to be unique for a span, so the change of overlap was small if the SQL key included e.g. the actual SQL query being executed (which IIRC was the case).

1046102779 commented 6 years ago

i know why.

Annotations type is slice , and its store&get operations is in order, and map is disorder

when we get data from annotations, it keeps original order is pretty good. the same type's data is tobe together. a unit is "_schema:xxx"

        "Client.Request.Headers.Connection":    "close",
        "Client.Request.Headers.Accept":        "application/json",
        "Client.Request.Headers.Authorization": "REDACTED",
        "Client.Request.Proto":                 "HTTP/1.1",
        "Client.Request.RemoteAddr":            "127.0.0.1",
        "Client.Request.Host":                  "example.com",
        "Client.Request.ContentLength":         "0",
        "Client.Request.Method":                "GET",
        "Client.Request.URI":                   "/foo",
        "Client.Response.StatusCode":           "200",
        "Client.Response.ContentLength":        "0",
        "Client.Send":                          "0001-01-01T00:00:00Z",
        "Client.Recv":                          "0001-01-01T00:00:00Z",
         "_schema:HTTPClient":                   "",

         ......
        "_schema:msg":  "",

        .......
       "_schema:timestamp": "",