in module/apmot/span.go [145:224]
func (s *otSpan) setSpanContext() {
var (
dbContext apm.DatabaseSpanContext
component string
httpURL string
httpMethod string
httpHost string
haveDBContext bool
haveHTTPContext bool
haveHTTPHostTag bool
)
for k, v := range s.tags {
switch k {
case "component":
component = stringify(v)
case "db.instance":
dbContext.Instance = stringify(v)
haveDBContext = true
case "db.statement":
dbContext.Statement = stringify(v)
haveDBContext = true
case "db.type":
dbContext.Type = stringify(v)
haveDBContext = true
case "db.user":
dbContext.User = stringify(v)
haveDBContext = true
case "http.url":
haveHTTPContext = true
httpURL = stringify(v)
case "http.method":
haveHTTPContext = true
httpMethod = stringify(v)
case "http.host":
haveHTTPContext = true
haveHTTPHostTag = true
httpHost = stringify(v)
// Elastic APM-specific tags:
case "type":
s.span.Type = stringify(v)
default:
s.span.Context.SetLabel(k, stringify(v))
}
}
switch {
case haveHTTPContext:
if s.span.Type == "" {
s.span.Type = "external"
s.span.Subtype = "http"
}
url, err := url.Parse(httpURL)
if err == nil {
// handles the case where the url.Host hasn't been set.
// Tries obtaining the host value from the "http.host" tag.
// If not found, or if the url.Host has a value, it won't
// mutate the existing host.
if url.Host == "" && haveHTTPHostTag {
url.Host = httpHost
}
s.span.Context.SetHTTPRequest(&http.Request{
ProtoMinor: 1,
ProtoMajor: 1,
Method: httpMethod,
URL: url,
})
}
case haveDBContext:
if s.span.Type == "" {
s.span.Type = "db"
s.span.Subtype = dbContext.Type
}
s.span.Context.SetDatabase(dbContext)
}
if s.span.Type == "" {
s.span.Type = "custom"
s.span.Subtype = component
}
}