Skip to content

Commit

Permalink
Warn unexpected SpanContext in otel span link (#3672)
Browse files Browse the repository at this point in the history
* add warning with non elastic spancontext

* update changelog
  • Loading branch information
SylvainJuge authored Jun 10, 2024
1 parent 7c63ade commit f17e701
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
[float]
===== Bug fixes
* Restore compatibility with Java 7 - {pull}3657[#3657]
* Avoid `ClassCastException` and issue warning when trying to use otel span links - {pull}3672[#3672]
[float]
===== Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
import co.elastic.apm.agent.impl.baggage.Baggage;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.MultiValueMapAccessor;
import co.elastic.apm.agent.impl.transaction.OTelSpanKind;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.opentelemetry.baggage.OtelBaggage;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import co.elastic.apm.agent.sdk.internal.util.LoggerUtils;
import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils;
import co.elastic.apm.agent.sdk.internal.util.VersionUtils;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -53,7 +52,8 @@

class OTelSpanBuilder implements SpanBuilder {

private static final Logger addLinkLogger = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpanBuilder.class));
private static final Logger addLinkLogger1 = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpanBuilder.class));
private static final Logger addLinkLogger2 = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpanBuilder.class));

private final String spanName;
private final ElasticApmTracer elasticApmTracer;
Expand Down Expand Up @@ -86,15 +86,19 @@ public SpanBuilder setNoParent() {

@Override
public SpanBuilder addLink(SpanContext spanContext) {
if (!(spanContext instanceof OTelSpanContext)) {
addLinkLogger2.warn("Adding arbitrary span context to links is currently unsupported");
return this;
}
links.add(spanContext);
return this;
}

@Override
public SpanBuilder addLink(SpanContext spanContext, Attributes attributes1) {
public SpanBuilder addLink(SpanContext spanContext, @Nullable Attributes attributes1) {
addLink(spanContext);
if (attributes1 != null && !attributes1.isEmpty()) {
addLinkLogger.warn("Adding attributes to links is currently unsupported - the links have been added but with no attributes, the following attributes have been ignored: %s",attributes1);
addLinkLogger1.warn("Adding attributes to links is currently unsupported - the links have been added but with no attributes, the following attributes have been ignored: %s", attributes1);
}
return this;
}
Expand Down Expand Up @@ -182,7 +186,7 @@ public Span startSpan() {
t.setFrameworkName("OpenTelemetry API");

String otelVersion = VersionUtils.getVersion(OpenTelemetry.class, "io.opentelemetry", "opentelemetry-api");
if(otelVersion != null){
if (otelVersion != null) {
t.setFrameworkVersion(otelVersion);
}
}
Expand Down

0 comments on commit f17e701

Please sign in to comment.