Skip to content

Commit bb95c55

Browse files
committed
Squash AgentSpan.Attributes with SpanAttributes (its only implementation)
1 parent a4db58b commit bb95c55

File tree

6 files changed

+25
-37
lines changed

6 files changed

+25
-37
lines changed

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/trace/OtelConventions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private static String getStringAttribute(AgentSpan span, String key) {
249249
return (String) tag;
250250
}
251251

252-
public static AgentSpan.Attributes convertAttributes(Attributes attributes) {
252+
public static SpanAttributes convertAttributes(Attributes attributes) {
253253
if (attributes.isEmpty()) {
254254
return SpanAttributes.EMPTY;
255255
}

dd-trace-core/src/main/java/datadog/trace/core/DDSpanLink.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.squareup.moshi.ToJson;
99
import datadog.trace.api.DDSpanId;
1010
import datadog.trace.api.DDTraceId;
11-
import datadog.trace.bootstrap.instrumentation.api.AgentSpan.Attributes;
1211
import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
1312
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
1413
import datadog.trace.bootstrap.instrumentation.api.SpanLink;
@@ -26,7 +25,11 @@ public class DDSpanLink extends SpanLink {
2625
private static final int TAG_MAX_LENGTH = 25_000;
2726

2827
protected DDSpanLink(
29-
DDTraceId traceId, long spanId, byte traceFlags, String traceState, Attributes attributes) {
28+
DDTraceId traceId,
29+
long spanId,
30+
byte traceFlags,
31+
String traceState,
32+
SpanAttributes attributes) {
3033
super(traceId, spanId, traceFlags, traceState, attributes);
3134
}
3235

@@ -49,7 +52,7 @@ public static SpanLink from(ExtractedContext context) {
4952
* @param attributes The span link attributes.
5053
* @return A span link to the given context with custom attributes.
5154
*/
52-
public static SpanLink from(ExtractedContext context, Attributes attributes) {
55+
public static SpanLink from(ExtractedContext context, SpanAttributes attributes) {
5356
byte traceFlags = context.getSamplingPriority() > 0 ? SAMPLED_FLAG : DEFAULT_FLAGS;
5457
String traceState =
5558
context.getPropagationTags() == null

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import datadog.trace.api.gateway.IGSpanInfo;
66
import datadog.trace.api.gateway.RequestContext;
77
import datadog.trace.api.interceptor.MutableSpan;
8-
import java.util.Map;
98

109
public interface AgentSpan extends MutableSpan, IGSpanInfo, WithAgentSpan {
1110

@@ -146,20 +145,4 @@ public interface AgentSpan extends MutableSpan, IGSpanInfo, WithAgentSpan {
146145
default AgentSpan asAgentSpan() {
147146
return this;
148147
}
149-
150-
interface Attributes {
151-
/**
152-
* Gets the attributes as an immutable map.
153-
*
154-
* @return The attributes as an immutable map.
155-
*/
156-
Map<String, String> asMap();
157-
158-
/**
159-
* Checks whether the attributes are empty.
160-
*
161-
* @return {@code true} if the attributes are empty, {@code false} otherwise.
162-
*/
163-
boolean isEmpty();
164-
}
165148
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package datadog.trace.bootstrap.instrumentation.api;
22

33
import datadog.trace.api.DDTraceId;
4-
import datadog.trace.bootstrap.instrumentation.api.AgentSpan.Attributes;
54

65
/**
76
* This interface describes a link to another span. The linked span could be part of the same trace
@@ -50,5 +49,5 @@ public interface AgentSpanLink {
5049
*
5150
* @return The link attributes.
5251
*/
53-
Attributes attributes();
52+
SpanAttributes attributes();
5453
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import static java.util.Objects.requireNonNull;
44

5-
import datadog.trace.bootstrap.instrumentation.api.AgentSpan.Attributes;
65
import java.util.Collections;
76
import java.util.HashMap;
87
import java.util.List;
98
import java.util.Map;
109

11-
/** This class is a base implementation of {@link Attributes}. */
12-
public class SpanAttributes implements Attributes {
10+
public class SpanAttributes {
1311
/** Represent an empty attributes. */
14-
public static final Attributes EMPTY = new SpanAttributes(Collections.emptyMap());
12+
public static final SpanAttributes EMPTY = new SpanAttributes(Collections.emptyMap());
1513

1614
private final Map<String, String> attributes;
1715

@@ -38,12 +36,20 @@ public static SpanAttributes fromMap(Map<String, String> map) {
3836
return new SpanAttributes(new HashMap<>(map));
3937
}
4038

41-
@Override
39+
/**
40+
* Gets the attributes as an immutable map.
41+
*
42+
* @return The attributes as an immutable map.
43+
*/
4244
public Map<String, String> asMap() {
4345
return this.attributes;
4446
}
4547

46-
@Override
48+
/**
49+
* Checks whether the attributes are empty.
50+
*
51+
* @return {@code true} if the attributes are empty, {@code false} otherwise.
52+
*/
4753
public boolean isEmpty() {
4854
return this.attributes.isEmpty();
4955
}
@@ -115,7 +121,7 @@ protected <T> Builder putArray(String key, List<T> array) {
115121
return this;
116122
}
117123

118-
public Attributes build() {
124+
public SpanAttributes build() {
119125
return new SpanAttributes(this.attributes);
120126
}
121127
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public class SpanLink implements AgentSpanLink {
1010
private final long spanId;
1111
private final byte traceFlags;
1212
private final String traceState;
13-
private final AgentSpan.Attributes attributes;
13+
private final SpanAttributes attributes;
1414

1515
protected SpanLink(
1616
DDTraceId traceId,
1717
long spanId,
1818
byte traceFlags,
1919
String traceState,
20-
AgentSpan.Attributes attributes) {
20+
SpanAttributes attributes) {
2121
this.traceId = traceId == null ? DDTraceId.ZERO : traceId;
2222
this.spanId = spanId;
2323
this.traceFlags = traceFlags;
@@ -47,10 +47,7 @@ public static SpanLink from(AgentSpanContext context) {
4747
* @return A span link to the given context.
4848
*/
4949
public static SpanLink from(
50-
AgentSpanContext context,
51-
byte traceFlags,
52-
String traceState,
53-
AgentSpan.Attributes attributes) {
50+
AgentSpanContext context, byte traceFlags, String traceState, SpanAttributes attributes) {
5451
if (context.getSamplingPriority() > 0) {
5552
traceFlags = (byte) (traceFlags | SAMPLED_FLAG);
5653
}
@@ -79,7 +76,7 @@ public String traceState() {
7976
}
8077

8178
@Override
82-
public AgentSpan.Attributes attributes() {
79+
public SpanAttributes attributes() {
8380
return this.attributes;
8481
}
8582

0 commit comments

Comments
 (0)