Skip to content

Commit

Permalink
Changed AgentSpanAttributes to nested Attributes interface under Agen…
Browse files Browse the repository at this point in the history
…tSpan
  • Loading branch information
mtoffl01 committed Aug 13, 2024
1 parent 5114b94 commit a248438
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import static java.util.Locale.ROOT;

import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanAttributes;
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import java.util.List;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -228,8 +228,7 @@ private static String getStringAttribute(AgentSpan span, String key) {
return (String) tag;
}

public static AgentSpanAttributes convertAttributes(
io.opentelemetry.api.common.Attributes attributes) {
public static AgentSpan.Attributes convertAttributes(Attributes attributes) {
if (attributes.isEmpty()) {
return SpanAttributes.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.squareup.moshi.ToJson;
import datadog.trace.api.DDSpanId;
import datadog.trace.api.DDTraceId;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanAttributes;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
import datadog.trace.bootstrap.instrumentation.api.SpanLink;
Expand All @@ -30,7 +30,7 @@ protected DDSpanLink(
long spanId,
byte traceFlags,
String traceState,
AgentSpanAttributes attributes) {
AgentSpan.Attributes attributes) {
super(traceId, spanId, traceFlags, traceState, attributes);
}

Expand All @@ -53,7 +53,7 @@ public static SpanLink from(ExtractedContext context) {
* @param attributes The span link attributes.
* @return A span link to the given context with custom attributes.
*/
public static SpanLink from(ExtractedContext context, AgentSpanAttributes attributes) {
public static SpanLink from(ExtractedContext context, AgentSpan.Attributes attributes) {
byte traceFlags = context.getSamplingPriority() > 0 ? SAMPLED_FLAG : DEFAULT_FLAGS;
String traceState =
context.getPropagationTags() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,20 @@ interface Extracted extends Context {
String getCustomIpHeader();
}
}

public interface Attributes {
/**
* Gets the attributes as an immutable map.
*
* @return The attributes as an immutable map.
*/
Map<String, String> asMap();

/**
* Checks whether the attributes are empty.
*
* @return {@code true} if the attributes are empty, {@code false} otherwise.
*/
boolean isEmpty();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ public interface AgentSpanLink {
*
* @return The link attributes.
*/
AgentSpanAttributes attributes();
AgentSpan.Attributes attributes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import java.util.Map;

/** This class is a base implementation of {@link AgentSpanAttributes}. */
public class SpanAttributes implements AgentSpanAttributes {
// TODO: How to link to AgentSpan.Attributes?
public class SpanAttributes implements AgentSpan.Attributes {
/** Represent an empty attributes. */
public static final AgentSpanAttributes EMPTY = new SpanAttributes(Collections.emptyMap());
public static final AgentSpan.Attributes EMPTY = new SpanAttributes(Collections.emptyMap());

private final Map<String, String> attributes;

Expand Down Expand Up @@ -114,7 +115,7 @@ protected <T> Builder putArray(String key, List<T> array) {
return this;
}

public AgentSpanAttributes build() {
public AgentSpan.Attributes build() {
return new SpanAttributes(this.attributes);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class SpanLink implements AgentSpanLink {
private final long spanId;
private final byte traceFlags;
private final String traceState;
private final AgentSpanAttributes attributes;
private final AgentSpan.Attributes attributes;

protected SpanLink(
DDTraceId traceId,
long spanId,
byte traceFlags,
String traceState,
AgentSpanAttributes attributes) {
AgentSpan.Attributes attributes) {
this.traceId = traceId == null ? DDTraceId.ZERO : traceId;
this.spanId = spanId;
this.traceFlags = traceFlags;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static SpanLink from(
AgentSpan.Context context,
byte traceFlags,
String traceState,
AgentSpanAttributes attributes) {
AgentSpan.Attributes attributes) {
if (context.getSamplingPriority() > 0) {
traceFlags = (byte) (traceFlags | SAMPLED_FLAG);
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public String traceState() {
}

@Override
public AgentSpanAttributes attributes() {
public AgentSpan.Attributes attributes() {
return this.attributes;
}

Expand Down

0 comments on commit a248438

Please sign in to comment.