Skip to content

Commit

Permalink
Change method to setError
Browse files Browse the repository at this point in the history
Signed-off-by: suranjay <[email protected]>
  • Loading branch information
suranjay committed Jul 4, 2023
1 parent b72f4cd commit e5aa24d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void addSpanEvent(String event) {
}

@Override
public void setStatus(StatusCode statusCode) {
span.setStatus(statusCode);
public void setError(Exception exception) {
span.setError(exception);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public interface Span {
void addAttribute(String key, Boolean value);

/**
* Sets status of the span
* Records error in the span
*
* @param statusCode status of the span
* @param exception exception to be recorded
*/
void setStatus(StatusCode statusCode);
void setError(Exception exception);

/**
* Adds an event in the span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public interface SpanScope extends AutoCloseable {
void addSpanEvent(String event);

/**
* Sets span status {@link Span}.
* Records error in the span
*
* @param statusCode status code
* @param exception exception to be recorded
*/
void setStatus(StatusCode statusCode);
void setError(Exception exception);

/**
* closes the scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.telemetry.tracing.noop;

import org.opensearch.telemetry.tracing.SpanScope;
import org.opensearch.telemetry.tracing.StatusCode;

/**
* No-op implementation of SpanScope
Expand Down Expand Up @@ -47,7 +46,7 @@ public void addSpanEvent(String event) {
}

@Override
public void setStatus(StatusCode statusCode) {
public void setError(Exception exception) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public void testAddEvent() {
verify(mockSpan).addEvent("eventName");
}

public void testSetStatus() {
public void testSetError() {
Span mockSpan = mock(Span.class);
DefaultSpanScope defaultSpanScope = new DefaultSpanScope(mockSpan, null);
defaultSpanScope.setStatus(StatusCode.OK);
Exception ex = new Exception("error");
defaultSpanScope.setError(ex);

verify(mockSpan).setStatus(StatusCode.OK);
verify(mockSpan).setError(ex);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.telemetry.tracing;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;

/**
* Default implementation of {@link Span} using Otel span. It keeps a reference of OpenTelemetry Span and handles span
Expand Down Expand Up @@ -49,8 +50,8 @@ public void addAttribute(String key, Boolean value) {
}

@Override
public void setStatus(StatusCode statusCode) {
delegateSpan.setStatus(io.opentelemetry.api.trace.StatusCode.valueOf(statusCode.name()));
public void setError(Exception exception) {
delegateSpan.setStatus(StatusCode.ERROR, exception.getMessage());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.telemetry.tracing;

import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import io.opentelemetry.sdk.trace.export.SpanExporter;

public class SpanExporterFactory {

public SpanExporter create(SpanExporterType exporterType) {
switch (exporterType) {
case LOGGING:
return LoggingSpanExporter.create();
case OLTP_GRPC:
return
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.telemetry.tracing;

import java.util.Arrays;

public enum SpanExporterType {

LOGGING, OLTP_GRPC;

public static SpanExporterType fromString(String name) {
for (SpanExporterType level : values()) {
if (level.name().equalsIgnoreCase(name)) {
return level;
}
}
throw new IllegalArgumentException(
"invalid value for tracing level [" + name + "], " + "must be in " + Arrays.asList(SpanExporterType.values())
);
}
}

0 comments on commit e5aa24d

Please sign in to comment.