Skip to content

Commit 218c106

Browse files
committed
refactor constants and fix tests
1 parent 42c62fe commit 218c106

8 files changed

Lines changed: 41 additions & 36 deletions

File tree

dd-java-agent/instrumentation/aws-java-s3-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/s3/S3Interceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.instrumentation.aws.v2.s3;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.S3_ETAG;
4+
35
import datadog.trace.api.Config;
46
import datadog.trace.bootstrap.InstanceStore;
57
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -52,6 +54,6 @@ public void afterExecution(
5254
// Store eTag as tag, then calculate hash + add span pointers in SpanPointersProcessor.
5355
// Bucket and key are already stored as tags in AwsSdkClientDecorator, so need to make redundant
5456
// tags.
55-
span.setTag("s3.eTag", eTag);
57+
span.setTag(S3_ETAG, eTag);
5658
}
5759
}

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/SpanPointersProcessor.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package datadog.trace.core.tagprocessor;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.AWS_BUCKET_NAME;
4+
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.AWS_OBJECT_KEY;
5+
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.S3_ETAG;
6+
37
import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
48
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
5-
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
69
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
710
import datadog.trace.bootstrap.instrumentation.api.SpanLink;
811
import datadog.trace.core.DDSpanContext;
@@ -17,26 +20,25 @@
1720
import org.slf4j.LoggerFactory;
1821

1922
public class SpanPointersProcessor implements TagsPostProcessor {
20-
private static final Logger log = LoggerFactory.getLogger(SpanPointersProcessor.class);
23+
private static final Logger LOG = LoggerFactory.getLogger(SpanPointersProcessor.class);
2124

2225
// The pointer direction will always be down. The serverless agent handles cases where the
2326
// direction is up.
24-
private static final String DOWN_DIRECTION = "d";
25-
private static final String S3_PTR_KIND = "aws.s3.object";
26-
private static final String LINK_KIND = "span-pointer";
27-
private static final String ETAG_KEY = "s3.eTag";
27+
static final String DOWN_DIRECTION = "d";
28+
static final String S3_PTR_KIND = "aws.s3.object";
29+
static final String LINK_KIND = "span-pointer";
2830

2931
@Override
3032
public Map<String, Object> processTags(
3133
Map<String, Object> unsafeTags, DDSpanContext spanContext, List<AgentSpanLink> spanLinks) {
32-
String eTag = asString(unsafeTags.remove(ETAG_KEY));
34+
String eTag = asString(unsafeTags.remove(S3_ETAG));
3335
if (eTag == null) {
3436
return unsafeTags;
3537
}
36-
String bucket = asString(unsafeTags.get(InstrumentationTags.AWS_BUCKET_NAME));
37-
String key = asString(unsafeTags.get(InstrumentationTags.AWS_OBJECT_KEY));
38+
String bucket = asString(unsafeTags.get(AWS_BUCKET_NAME));
39+
String key = asString(unsafeTags.get(AWS_OBJECT_KEY));
3840
if (bucket == null || key == null) {
39-
log.debug("Unable to calculate span pointer hash because could not find bucket or key tags.");
41+
LOG.debug("Unable to calculate span pointer hash because could not find bucket or key tags.");
4042
return unsafeTags;
4143
}
4244

@@ -59,7 +61,7 @@ public Map<String, Object> processTags(
5961
AgentSpanLink link = SpanLink.from(zeroContext, AgentSpanLink.DEFAULT_FLAGS, "", attributes);
6062
spanLinks.add(link);
6163
} catch (Exception e) {
62-
log.debug("Failed to add span pointer: {}", e.getMessage());
64+
LOG.debug("Failed to add span pointer: {}", e.getMessage());
6365
}
6466

6567
return unsafeTags;

dd-trace-core/src/test/groovy/datadog/trace/core/tagprocessor/BaseServiceAdderTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class BaseServiceAdderTest extends DDSpecification {
1212
def spanContext = Mock(DDSpanContext)
1313

1414
when:
15-
def enrichedTags = calculator.processTags([:], spanContext)
15+
def enrichedTags = calculator.processTags([:], spanContext, [])
1616

1717
then:
1818
1 * spanContext.getServiceName() >> serviceName

dd-trace-core/src/test/groovy/datadog/trace/core/tagprocessor/PayloadTagsProcessorTest.groovy

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
8282
]
8383

8484
expect:
85-
ptp.processTags(spanTags, null) == ["foo": "bar", "tag1": 1]
85+
ptp.processTags(spanTags, null, []) == ["foo": "bar", "tag1": 1]
8686
}
8787

8888
static PathAndValue pv(PathCursor path, Object value) {
@@ -107,7 +107,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
107107
]
108108

109109
expect:
110-
ptp.processTags(spanTags, null) == ["foo": "bar", "tag1": 1, "payload.tag1": 0]
110+
ptp.processTags(spanTags, null, []) == ["foo": "bar", "tag1": 1, "payload.tag1": 0]
111111
}
112112

