Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn unexpected SpanContext in otel span link #3672

Merged
merged 2 commits into from
Jun 10, 2024
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
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
Loading