Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion inferred-spans/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
compileOnly("com.google.auto.service:auto-service-annotations")
compileOnly("io.opentelemetry:opentelemetry-sdk")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
compileOnly("io.opentelemetry.semconv:opentelemetry-semconv")
implementation("com.lmax:disruptor")
implementation("org.jctools:jctools-core")
implementation("tools.profiler:async-profiler")
Expand All @@ -21,7 +22,7 @@ dependencies {

testAnnotationProcessor("com.google.auto.service:auto-service")
testCompileOnly("com.google.auto.service:auto-service-annotations")
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv")
testImplementation("io.opentelemetry:opentelemetry-sdk")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.contrib.inferredspans.internal;

import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.CODE_STACKTRACE;
import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.LINK_IS_CHILD;
import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.SPAN_IS_INFERRED;
import static java.util.logging.Level.FINE;
Expand All @@ -20,6 +19,7 @@
import io.opentelemetry.contrib.inferredspans.internal.pooling.ObjectPool;
import io.opentelemetry.contrib.inferredspans.internal.pooling.Recyclable;
import io.opentelemetry.contrib.inferredspans.internal.util.HexUtils;
import io.opentelemetry.semconv.CodeAttributes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -515,7 +515,7 @@ protected Span asSpan(
assert this.parent != null;
tempBuilder.setLength(0);
this.parent.fillStackTrace(tempBuilder);
spanBuilder.setAttribute(CODE_STACKTRACE, tempBuilder.toString());
spanBuilder.setAttribute(CodeAttributes.CODE_STACKTRACE, tempBuilder.toString());
}

Span span = spanBuilder.startSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class Attributes {

private Attributes() {}

public static final AttributeKey<String> CODE_STACKTRACE =
AttributeKey.stringKey("code.stacktrace");
public static final AttributeKey<Boolean> LINK_IS_CHILD = AttributeKey.booleanKey("is_child");
public static final AttributeKey<Boolean> SPAN_IS_INFERRED =
AttributeKey.booleanKey("is_inferred");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.contrib.inferredspans.internal;

import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.CODE_STACKTRACE;
import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.SPAN_IS_INFERRED;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

Expand All @@ -21,6 +20,7 @@
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.semconv.CodeAttributes;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -64,26 +64,26 @@ void testSpanification() throws Exception {
SpanData a = setup.getSpans().get(1);
assertThat(a).hasName("CallTreeTest#a");
assertThat(a.getEndEpochNanos() - a.getStartEpochNanos()).isEqualTo(30_000_000);
assertThat(a.getAttributes().get(CODE_STACKTRACE)).isBlank();
assertThat(a.getAttributes().get(CodeAttributes.CODE_STACKTRACE)).isBlank();
assertThat(a).hasAttribute(SPAN_IS_INFERRED, true);

SpanData b = setup.getSpans().get(2);
assertThat(b).hasName("CallTreeTest#b");
assertThat(b.getEndEpochNanos() - b.getStartEpochNanos()).isEqualTo(20_000_000);
assertThat(b.getAttributes().get(CODE_STACKTRACE)).isBlank();
assertThat(b.getAttributes().get(CodeAttributes.CODE_STACKTRACE)).isBlank();
assertThat(b).hasAttribute(SPAN_IS_INFERRED, true);

SpanData d = setup.getSpans().get(3);
assertThat(d).hasName("CallTreeTest#d");
assertThat(d.getEndEpochNanos() - d.getStartEpochNanos()).isEqualTo(10_000_000);
assertThat(d.getAttributes().get(CODE_STACKTRACE))
assertThat(d.getAttributes().get(CodeAttributes.CODE_STACKTRACE))
.isEqualTo("at " + CallTreeTest.class.getName() + ".c(CallTreeTest.java)");
assertThat(d).hasAttribute(SPAN_IS_INFERRED, true);

SpanData e = setup.getSpans().get(4);
assertThat(e).hasName("CallTreeTest#e");
assertThat(e.getEndEpochNanos() - e.getStartEpochNanos()).isEqualTo(10_000_000);
assertThat(e.getAttributes().get(CODE_STACKTRACE)).isBlank();
assertThat(e.getAttributes().get(CodeAttributes.CODE_STACKTRACE)).isBlank();
assertThat(e).hasAttribute(SPAN_IS_INFERRED, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.contrib.inferredspans.internal;

import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.CODE_STACKTRACE;
import static io.opentelemetry.contrib.inferredspans.internal.semconv.Attributes.LINK_IS_CHILD;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static java.util.stream.Collectors.toMap;
Expand All @@ -20,6 +19,7 @@
import io.opentelemetry.contrib.inferredspans.internal.util.DisabledOnOpenJ9;
import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.CodeAttributes;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
Expand Down Expand Up @@ -924,7 +924,7 @@ private Map<String, SpanData> assertCallTree(
.describedAs("Unexpected duration for span %s", span)
.isEqualTo(durationMs * 1_000_000L);

String actualStacktrace = span.getAttributes().get(CODE_STACKTRACE);
String actualStacktrace = span.getAttributes().get(CodeAttributes.CODE_STACKTRACE);
if (stackTrace == null || stackTrace.isEmpty()) {
assertThat(actualStacktrace).isBlank();
} else {
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion span-stacktrace/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ dependencies {
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")

testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
compileOnly("io.opentelemetry.semconv:opentelemetry-semconv")
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv")

testAnnotationProcessor("com.google.auto.service:auto-service")
testCompileOnly("com.google.auto.service:auto-service-annotations")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@

package io.opentelemetry.contrib.stacktrace;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.internal.ExtendedSpanProcessor;
import io.opentelemetry.semconv.CodeAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.function.Predicate;

public class StackTraceSpanProcessor implements ExtendedSpanProcessor {

// inlined incubating attribute to prevent direct dependency on incubating semconv
private static final AttributeKey<String> SPAN_STACKTRACE =
AttributeKey.stringKey("code.stacktrace");

private final long minSpanDurationNanos;

private final Predicate<ReadableSpan> filterPredicate;
Expand Down Expand Up @@ -56,14 +52,14 @@ public void onEnding(ReadWriteSpan span) {
if (span.getLatencyNanos() < minSpanDurationNanos) {
return;
}
if (span.getAttribute(SPAN_STACKTRACE) != null) {
if (span.getAttribute(CodeAttributes.CODE_STACKTRACE) != null) {
// Span already has a stacktrace, do not override
return;
}
if (!filterPredicate.test(span)) {
return;
}
span.setAttribute(SPAN_STACKTRACE, generateSpanEndStacktrace());
span.setAttribute(CodeAttributes.CODE_STACKTRACE, generateSpanEndStacktrace());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
import io.opentelemetry.semconv.CodeAttributes;
import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
Expand Down Expand Up @@ -89,7 +89,7 @@ void spanWithExistingStackTrace() {
YesPredicate.class,
"1ms",
Duration.ofMillis(1).toNanos(),
sb -> sb.setAttribute(CodeIncubatingAttributes.CODE_STACKTRACE, "hello"),
sb -> sb.setAttribute(CodeAttributes.CODE_STACKTRACE, "hello"),
stacktrace -> assertThat(stacktrace).isEqualTo("hello"));
}

Expand Down Expand Up @@ -169,8 +169,7 @@ private static void checkSpan(
List<SpanData> finishedSpans = spansExporter.getFinishedSpanItems();
assertThat(finishedSpans).hasSize(1);

String stackTrace =
finishedSpans.get(0).getAttributes().get(CodeIncubatingAttributes.CODE_STACKTRACE);
String stackTrace = finishedSpans.get(0).getAttributes().get(CodeAttributes.CODE_STACKTRACE);

stackTraceCheck.accept(stackTrace);
}
Expand Down
Loading