Skip to content

Commit 05c53ec

Browse files
committed
fix forbidden api
1 parent 135435a commit 05c53ec

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/AwsSdkClientDecorator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ public AgentSpan onRequest(final AgentSpan span, final Request request) {
188188
String serverlessFunction = System.getenv("AWS_LAMBDA_FUNCTION_NAME");
189189
// Set peer.service based on environment
190190
if (serverlessFunction != null && !serverlessFunction.isEmpty()) {
191-
String hostname = endpoint.replaceFirst("^https?://", "").split("/")[0];
191+
URI uri = request.getEndpoint();
192+
String hostname = uri.getHost();
193+
if (uri.getPort() != -1) {
194+
hostname = hostname + ":" + uri.getPort();
195+
}
192196
span.setTag(Tags.PEER_SERVICE, hostname);
193197
} else {
194198
if (bestPrecursor != null && SpanNaming.instance().namingSchema().peerService().supports()) {

dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsSdkClientDecorator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,13 @@ public AgentSpan onSdkRequest(
217217
// Set peer.service based on environment for serverless functions
218218
String serverlessFunction = System.getenv("AWS_LAMBDA_FUNCTION_NAME");
219219
if (serverlessFunction != null && !serverlessFunction.isEmpty()) {
220-
String endpoint = httpRequest.getUri().toString();
221-
// Extract just the hostname from the endpoint URL
222-
String hostname = endpoint.replaceFirst("^https?://", "").split("/")[0];
220+
URI uri = httpRequest.getUri();
221+
String hostname = uri.getHost();
222+
if (uri.getPort() != -1) {
223+
hostname = hostname + ":" + uri.getPort();
224+
}
223225
span.setTag(Tags.PEER_SERVICE, hostname);
226+
span.setTag(DDTags.PEER_SERVICE_SOURCE, "peer.service");
224227
}
225228

226229
return span;

0 commit comments

Comments
 (0)