Skip to content

Commit 1c2d049

Browse files
authored
Update Endpoint discovery model (#9277)
What Does This Do The names of the endpoint attributes that previously used hyphens (e.g., operation-name) have been updated to use underscores (operation_name) to align with the RFC. Only operation_name and resource_name are now required fields. The resource_name attribute has been added. Motivation The current implementation of endpoint discovery for API Security does not match the latest version of the RFC. Additional Notes https://docs.google.com/document/d/1txwuurIiSUWjYX7Xa0let7e49XKW2uhm1djgqjl_gL0/edit?tab=t.0
1 parent 15176df commit 1c2d049

File tree

6 files changed

+40
-14
lines changed

6 files changed

+40
-14
lines changed

dd-java-agent/instrumentation/spring-webmvc-3.1/src/main/java/datadog/trace/instrumentation/springweb/RequestMappingInfoIterator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private void fetchNext() {
6969
new Endpoint()
7070
.type(Endpoint.Type.REST)
7171
.operation(Endpoint.Operation.HTTP_REQUEST)
72+
.resource(method + " " + path)
7273
.path(path)
7374
.method(method)
7475
.requestBodyType(requestBody)

dd-java-agent/instrumentation/spring-webmvc-5.3/src/main/java/datadog/trace/instrumentation/springweb/RequestMappingInfoWithPathPatternsIterator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private void fetchNext() {
7373
new Endpoint()
7474
.type(Endpoint.Type.REST)
7575
.operation(Endpoint.Operation.HTTP_REQUEST)
76+
.resource(method + " " + path)
7677
.path(path)
7778
.method(method)
7879
.requestBodyType(requestBody)

internal-api/src/main/java/datadog/trace/api/telemetry/Endpoint.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Endpoint {
1616
private String method;
1717
private String path;
1818
private String operation;
19+
private String resource;
1920
private List<String> requestBodyType;
2021
private List<String> responseBodyType;
2122
private List<Integer> responseCode;
@@ -67,6 +68,15 @@ public Endpoint operation(final String operation) {
6768
return this;
6869
}
6970

71+
public String getResource() {
72+
return resource;
73+
}
74+
75+
public Endpoint resource(final String resource) {
76+
this.resource = resource;
77+
return this;
78+
}
79+
7080
public List<String> getRequestBodyType() {
7181
return requestBodyType;
7282
}

telemetry/src/main/java/datadog/telemetry/TelemetryRequestBody.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,18 +317,25 @@ public void beginEndpoints() throws IOException {
317317

318318
public void writeEndpoint(final Endpoint endpoint) throws IOException {
319319
bodyWriter.beginObject();
320-
bodyWriter.name("type").value(endpoint.getType());
321-
bodyWriter.name("method").value(endpoint.getMethod());
322-
bodyWriter.name("path").value(endpoint.getPath());
323-
bodyWriter.name("operation-name").value(endpoint.getOperation());
320+
if (endpoint.getType() != null) {
321+
bodyWriter.name("type").value(endpoint.getType());
322+
}
323+
if (endpoint.getMethod() != null) {
324+
bodyWriter.name("method").value(endpoint.getMethod());
325+
}
326+
if (endpoint.getPath() != null) {
327+
bodyWriter.name("path").value(endpoint.getPath());
328+
}
329+
bodyWriter.name("operation_name").value(endpoint.getOperation());
330+
bodyWriter.name("resource_name").value(endpoint.getResource());
324331
if (endpoint.getRequestBodyType() != null) {
325332
bodyWriter.name("request-body-type").jsonValue(endpoint.getRequestBodyType());
326333
}
327334
if (endpoint.getResponseBodyType() != null) {
328-
bodyWriter.name("response-body-type").jsonValue(endpoint.getResponseBodyType());
335+
bodyWriter.name("response_body_type").jsonValue(endpoint.getResponseBodyType());
329336
}
330337
if (endpoint.getResponseCode() != null) {
331-
bodyWriter.name("response-code").jsonValue(endpoint.getResponseCode());
338+
bodyWriter.name("response_code").jsonValue(endpoint.getResponseCode());
332339
}
333340
if (endpoint.getAuthentication() != null) {
334341
bodyWriter.name("authentication").jsonValue(endpoint.getAuthentication());

telemetry/src/test/groovy/datadog/telemetry/TelemetryServiceSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TelemetryServiceSpecification extends DDSpecification {
2626
def distribution = new DistributionSeries().namespace("tracers").metric("distro").points([1, 2, 3]).tags(["tag1", "tag2"]).common(false)
2727
def logMessage = new LogMessage().message("log-message").tags("tag1:tag2").level(LogMessageLevel.DEBUG).stackTrace("stack-trace").tracerTime(32423).count(1)
2828
def productChange = new ProductChange().productType(ProductChange.ProductType.APPSEC).enabled(true)
29-
def endpoint = new Endpoint().first(true).type('REST').method("GET").operation('http.request').path("/test")
29+
def endpoint = new Endpoint().first(true).type('REST').method("GET").operation('http.request').resource("GET /test").path("/test")
3030

3131
def 'happy path without data'() {
3232
setup:

telemetry/src/test/groovy/datadog/telemetry/TestTelemetryRouter.groovy

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,29 @@ class TestTelemetryRouter extends TelemetryRouter {
273273
def expected = []
274274
endpoints.each {
275275
final item = [
276-
'type' : it.type,
277-
'method' : it.method,
278-
'path' : it.path,
279-
'operation-name': it.operation
276+
'operation_name': it.operation,
277+
'resource_name' : it.method + ' ' + it.path,
280278
] as Map<String, Object>
279+
if (it.type) {
280+
item['type'] = it.type
281+
}
282+
if (it.method) {
283+
item['method'] = it.method
284+
}
285+
if (it.path) {
286+
item['path'] = it.path
287+
}
281288
if (it.requestBodyType) {
282-
item['request-body-type'] = it.requestBodyType
289+
item['request_body_type'] = it.requestBodyType
283290
}
284291
if (it.responseBodyType) {
285-
item['response-body-type'] = it.responseBodyType
292+
item['response_body_type'] = it.responseBodyType
286293
}
287294
if (it.authentication) {
288295
item['authentication'] = it.authentication
289296
}
290297
if (it.responseCode) {
291-
item['response-code'] = it.responseCode
298+
item['response_code'] = it.responseCode
292299
}
293300
if (it.metadata) {
294301
item['metadata'] = it.metadata

0 commit comments

Comments
 (0)