Skip to content

Commit 46a0c27

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add support for span id remapper in logs pipelines processors (#2724)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent fb72561 commit 46a0c27

File tree

9 files changed

+530
-9
lines changed

9 files changed

+530
-9
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2025-02-21 08:00:41.502787",
8-
"spec_repo_commit": "8f2d39c3"
7+
"regenerated": "2025-02-21 18:16:25.164341",
8+
"spec_repo_commit": "5de91bd6"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2025-02-21 08:00:41.517713",
13-
"spec_repo_commit": "8f2d39c3"
12+
"regenerated": "2025-02-21 18:16:25.179171",
13+
"spec_repo_commit": "5de91bd6"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6049,6 +6049,7 @@ components:
60496049
- $ref: '#/components/schemas/LogsLookupProcessor'
60506050
- $ref: '#/components/schemas/ReferenceTableLogsLookupProcessor'
60516051
- $ref: '#/components/schemas/LogsTraceRemapper'
6052+
- $ref: '#/components/schemas/LogsSpanRemapper'
60526053
LogsQueryCompute:
60536054
description: Define computation for a log query.
60546055
properties:
@@ -6160,6 +6161,43 @@ components:
61606161
x-enum-varnames:
61616162
- TIME_ASCENDING
61626163
- TIME_DESCENDING
6164+
LogsSpanRemapper:
6165+
description: "There are two ways to define correlation between application spans
6166+
and logs:\n\n 1. Follow the documentation on [how to inject a span ID in
6167+
the application logs](https://docs.datadoghq.com/tracing/connect_logs_and_traces).\n
6168+
\ Log integrations automatically handle all remaining setup steps by default.\n\n
6169+
\ 2. Use the span remapper processor to define a log attribute as its associated
6170+
span ID."
6171+
properties:
6172+
is_enabled:
6173+
default: false
6174+
description: Whether or not the processor is enabled.
6175+
type: boolean
6176+
name:
6177+
description: Name of the processor.
6178+
type: string
6179+
sources:
6180+
default:
6181+
- dd.span_id
6182+
description: Array of source attributes.
6183+
items:
6184+
description: Attribute to extract the span ID from.
6185+
type: string
6186+
type: array
6187+
type:
6188+
$ref: '#/components/schemas/LogsSpanRemapperType'
6189+
required:
6190+
- type
6191+
type: object
6192+
LogsSpanRemapperType:
6193+
default: span-id-remapper
6194+
description: Type of logs span remapper.
6195+
enum:
6196+
- span-id-remapper
6197+
example: span-id-remapper
6198+
type: string
6199+
x-enum-varnames:
6200+
- SPAN_ID_REMAPPER
61636201
LogsStatusRemapper:
61646202
description: "Use this Processor if you want to assign some attributes as the
61656203
official status.\n\nEach incoming status value is mapped as follows.\n\n -
@@ -6275,7 +6313,7 @@ components:
62756313
- dd.trace_id
62766314
description: Array of source attributes.
62776315
items:
6278-
description: Attribute to extract the Trace ID from.
6316+
description: Attribute to extract the trace ID from.
62796317
type: string
62806318
type: array
62816319
type:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Create a pipeline with Span Id Remapper returns "OK" response
2+
3+
import com.datadog.api.client.ApiClient;
4+
import com.datadog.api.client.ApiException;
5+
import com.datadog.api.client.v1.api.LogsPipelinesApi;
6+
import com.datadog.api.client.v1.model.LogsFilter;
7+
import com.datadog.api.client.v1.model.LogsPipeline;
8+
import com.datadog.api.client.v1.model.LogsProcessor;
9+
import com.datadog.api.client.v1.model.LogsSpanRemapper;
10+
import com.datadog.api.client.v1.model.LogsSpanRemapperType;
11+
import java.util.Collections;
12+
13+
public class Example {
14+
public static void main(String[] args) {
15+
ApiClient defaultClient = ApiClient.getDefaultApiClient();
16+
LogsPipelinesApi apiInstance = new LogsPipelinesApi(defaultClient);
17+
18+
LogsPipeline body =
19+
new LogsPipeline()
20+
.filter(new LogsFilter().query("source:python"))
21+
.name("testPipeline")
22+
.processors(
23+
Collections.singletonList(
24+
new LogsProcessor(
25+
new LogsSpanRemapper()
26+
.type(LogsSpanRemapperType.SPAN_ID_REMAPPER)
27+
.isEnabled(true)
28+
.name("test_filter")
29+
.sources(Collections.singletonList("dd.span_id")))));
30+
31+
try {
32+
LogsPipeline result = apiInstance.createLogsPipeline(body);
33+
System.out.println(result);
34+
} catch (ApiException e) {
35+
System.err.println("Exception when calling LogsPipelinesApi#createLogsPipeline");
36+
System.err.println("Status code: " + e.getCode());
37+
System.err.println("Reason: " + e.getResponseBody());
38+
System.err.println("Response headers: " + e.getResponseHeaders());
39+
e.printStackTrace();
40+
}
41+
}
42+
}

src/main/java/com/datadog/api/client/v1/model/LogsProcessor.java

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,50 @@ public LogsProcessor deserialize(JsonParser jp, DeserializationContext ctxt)
788788
log.log(Level.FINER, "Input data does not match schema 'LogsTraceRemapper'", e);
789789
}
790790

791+
// deserialize LogsSpanRemapper
792+
try {
793+
boolean attemptParsing = true;
794+
// ensure that we respect type coercion as set on the client ObjectMapper
795+
if (LogsSpanRemapper.class.equals(Integer.class)
796+
|| LogsSpanRemapper.class.equals(Long.class)
797+
|| LogsSpanRemapper.class.equals(Float.class)
798+
|| LogsSpanRemapper.class.equals(Double.class)
799+
|| LogsSpanRemapper.class.equals(Boolean.class)
800+
|| LogsSpanRemapper.class.equals(String.class)) {
801+
attemptParsing = typeCoercion;
802+
if (!attemptParsing) {
803+
attemptParsing |=
804+
((LogsSpanRemapper.class.equals(Integer.class)
805+
|| LogsSpanRemapper.class.equals(Long.class))
806+
&& token == JsonToken.VALUE_NUMBER_INT);
807+
attemptParsing |=
808+
((LogsSpanRemapper.class.equals(Float.class)
809+
|| LogsSpanRemapper.class.equals(Double.class))
810+
&& (token == JsonToken.VALUE_NUMBER_FLOAT
811+
|| token == JsonToken.VALUE_NUMBER_INT));
812+
attemptParsing |=
813+
(LogsSpanRemapper.class.equals(Boolean.class)
814+
&& (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
815+
attemptParsing |=
816+
(LogsSpanRemapper.class.equals(String.class) && token == JsonToken.VALUE_STRING);
817+
}
818+
}
819+
if (attemptParsing) {
820+
tmp = tree.traverse(jp.getCodec()).readValueAs(LogsSpanRemapper.class);
821+
// TODO: there is no validation against JSON schema constraints
822+
// (min, max, enum, pattern...), this does not perform a strict JSON
823+
// validation, which means the 'match' count may be higher than it should be.
824+
if (!((LogsSpanRemapper) tmp).unparsed) {
825+
deserialized = tmp;
826+
match++;
827+
}
828+
log.log(Level.FINER, "Input data matches schema 'LogsSpanRemapper'");
829+
}
830+
} catch (Exception e) {
831+
// deserialization failed, continue
832+
log.log(Level.FINER, "Input data does not match schema 'LogsSpanRemapper'", e);
833+
}
834+
791835
LogsProcessor ret = new LogsProcessor();
792836
if (match == 1) {
793837
ret.setActualInstance(deserialized);
@@ -896,6 +940,11 @@ public LogsProcessor(LogsTraceRemapper o) {
896940
setActualInstance(o);
897941
}
898942

943+
public LogsProcessor(LogsSpanRemapper o) {
944+
super("oneOf", Boolean.FALSE);
945+
setActualInstance(o);
946+
}
947+
899948
static {
900949
schemas.put("LogsGrokParser", new GenericType<LogsGrokParser>() {});
901950
schemas.put("LogsDateRemapper", new GenericType<LogsDateRemapper>() {});
@@ -915,6 +964,7 @@ public LogsProcessor(LogsTraceRemapper o) {
915964
"ReferenceTableLogsLookupProcessor",
916965
new GenericType<ReferenceTableLogsLookupProcessor>() {});
917966
schemas.put("LogsTraceRemapper", new GenericType<LogsTraceRemapper>() {});
967+
schemas.put("LogsSpanRemapper", new GenericType<LogsSpanRemapper>() {});
918968
JSON.registerDescendants(LogsProcessor.class, Collections.unmodifiableMap(schemas));
919969
}
920970

@@ -929,7 +979,7 @@ public Map<String, GenericType> getSchemas() {
929979
* LogsServiceRemapper, LogsMessageRemapper, LogsAttributeRemapper, LogsURLParser,
930980
* LogsUserAgentParser, LogsCategoryProcessor, LogsArithmeticProcessor,
931981
* LogsStringBuilderProcessor, LogsPipelineProcessor, LogsGeoIPParser, LogsLookupProcessor,
932-
* ReferenceTableLogsLookupProcessor, LogsTraceRemapper
982+
* ReferenceTableLogsLookupProcessor, LogsTraceRemapper, LogsSpanRemapper
933983
*
934984
* <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
935985
* composed schema (allOf, anyOf, oneOf).
@@ -1001,6 +1051,10 @@ public void setActualInstance(Object instance) {
10011051
super.setActualInstance(instance);
10021052
return;
10031053
}
1054+
if (JSON.isInstanceOf(LogsSpanRemapper.class, instance, new HashSet<Class<?>>())) {
1055+
super.setActualInstance(instance);
1056+
return;
1057+
}
10041058

10051059
if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) {
10061060
super.setActualInstance(instance);
@@ -1011,21 +1065,22 @@ public void setActualInstance(Object instance) {
10111065
+ " LogsServiceRemapper, LogsMessageRemapper, LogsAttributeRemapper, LogsURLParser,"
10121066
+ " LogsUserAgentParser, LogsCategoryProcessor, LogsArithmeticProcessor,"
10131067
+ " LogsStringBuilderProcessor, LogsPipelineProcessor, LogsGeoIPParser,"
1014-
+ " LogsLookupProcessor, ReferenceTableLogsLookupProcessor, LogsTraceRemapper");
1068+
+ " LogsLookupProcessor, ReferenceTableLogsLookupProcessor, LogsTraceRemapper,"
1069+
+ " LogsSpanRemapper");
10151070
}
10161071

10171072
/**
10181073
* Get the actual instance, which can be the following: LogsGrokParser, LogsDateRemapper,
10191074
* LogsStatusRemapper, LogsServiceRemapper, LogsMessageRemapper, LogsAttributeRemapper,
10201075
* LogsURLParser, LogsUserAgentParser, LogsCategoryProcessor, LogsArithmeticProcessor,
10211076
* LogsStringBuilderProcessor, LogsPipelineProcessor, LogsGeoIPParser, LogsLookupProcessor,
1022-
* ReferenceTableLogsLookupProcessor, LogsTraceRemapper
1077+
* ReferenceTableLogsLookupProcessor, LogsTraceRemapper, LogsSpanRemapper
10231078
*
10241079
* @return The actual instance (LogsGrokParser, LogsDateRemapper, LogsStatusRemapper,
10251080
* LogsServiceRemapper, LogsMessageRemapper, LogsAttributeRemapper, LogsURLParser,
10261081
* LogsUserAgentParser, LogsCategoryProcessor, LogsArithmeticProcessor,
10271082
* LogsStringBuilderProcessor, LogsPipelineProcessor, LogsGeoIPParser, LogsLookupProcessor,
1028-
* ReferenceTableLogsLookupProcessor, LogsTraceRemapper)
1083+
* ReferenceTableLogsLookupProcessor, LogsTraceRemapper, LogsSpanRemapper)
10291084
*/
10301085
@Override
10311086
public Object getActualInstance() {
@@ -1208,4 +1263,15 @@ public ReferenceTableLogsLookupProcessor getReferenceTableLogsLookupProcessor()
12081263
public LogsTraceRemapper getLogsTraceRemapper() throws ClassCastException {
12091264
return (LogsTraceRemapper) super.getActualInstance();
12101265
}
1266+
1267+
/**
1268+
* Get the actual instance of `LogsSpanRemapper`. If the actual instance is not
1269+
* `LogsSpanRemapper`, the ClassCastException will be thrown.
1270+
*
1271+
* @return The actual instance of `LogsSpanRemapper`
1272+
* @throws ClassCastException if the instance is not `LogsSpanRemapper`
1273+
*/
1274+
public LogsSpanRemapper getLogsSpanRemapper() throws ClassCastException {
1275+
return (LogsSpanRemapper) super.getActualInstance();
1276+
}
12111277
}

0 commit comments

Comments
 (0)