Skip to content

Commit 32ad019

Browse files
Merge branch 'master' into nikita-tkachenko/test-framework-tags-sync
2 parents d81799f + 991929d commit 32ad019

30 files changed

+459
-673
lines changed

dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/DebuggerContext.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.time.Duration;
88
import java.time.temporal.ChronoUnit;
99
import java.util.ArrayList;
10+
import java.util.Collections;
1011
import java.util.List;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
@@ -337,6 +338,18 @@ public static void evalContextAndCommit(
337338
}
338339
}
339340

341+
public static void codeOrigin(String probeId) {
342+
try {
343+
ProbeImplementation probe = probeResolver.resolve(probeId);
344+
if (probe != null) {
345+
probe.commit(
346+
CapturedContext.EMPTY_CONTEXT, CapturedContext.EMPTY_CONTEXT, Collections.emptyList());
347+
}
348+
} catch (Exception e) {
349+
LOGGER.debug("Error in codeOrigin: ", e);
350+
}
351+
}
352+
340353
/**
341354
* Commit snapshot based on entry/exit contexts and eventually caught exceptions for given probe
342355
* Ids This is for method probes

dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/ProbeId.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.bootstrap.debugger;
22

3+
import java.util.UUID;
4+
35
public class ProbeId {
46
private static final String ID_SEPARATOR = ":";
57

@@ -29,6 +31,10 @@ private ProbeId(String id, int version, String encoded) {
2931
this.encoded = encoded;
3032
}
3133

34+
public static ProbeId newId() {
35+
return new ProbeId(UUID.randomUUID().toString(), 0);
36+
}
37+
3238
public String getId() {
3339
return id;
3440
}
Lines changed: 54 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.datadog.debugger.agent;
22

3-
import com.datadog.debugger.probe.ExceptionProbe;
43
import com.datadog.debugger.probe.LogProbe;
54
import com.datadog.debugger.probe.MetricProbe;
65
import com.datadog.debugger.probe.ProbeDefinition;
@@ -12,6 +11,8 @@
1211
import java.util.Collection;
1312
import java.util.List;
1413
import java.util.Objects;
14+
import java.util.stream.Collectors;
15+
import java.util.stream.Stream;
1516

1617
/**
1718
* Stores debugger configuration for a service with: - Probe definitions - filters (allow/deny) -
@@ -63,46 +64,47 @@ public int hashCode() {
6364
@Json(name = "id")
6465
private final String service;
6566

66-
private final Collection<MetricProbe> metricProbes;
67-
private final Collection<LogProbe> logProbes;
68-
private final Collection<SpanProbe> spanProbes;
69-
private final Collection<TriggerProbe> triggerProbes;
70-
private final Collection<SpanDecorationProbe> spanDecorationProbes;
67+
private transient List<ProbeDefinition> probes = new ArrayList<>();
68+
private Collection<MetricProbe> metricProbes = new ArrayList<>();
69+
private Collection<LogProbe> logProbes = new ArrayList<>();
70+
private Collection<SpanProbe> spanProbes = new ArrayList<>();
71+
private Collection<TriggerProbe> triggerProbes = new ArrayList<>();
72+
private Collection<SpanDecorationProbe> spanDecorationProbes = new ArrayList<>();
7173
private final FilterList allowList;
7274
private final FilterList denyList;
7375
private final LogProbe.Sampling sampling;
7476

75-
public Configuration(String service, Collection<LogProbe> logProbes) {
76-
this(service, null, logProbes, null);
77+
public Configuration(String serviceName, List<? extends ProbeDefinition> probes) {
78+
this(serviceName, probes, null, null, null);
7779
}
7880

7981
public Configuration(
8082
String serviceName,
81-
Collection<MetricProbe> metricProbes,
82-
Collection<LogProbe> logProbes,
83-
Collection<SpanProbe> spanProbes) {
84-
this(serviceName, metricProbes, logProbes, spanProbes, null, null, null, null, null);
85-
}
86-
87-
public Configuration(
88-
String serviceName,
89-
Collection<MetricProbe> metricProbes,
90-
Collection<LogProbe> logProbes,
91-
Collection<SpanProbe> spanProbes,
92-
Collection<TriggerProbe> triggerProbes,
93-
Collection<SpanDecorationProbe> spanDecorationProbes,
83+
List<? extends ProbeDefinition> probes,
9484
FilterList allowList,
9585
FilterList denyList,
9686
LogProbe.Sampling sampling) {
9787
this.service = serviceName;
98-
this.metricProbes = metricProbes;
99-
this.logProbes = logProbes;
100-
this.spanProbes = spanProbes;
101-
this.triggerProbes = triggerProbes;
102-
this.spanDecorationProbes = spanDecorationProbes;
10388
this.allowList = allowList;
10489
this.denyList = denyList;
10590
this.sampling = sampling;
91+
probes.forEach(this::add);
92+
}
93+
94+
private void add(ProbeDefinition p) {
95+
if (p instanceof LogProbe) {
96+
logProbes.add((LogProbe) p);
97+
} else if (p instanceof MetricProbe) {
98+
metricProbes.add((MetricProbe) p);
99+
} else if (p instanceof SpanProbe) {
100+
spanProbes.add((SpanProbe) p);
101+
} else if (p instanceof SpanDecorationProbe) {
102+
spanDecorationProbes.add((SpanDecorationProbe) p);
103+
} else if (p instanceof TriggerProbe) {
104+
triggerProbes.add((TriggerProbe) p);
105+
} else {
106+
probes.add(p);
107+
}
106108
}
107109

108110
public String getService() {
@@ -141,24 +143,12 @@ public LogProbe.Sampling getSampling() {
141143
return sampling;
142144
}
143145

144-
public Collection<ProbeDefinition> getDefinitions() {
145-
Collection<ProbeDefinition> result = new ArrayList<>();
146-
if (triggerProbes != null) {
147-
result.addAll(triggerProbes);
148-
}
149-
if (metricProbes != null) {
150-
result.addAll(metricProbes);
151-
}
152-
if (logProbes != null) {
153-
result.addAll(logProbes);
154-
}
155-
if (spanProbes != null) {
156-
result.addAll(spanProbes);
157-
}
158-
if (spanDecorationProbes != null) {
159-
result.addAll(spanDecorationProbes);
160-
}
161-
return result;
146+
public List<ProbeDefinition> getDefinitions() {
147+
return Stream.of(
148+
triggerProbes, metricProbes, logProbes, spanProbes, spanDecorationProbes, probes)
149+
.filter(Objects::nonNull)
150+
.flatMap(Collection::stream)
151+
.collect(Collectors.toList());
162152
}
163153

164154
@Generated
@@ -167,10 +157,8 @@ public String toString() {
167157
return "DebuggerConfiguration{"
168158
+ "service="
169159
+ service
170-
+ ", metricProbes="
171-
+ metricProbes
172-
+ ", logProbes="
173-
+ logProbes
160+
+ ", probes="
161+
+ getDefinitions()
174162
+ ", allowList="
175163
+ allowList
176164
+ ", denyList="
@@ -183,12 +171,15 @@ public String toString() {
183171
@Generated
184172
@Override
185173
public boolean equals(Object o) {
186-
if (this == o) return true;
187-
if (o == null || getClass() != o.getClass()) return false;
174+
if (this == o) {
175+
return true;
176+
}
177+
if (o == null || getClass() != o.getClass()) {
178+
return false;
179+
}
188180
Configuration that = (Configuration) o;
189181
return Objects.equals(service, that.service)
190-
&& Objects.equals(metricProbes, that.metricProbes)
191-
&& Objects.equals(logProbes, that.logProbes)
182+
&& Objects.equals(probes, that.probes)
192183
&& Objects.equals(allowList, that.allowList)
193184
&& Objects.equals(denyList, that.denyList)
194185
&& Objects.equals(sampling, that.sampling);
@@ -197,7 +188,7 @@ public boolean equals(Object o) {
197188
@Generated
198189
@Override
199190
public int hashCode() {
200-
return Objects.hash(service, metricProbes, logProbes, allowList, denyList, sampling);
191+
return Objects.hash(service, probes, allowList, denyList, sampling);
201192
}
202193

203194
public static Configuration.Builder builder() {
@@ -206,13 +197,13 @@ public static Configuration.Builder builder() {
206197

207198
public static class Builder {
208199
private String service = null;
209-
private List<MetricProbe> metricProbes = null;
210-
private List<LogProbe> logProbes = null;
211-
private List<SpanProbe> spanProbes = null;
212-
private List<TriggerProbe> triggerProbes = null;
213-
private List<SpanDecorationProbe> spanDecorationProbes = null;
200+
201+
private final List<ProbeDefinition> probes = new ArrayList<>();
202+
214203
private FilterList allowList = null;
204+
215205
private FilterList denyList = null;
206+
216207
private LogProbe.Sampling sampling = null;
217208

218209
public Configuration.Builder setService(String service) {
@@ -224,53 +215,14 @@ public Configuration.Builder add(Collection<? extends ProbeDefinition> definitio
224215
if (definitions == null) {
225216
return this;
226217
}
227-
for (ProbeDefinition definition : definitions) {
228-
if (definition instanceof MetricProbe) add((MetricProbe) definition);
229-
if (definition instanceof TriggerProbe) add((TriggerProbe) definition);
230-
if (definition instanceof LogProbe) add((LogProbe) definition);
231-
if (definition instanceof SpanProbe) add((SpanProbe) definition);
232-
if (definition instanceof SpanDecorationProbe) add((SpanDecorationProbe) definition);
233-
}
218+
probes.addAll(definitions);
234219
return this;
235220
}
236221

237-
public Configuration.Builder add(MetricProbe probe) {
238-
if (metricProbes == null) {
239-
metricProbes = new ArrayList<>();
222+
public Configuration.Builder add(ProbeDefinition... probes) {
223+
for (ProbeDefinition probe : probes) {
224+
this.probes.add(probe);
240225
}
241-
metricProbes.add(probe);
242-
return this;
243-
}
244-
245-
public Configuration.Builder add(LogProbe probe) {
246-
if (logProbes == null) {
247-
logProbes = new ArrayList<>();
248-
}
249-
logProbes.add(probe);
250-
return this;
251-
}
252-
253-
public Configuration.Builder add(SpanProbe probe) {
254-
if (spanProbes == null) {
255-
spanProbes = new ArrayList<>();
256-
}
257-
spanProbes.add(probe);
258-
return this;
259-
}
260-
261-
public Configuration.Builder add(TriggerProbe probe) {
262-
if (triggerProbes == null) {
263-
triggerProbes = new ArrayList<>();
264-
}
265-
triggerProbes.add(probe);
266-
return this;
267-
}
268-
269-
public Configuration.Builder add(SpanDecorationProbe probe) {
270-
if (spanDecorationProbes == null) {
271-
spanDecorationProbes = new ArrayList<>();
272-
}
273-
spanDecorationProbes.add(probe);
274226
return this;
275227
}
276228

@@ -281,66 +233,6 @@ public Configuration.Builder add(LogProbe.Sampling newSampling) {
281233
return this;
282234
}
283235

284-
public Configuration.Builder addMetricProbes(Collection<MetricProbe> probes) {
285-
if (probes == null) {
286-
return this;
287-
}
288-
for (MetricProbe probe : probes) {
289-
add(probe);
290-
}
291-
return this;
292-
}
293-
294-
public Configuration.Builder addLogProbes(Collection<LogProbe> probes) {
295-
if (probes == null) {
296-
return this;
297-
}
298-
for (LogProbe probe : probes) {
299-
add(probe);
300-
}
301-
return this;
302-
}
303-
304-
public Builder addExceptionProbes(Collection<ExceptionProbe> probes) {
305-
if (probes == null) {
306-
return this;
307-
}
308-
for (ExceptionProbe probe : probes) {
309-
add(probe);
310-
}
311-
return this;
312-
}
313-
314-
public Configuration.Builder addSpanProbes(Collection<SpanProbe> probes) {
315-
if (probes == null) {
316-
return this;
317-
}
318-
for (SpanProbe probe : probes) {
319-
add(probe);
320-
}
321-
return this;
322-
}
323-
324-
public Configuration.Builder addTriggerProbes(Collection<TriggerProbe> probes) {
325-
if (probes == null) {
326-
return this;
327-
}
328-
for (TriggerProbe probe : probes) {
329-
add(probe);
330-
}
331-
return this;
332-
}
333-
334-
public Configuration.Builder addSpanDecorationProbes(Collection<SpanDecorationProbe> probes) {
335-
if (probes == null) {
336-
return this;
337-
}
338-
for (SpanDecorationProbe probe : probes) {
339-
add(probe);
340-
}
341-
return this;
342-
}
343-
344236
public Configuration.Builder addAllowList(FilterList newAllowList) {
345237
if (newAllowList == null) {
346238
return this;
@@ -370,32 +262,8 @@ public Configuration.Builder setSampling(LogProbe.Sampling sampling) {
370262
return this;
371263
}
372264

373-
public Configuration.Builder add(Configuration other) {
374-
if (other.service != null) {
375-
this.service = other.service;
376-
}
377-
addMetricProbes(other.getMetricProbes());
378-
addLogProbes(other.getLogProbes());
379-
addSpanProbes(other.getSpanProbes());
380-
addTriggerProbes(other.getTriggerProbes());
381-
addSpanDecorationProbes(other.getSpanDecorationProbes());
382-
addAllowList(other.getAllowList());
383-
addDenyList(other.getDenyList());
384-
add(other.getSampling());
385-
return this;
386-
}
387-
388265
public Configuration build() {
389-
return new Configuration(
390-
service,
391-
metricProbes,
392-
logProbes,
393-
spanProbes,
394-
triggerProbes,
395-
spanDecorationProbes,
396-
allowList,
397-
denyList,
398-
sampling);
266+
return new Configuration(service, probes, allowList, denyList, sampling);
399267
}
400268
}
401269
}

0 commit comments

Comments
 (0)