class ApplicationSpan implements Span {
private final io.opentelemetry.api.trace.Span agentSpan;
ApplicationSpan(io.opentelemetry.api.trace.Span agentSpan) {
this.agentSpan = agentSpan;
io.opentelemetry.api.trace.Span getAgentSpan() {
public Span setAttribute(String key, String value) {
agentSpan.setAttribute(key, value);
public Span setAttribute(String key, long value) {
agentSpan.setAttribute(key, value);
public Span setAttribute(String key, double value) {
agentSpan.setAttribute(key, value);
public Span setAttribute(String key, boolean value) {
agentSpan.setAttribute(key, value);
public <T> Span setAttribute(AttributeKey<T> applicationKey, T value) {
@SuppressWarnings("unchecked")
io.opentelemetry.api.common.AttributeKey<T> agentKey = Bridging.toAgent(applicationKey);
agentSpan.setAttribute(agentKey, value);
public Span addEvent(String name) {
agentSpan.addEvent(name);
public Span addEvent(String name, long timestamp, TimeUnit unit) {
agentSpan.addEvent(name, timestamp, unit);
public Span addEvent(String name, Attributes applicationAttributes) {
agentSpan.addEvent(name, Bridging.toAgent(applicationAttributes));
String name, Attributes applicationAttributes, long timestamp, TimeUnit unit) {
agentSpan.addEvent(name, Bridging.toAgent(applicationAttributes), timestamp, unit);
public Span setStatus(StatusCode status) {
agentSpan.setStatus(Bridging.toAgent(status));
public Span setStatus(StatusCode status, String description) {
agentSpan.setStatus(Bridging.toAgent(status), description);
public Span recordException(Throwable throwable) {
agentSpan.recordException(throwable);
public Span recordException(Throwable throwable, Attributes attributes) {
agentSpan.recordException(throwable, Bridging.toAgent(attributes));
public Span updateName(String name) {
agentSpan.updateName(name);
public void end(long timestamp, TimeUnit unit) {
agentSpan.end(timestamp, unit);
public SpanContext getSpanContext() {
return Bridging.toApplication(agentSpan.getSpanContext());
public boolean isRecording() {
return agentSpan.isRecording();
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof ApplicationSpan)) {
ApplicationSpan other = (ApplicationSpan) obj;
return agentSpan.equals(other.agentSpan);
public String toString() {
return "ApplicationSpan{agentSpan=" + agentSpan + '}';
return agentSpan.hashCode();
static class Builder implements SpanBuilder {
private final io.opentelemetry.api.trace.SpanBuilder agentBuilder;
Builder(io.opentelemetry.api.trace.SpanBuilder agentBuilder) {
this.agentBuilder = agentBuilder;
public SpanBuilder setParent(Context applicationContext) {
agentBuilder.setParent(AgentContextStorage.getAgentContext(applicationContext));
public SpanBuilder setNoParent() {
agentBuilder.setNoParent();
public SpanBuilder addLink(SpanContext applicationSpanContext) {
agentBuilder.addLink(Bridging.toAgent(applicationSpanContext));
public SpanBuilder addLink(
SpanContext applicationSpanContext, Attributes applicationAttributes) {
agentBuilder.addLink(Bridging.toAgent(applicationSpanContext));
public SpanBuilder setAttribute(String key, String value) {
agentBuilder.setAttribute(key, value);
public SpanBuilder setAttribute(String key, long value) {
agentBuilder.setAttribute(key, value);
public SpanBuilder setAttribute(String key, double value) {
agentBuilder.setAttribute(key, value);
public SpanBuilder setAttribute(String key, boolean value) {
agentBuilder.setAttribute(key, value);
public <T> SpanBuilder setAttribute(AttributeKey<T> applicationKey, T value) {
@SuppressWarnings("unchecked")
io.opentelemetry.api.common.AttributeKey<T> agentKey = Bridging.toAgent(applicationKey);
agentBuilder.setAttribute(agentKey, value);
public SpanBuilder setSpanKind(SpanKind applicationSpanKind) {
io.opentelemetry.api.trace.SpanKind agentSpanKind = toAgentOrNull(applicationSpanKind);
if (agentSpanKind != null) {
agentBuilder.setSpanKind(agentSpanKind);
public SpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) {
agentBuilder.setStartTimestamp(startTimestamp, unit);
public Span startSpan() {
return new ApplicationSpan(agentBuilder.startSpan());