Skip to content

Commit 2c20bf3

Browse files
committed
fix: http.route may be empty in apollo otel spans which leads to an incomplete transaction name
1 parent 437d181 commit 2c20bf3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/otel/attr-mapping/http.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ const attrMappings = {
1414
clientHost: {
1515
attrs: [constants.ATTR_SERVER_ADDRESS, constants.ATTR_NET_PEER_NAME],
1616
mapping() {
17-
return () => {}
17+
return () => { }
1818
}
1919
},
2020
clientPort: {
2121
attrs: [constants.ATTR_SERVER_PORT, constants.ATTR_NETWORK_PEER_PORT, constants.ATTR_NET_PEER_PORT],
2222
mapping() {
23-
return () => {}
23+
return () => { }
2424
}
2525
},
2626
clientUrl: {
2727
attrs: [constants.ATTR_FULL_URL, constants.ATTR_HTTP_URL],
2828
mapping() {
29-
return () => {}
29+
return () => { }
3030
}
3131
},
3232
grpcStatusCode: {
@@ -83,8 +83,16 @@ const attrMappings = {
8383
attrs: [constants.ATTR_HTTP_ROUTE],
8484
mapping({ segment, transaction }) {
8585
return (value) => {
86-
transaction.nameState.appendPath(value)
87-
segment.addAttribute('http.route', value)
86+
if (value.length > 0) {
87+
transaction.nameState.appendPath(value)
88+
segment.addAttribute('http.route', value)
89+
}
90+
// Some spans e.g. Apollo Server do not have the http.route
91+
// attribute and therefore will not have not a correct transaction
92+
// name, so this is a work around.
93+
else if (segment.attributes['http.target']) {
94+
transaction.nameState.appendPath(segment.attributes['http.target'])
95+
}
8896
}
8997
}
9098
},

0 commit comments

Comments
 (0)