Skip to content

Commit

Permalink
Remove endSpan method
Browse files Browse the repository at this point in the history
  • Loading branch information
suranjay committed Jun 27, 2023
1 parent f2b1417 commit bae04ac
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ public Scope startSpan(String spanName) {
return new ScopeImpl(() -> endSpan(span));
}

@Override
public void endSpan() {
Span currentSpan = getCurrentSpan();
endSpan(currentSpan);
}

@Override
public void addSpanAttribute(String key, String value) {
Span currentSpan = getCurrentSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ public interface Tracer extends Closeable {
* Starts the {@link Span} with given name
*
* @param spanName span name
* @return scope of the span, can be used with try-with-resources to close the span
* @return scope of the span, must be closed with explicit close or with try-with-resource
*/
Scope startSpan(String spanName);

/**
* Ends the current active {@link Span}
*
*/
void endSpan();

/**
* Adds string attribute to the current active {@link Span}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public Scope startSpan(String spanName) {
return Scope.NO_OP;
}

@Override
public void endSpan() {}

/**
* @param key attribute key
* @param value attribute value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ public void testCreateSpan() {
Assert.assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName());
}

public void testEndSpan() {
DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage);
defaultTracer.startSpan("span_name");
verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockSpan);

defaultTracer.endSpan();
verify(mockSpan).endSpan();
verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockParentSpan);
}

public void testEndSpanByClosingScope() {
DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage);
try (Scope scope = defaultTracer.startSpan("span_name")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,55 @@
*/
class OTelSpan extends AbstractSpan {

private final Span oTelSpan;
private final Span delegateSpan;

public OTelSpan(String spanName, Span span, org.opensearch.telemetry.tracing.Span parentSpan) {
super(spanName, parentSpan);
this.oTelSpan = span;
this.delegateSpan = span;
}

@Override
public void endSpan() {
oTelSpan.end();
delegateSpan.end();
}

@Override
public void addAttribute(String key, String value) {
oTelSpan.setAttribute(key, value);
delegateSpan.setAttribute(key, value);
}

@Override
public void addAttribute(String key, Long value) {
oTelSpan.setAttribute(key, value);
delegateSpan.setAttribute(key, value);
}

@Override
public void addAttribute(String key, Double value) {
oTelSpan.setAttribute(key, value);
delegateSpan.setAttribute(key, value);
}

@Override
public void addAttribute(String key, Boolean value) {
oTelSpan.setAttribute(key, value);
delegateSpan.setAttribute(key, value);
}

@Override
public void addEvent(String event) {
oTelSpan.addEvent(event);
delegateSpan.addEvent(event);
}

@Override
public String getTraceId() {
return oTelSpan.getSpanContext().getTraceId();
return delegateSpan.getSpanContext().getTraceId();
}

@Override
public String getSpanId() {
return oTelSpan.getSpanContext().getSpanId();
return delegateSpan.getSpanContext().getSpanId();
}

io.opentelemetry.api.trace.Span getoTelSpan() {
return oTelSpan;
io.opentelemetry.api.trace.Span getDelegateSpan() {
return delegateSpan;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void inject(Span currentSpan, BiConsumer<String, String> setter) {
}

private static Context context(OTelSpan oTelSpan) {
return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getoTelSpan().getSpanContext()));
return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getDelegateSpan().getSpanContext()));
}

private static final TextMapSetter<BiConsumer<String, String>> TEXT_MAP_SETTER = (carrier, key, value) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ private Span createOtelSpan(String spanName, Span parentSpan) {
io.opentelemetry.api.trace.Span otelSpan(String spanName, Span parentOTelSpan) {
return parentOTelSpan == null || !(parentOTelSpan instanceof OTelSpan)
? otelTracer.spanBuilder(spanName).startSpan()
: otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getoTelSpan())).startSpan();
: otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getDelegateSpan())).startSpan();
}
}

0 comments on commit bae04ac

Please sign in to comment.