Skip to content

Commit

Permalink
Clarify http(s) default port handling for service.target_name (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
z1c0 authored Nov 30, 2022
1 parent 2ca56f1 commit a0d2a6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
7 changes: 4 additions & 3 deletions specs/agents/tracing-spans-service-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ if (span.isExit) {

} else if (context.http?.url) { // http spans
service_target.name = getHostFromUrl(context.http.url);
//
// We always expect a valid port number here (80/443 default).
//
port = getPortFromUrl(context.http.url);
if (port > 0) {
service_target.name += ":" + port;
}
service_target.name += ":" + port;
}
}
} else {
Expand Down
38 changes: 12 additions & 26 deletions tests/agents/json-specs/service_resource_inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@
"type": "elasticsearch"
},
"http": {
"url": {
"host": "my-cluster.com",
"port": 9200
}
"url": "https://my-cluster.com:9200"
}
}
},
Expand All @@ -153,10 +150,7 @@
"body": "Text message"
},
"http": {
"url": {
"host": "my-broker.com",
"port": 8888
}
"url": "https://my-broker.com:8888"
}
}
},
Expand All @@ -173,10 +167,7 @@
"subtype": "http",
"context": {
"http": {
"url": {
"host": "my-cluster.com",
"port": 9200
}
"url": "http://my-cluster.com:9200"
}
}
},
Expand All @@ -185,7 +176,7 @@
"type": "http",
"name": "my-cluster.com:9200"
},
"failure_message": "If `context.http.url` exists, output should be `${context.http.url.host}:${context.http.url.port}"
"failure_message": "If `context.http.url` exists, output should be `${context.http.url}`"
},
{
"span": {
Expand All @@ -194,19 +185,16 @@
"subtype": "http",
"context": {
"http": {
"url": {
"host": "my-cluster.com",
"port": -1
}
"url": "https://my-cluster.com"
}
}
},
"expected_resource": "my-cluster.com",
"expected_resource": "my-cluster.com:443",
"expected_service_target": {
"type": "http",
"name": "my-cluster.com"
"name": "my-cluster.com:443"
},
"failure_message": "Negative `context.http.url.port` should be omitted from output"
"failure_message": "`context.http.url` without an explicit default HTTPS port, output should be reported as `${context.http.url}:443`"
},
{
"span": {
Expand All @@ -215,18 +203,16 @@
"subtype": "http",
"context": {
"http": {
"url": {
"host": "my-cluster.com"
}
"url": "http://my-cluster.com"
}
}
},
"expected_resource": "my-cluster.com",
"expected_resource": "my-cluster.com:80",
"expected_service_target": {
"type": "http",
"name": "my-cluster.com"
"name": "my-cluster.com:80"
},
"failure_message": "If `context.http.url.port` does not exist, output should be `${context.http.url.host}`"
"failure_message": "`context.http.url` without an explicit default HTTP port, output should be reported as `${context.http.url}:80`"
},
{
"span": {
Expand Down

0 comments on commit a0d2a6c

Please sign in to comment.