Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/test/oats/http/yaml/oats_python_outgoing_host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ expected:
metrics:
- promql: 'traces_service_graph_request_client_count{client="testserver", server="www.google.com"}'
value: "> 5"
traces:
- traceql: '{kind=client && name="GET /" && span.peer.service="www.google.com"}'
spans:
- name: "GET /"
allow-duplicates: true
1 change: 1 addition & 0 deletions internal/test/oats/sql/yaml/oats_sql_other_langs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ expected:
db.collection.name: accounting.contacts
db.system.name: postgresql
db.query.text: "SELECT * FROM accounting.contacts WHERE id = 1"
peer.service: sqlserver
metrics:
- promql: 'db_client_operation_duration_sum{db_system_name="postgresql"}'
value: "> 0"
Expand Down
17 changes: 17 additions & 0 deletions pkg/appolly/app/request/metric_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"strings"

"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"

attr "go.opentelemetry.io/obi/pkg/export/attributes/names"
)
Expand Down Expand Up @@ -174,6 +175,10 @@
return attribute.Key(attr.CloudRegion).String(val)
}

func PeerService(val string) attribute.KeyValue {
return attribute.Key(semconv.PeerServiceKey).String(val)

Check failure on line 179 in pkg/appolly/app/request/metric_attributes.go

View workflow job for this annotation

GitHub Actions / test

unnecessary conversion (unconvert)
}

func SpanHost(span *Span) string {
if span.HostName != "" {
return span.HostName
Expand Down Expand Up @@ -240,6 +245,18 @@
return SpanHost(span)
}

func PeerServiceFromSpan(span *Span) string {
if !span.IsClientSpan() {
return ""
}

if span.OtherNamespace != "" && span.OtherNamespace != span.Service.UID.Namespace && span.HostName != "" {
return span.HostName + "." + span.OtherNamespace
}

return span.HostName
}

func PeerAsClient(span *Span) string {
if span.OtherNamespace != "" && span.OtherNamespace != span.Service.UID.Namespace && span.PeerName != "" {
if !span.IsClientSpan() {
Expand Down
12 changes: 12 additions & 0 deletions pkg/export/otel/tracesgen/tracesgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func TraceAttributesSelector(span *request.Span, optionalAttrs map[attr.Name]str
request.HTTPUrlFull(url),
semconv.HTTPScheme(scheme),
request.ServerAddr(host),
request.PeerService(request.PeerServiceFromSpan(span)),
request.ServerPort(span.HostPort),
request.HTTPRequestBodySize(int(span.RequestBodyLength())),
request.HTTPResponseBodySize(span.ResponseBodyLength()),
Expand Down Expand Up @@ -388,11 +389,13 @@ func TraceAttributesSelector(span *request.Span, optionalAttrs map[attr.Name]str
semconv.RPCSystemGRPC,
semconv.RPCGRPCStatusCodeKey.Int(span.Status),
request.ServerAddr(request.HostAsServer(span)),
request.PeerService(request.PeerServiceFromSpan(span)),
request.ServerPort(span.HostPort),
}
case request.EventTypeSQLClient:
attrs = []attribute.KeyValue{
request.ServerAddr(request.HostAsServer(span)),
request.PeerService(request.PeerServiceFromSpan(span)),
request.ServerPort(span.HostPort),
span.DBSystemName(), // We can distinguish in the future for MySQL, Postgres etc
}
Expand All @@ -417,6 +420,9 @@ func TraceAttributesSelector(span *request.Span, optionalAttrs map[attr.Name]str
request.ServerPort(span.HostPort),
dbSystemRedis,
}
if span.Type == request.EventTypeRedisClient {
attrs = append(attrs, request.PeerService(request.PeerServiceFromSpan(span)))
}
operation := span.Method
if operation != "" {
attrs = append(attrs, request.DBOperationName(operation))
Expand All @@ -443,6 +449,11 @@ func TraceAttributesSelector(span *request.Span, optionalAttrs map[attr.Name]str
semconv.MessagingClientID(span.Statement),
operation,
}

if span.Type == request.EventTypeKafkaClient {
attrs = append(attrs, request.PeerService(request.PeerServiceFromSpan(span)))
}

if span.MessagingInfo != nil {
attrs = append(attrs, request.MessagingPartition(span.MessagingInfo.Partition))
if span.Method == request.MessagingProcess {
Expand All @@ -453,6 +464,7 @@ func TraceAttributesSelector(span *request.Span, optionalAttrs map[attr.Name]str
attrs = []attribute.KeyValue{
request.ServerAddr(request.HostAsServer(span)),
request.ServerPort(span.HostPort),
request.PeerService(request.PeerServiceFromSpan(span)),
dbSystemMongo,
}
operation := span.Method
Expand Down
Loading