113113
def "expand preserving tag types"() {
@@ -124,7 +124,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
124124
])
125125

126126
expect:
127-
ptp.processTags(st, null) == [
127+
ptp.processTags(st, null, []) == [
128128
"payload.tag1": 11,
129129
"payload.tag2.Value": 2342l,
130130
"payload.tag3.0": 3.14d,
@@ -142,7 +142,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
142142
def st = spanTags("payload", [pv(pc().push("tag7"), unknownValue),])
143143

144144
expect:
145-
ptp.processTags(st, null) == [
145+
ptp.processTags(st, null, []) == [
146146
"payload.tag7": unknownValue.toString(),
147147
]
148148
}
@@ -159,7 +159,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
159159
])
160160

161161
expect:
162-
ptp.processTags(st, null) == [
162+
ptp.processTags(st, null, []) == [
163163
"p.j3.0": "1",
164164
"p.j3.1": 2,
165165
"p.j3.2": 3.14d,
@@ -204,7 +204,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
204204
def st = spanTags("dd", [pv(pc(), json),])
205205

206206
expect:
207-
ptp.processTags(st, null) == [
207+
ptp.processTags(st, null, []) == [
208208
'dd.a' : 33,
209209
'dd.Message.id' : 45,
210210
'dd.Message.user.a' : 1.15d,
@@ -220,7 +220,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
220220
def st = spanTags("p", [pv(pc().push("key"), invalidJson),])
221221

222222
expect:
223-
ptp.processTags(st, null) == [
223+
ptp.processTags(st, null, []) == [
224224
"p.key": invalidJson,
225225
]
226226

@@ -246,7 +246,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
246246
])
247247

248248
expect:
249-
ptp.processTags(st, null) == [
249+
ptp.processTags(st, null, []) == [
250250
"p.j1.foo": "bar",
251251
"p.j2.0": 1,
252252
"p.j2.1": true,
@@ -261,7 +261,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
261261
def st = spanTags("p", [pv(pc().push("v"), new ByteArrayInputStream("""{ "inner": $innerJson}""".bytes))])
262262

263263
then:
264-
ptp.processTags(st, null) == [
264+
ptp.processTags(st, null, []) == [
265265
"p.v.inner.a": 1.15d,
266266
"p.v.inner.password": "my-secret-password",
267267
]
@@ -283,7 +283,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
283283
def st = spanTags("p", [pv(pc().push("key"), new ByteArrayInputStream(invalidJson.bytes)),])
284284

285285
expect:
286-
ptp.processTags(st, null) == [
286+
ptp.processTags(st, null, []) == [
287287
"p.key": "<binary>",
288288
]
289289

@@ -303,7 +303,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
303303
])
304304

305305
expect:
306-
ptp.processTags(st, null) == [
306+
ptp.processTags(st, null, []) == [
307307
"p.j3.0": "redacted",
308308
"p.j3.1": 2,
309309
"p.j3.2": 3.14d,
@@ -326,7 +326,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
326326
])
327327

328328
expect:
329-
ptp.processTags(st, null) == [
329+
ptp.processTags(st, null, []) == [
330330
"p.j3.0": "redacted",
331331
"p.j3.1": 2,
332332
"p.j3.2": 3.14d,
@@ -345,7 +345,7 @@ class PayloadTagsProcessorTest extends DDSpecification {
345345
])
346346

347347
expect:
348-
ptp.processTags(st, null) == [
348+
ptp.processTags(st, null, []) == [
349349
"p.j3.0": "redacted",
350350
"p.j3.1": 2,
351351
"p.j3.2": 3.14d,

dd-trace-core/src/test/groovy/datadog/trace/core/tagprocessor/PeerServiceCalculatorTest.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PeerServiceCalculatorTest extends DDSpecification {
1313
setup:
1414
def calculator = new PeerServiceCalculator(new NamingSchemaV0().peerService(), Collections.emptyMap())
1515
when:
16-
def enrichedTags = calculator.processTags(tags, null)
16+
def enrichedTags = calculator.processTags(tags, null, [])
1717
then:
1818
// tags are not modified
1919
assert enrichedTags == tags
@@ -33,7 +33,7 @@ class PeerServiceCalculatorTest extends DDSpecification {
3333
def calculator = new PeerServiceCalculator(new NamingSchemaV1().peerService(), Collections.emptyMap())
3434
when:
3535
tags.put(Tags.SPAN_KIND, Tags.SPAN_KIND_CLIENT)
36-
def calculated = calculator.processTags(tags, null)
36+
def calculated = calculator.processTags(tags, null, [])
3737

3838
then:
3939
calculated.get(DDTags.PEER_SERVICE_SOURCE) == provenance
@@ -56,7 +56,7 @@ class PeerServiceCalculatorTest extends DDSpecification {
5656
injectSysConfig(TracerConfig.TRACE_PEER_SERVICE_DEFAULTS_ENABLED, "true")
5757
def calculator = new PeerServiceCalculator(new NamingSchemaV0().peerService(), Collections.emptyMap())
5858
when:
59-
def calculated = calculator.processTags(["span.kind": "client", "peer.hostname": "test"], null)
59+
def calculated = calculator.processTags(["span.kind": "client", "peer.hostname": "test"], null, [])
6060
then:
6161
assert calculated.get(Tags.PEER_SERVICE) == "test"
6262
}
@@ -70,7 +70,7 @@ class PeerServiceCalculatorTest extends DDSpecification {
7070
def tags = ["span.kind": kind, "peer.hostname": "test"]
7171

7272
then:
73-
assert calculator.processTags(tags, null).containsKey(Tags.PEER_SERVICE) == calculate
73+
assert calculator.processTags(tags, null, []).containsKey(Tags.PEER_SERVICE) == calculate
7474

7575
where:
7676
kind | calculate
@@ -87,7 +87,7 @@ class PeerServiceCalculatorTest extends DDSpecification {
8787
def calculator = new PeerServiceCalculator(new NamingSchemaV0().peerService(), Config.get().getPeerServiceMapping())
8888

8989
when:
90-
def calculated = calculator.processTags(tags, null)
90+
def calculated = calculator.processTags(tags, null, [])
9191

9292
then:
9393
assert calculated.get(Tags.PEER_SERVICE) == expected
@@ -108,7 +108,7 @@ class PeerServiceCalculatorTest extends DDSpecification {
108108
def calculator = new PeerServiceCalculator(new NamingSchemaV0().peerService(), Config.get().getPeerServiceComponentOverrides())
109109

110110
when:
111-
def calculated = calculator.processTags(tags, null)
111+
def calculated = calculator.processTags(tags, null, [])
112112

113113
then:
114114
assert calculated.get(Tags.PEER_SERVICE) == expected

dd-trace-core/src/test/groovy/datadog/trace/core/tagprocessor/PostProcessorChainTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PostProcessorChainTest extends DDSpecification {
2727
def tags = ["key1": "root", "key3": "root"]
2828

2929
when:
30-
def out = chain.processTags(tags, null)
30+
def out = chain.processTags(tags, null, [])
3131

3232
then:
3333
assert out == ["key1": "processor2", "key2": "processor1", "key3": "root"]
@@ -55,7 +55,7 @@ class PostProcessorChainTest extends DDSpecification {
5555
def tags = ["test": "test"]
5656
5757
when:
58-
def out = chain.processTags(tags, null)
58+
def out = chain.processTags(tags, null, [])
5959
6060
then:
6161
assert out == ["my": "tag"]

dd-trace-core/src/test/groovy/datadog/trace/core/tagprocessor/QueryObfuscatorTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class QueryObfuscatorTest extends DDSpecification {
1414
]
1515

1616
when:
17-
def result = obfuscator.processTags(tags, null)
17+
def result = obfuscator.processTags(tags, null, [])
1818

1919
then:
2020
assert result.get(DDTags.HTTP_QUERY) == expectedQuery
@@ -36,7 +36,7 @@ class QueryObfuscatorTest extends DDSpecification {
3636
]
3737

3838
when:
39-
def result = obfuscator.processTags(tags, null)
39+
def result = obfuscator.processTags(tags, null, [])
4040

4141
then:
4242
assert result.get(DDTags.HTTP_QUERY) == expectedQuery

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/InstrumentationTags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class InstrumentationTags {
3636
public static final String TABLE_NAME = "tablename";
3737
public static final String AWS_REQUEST_ID = "aws.requestId";
3838
public static final String AWS_STORAGE_CLASS = "aws.storage.class";
39+
public static final String S3_ETAG = "s3.eTag";
3940

4041
public static final String BUCKET = "bucket";
4142
public static final String CASSANDRA_CONTACT_POINTS = "db.cassandra.contact.points";

0 commit comments

Comments
 (0)