classifySpan extracts service graph metadata from raw span attributes. Returns peer_type ("db", "http", "cache", "queue", "unknown") and peer_address.
(span RawSpan)
| 8 | // classifySpan extracts service graph metadata from raw span attributes. |
| 9 | // Returns peer_type ("db", "http", "cache", "queue", "unknown") and peer_address. |
| 10 | func classifySpan(span RawSpan) (peerType string, peerAddress string) { |
| 11 | op := span.Op |
| 12 | attrs := span.Data |
| 13 | |
| 14 | switch { |
| 15 | case strings.HasPrefix(op, "db."): |
| 16 | peerType = "db" |
| 17 | peerAddress = firstNonEmpty( |
| 18 | attrs["server.address"], |
| 19 | attrs["db.server.address"], |
| 20 | attrs["db.name"], |
| 21 | ) |
| 22 | case op == "http.client": |
| 23 | peerType = "http" |
| 24 | if raw := attrs["http.url"]; raw != "" { |
| 25 | if u, err := url.Parse(raw); err == nil { |
| 26 | peerAddress = u.Host |
| 27 | } |
| 28 | } |
| 29 | case strings.HasPrefix(op, "cache."): |
| 30 | peerType = "cache" |
| 31 | peerAddress = attrs["server.address"] |
| 32 | case strings.HasPrefix(op, "queue."): |
| 33 | peerType = "queue" |
| 34 | peerAddress = attrs["messaging.destination"] |
| 35 | default: |
| 36 | peerType = "unknown" |
| 37 | } |
| 38 | |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | // extractServiceName extracts the service name from span attributes or SDK info. |
| 43 | func extractServiceName(span RawSpan, sdk *SDK) string { |