Skip to content

Commit

Permalink
Remove Status object from API, keep StatusCanonicalCode (#1741)
Browse files Browse the repository at this point in the history
* Remove Status object from API, keep StatusCanonicalCode

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>

* Respond to comments, change more old usages

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>

* Fix build, run gojf

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Oct 5, 2020
1 parent 42cdff4 commit eb4a18f
Show file tree
Hide file tree
Showing 44 changed files with 326 additions and 416 deletions.
3 changes: 2 additions & 1 deletion api/src/main/java/io/opentelemetry/trace/DefaultSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.common.AttributeKey;
import io.opentelemetry.common.Attributes;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ public void addEvent(String name, Attributes attributes) {}
public void addEvent(String name, Attributes attributes, long timestamp) {}

@Override
public void setStatus(Status status) {}
public void setStatus(StatusCanonicalCode canonicalCode, @Nullable String description) {}

@Override
public void recordException(Throwable exception) {}
Expand Down
12 changes: 8 additions & 4 deletions api/src/main/java/io/opentelemetry/trace/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.common.AttributeKey;
import io.opentelemetry.common.Attributes;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -201,17 +202,20 @@ default void setAttribute(AttributeKey<Long> key, int value) {
void addEvent(String name, Attributes attributes, long timestamp);

/**
* Sets the {@link Status} to the {@code Span}.
* Sets the status to the {@code Span}.
*
* <p>If used, this will override the default {@code Span} status. Default is {@link Status#OK}.
* <p>If used, this will override the default {@code Span} status. Default status code is {@link
* StatusCanonicalCode#UNSET}.
*
* <p>Only the value of the last call will be recorded, and implementations are free to ignore
* previous calls.
*
* @param status the {@link Status} to set.
* @param canonicalCode the {@link StatusCanonicalCode} to set.
* @param description the description of the {@code Status}.
* @since 0.1.0
*/
void setStatus(Status status);
// TODO: Add a setStatus overload without description.
void setStatus(StatusCanonicalCode canonicalCode, @Nullable String description);

/**
* Records information about the {@link Throwable} to the {@link Span}.
Expand Down
204 changes: 0 additions & 204 deletions api/src/main/java/io/opentelemetry/trace/Status.java

This file was deleted.

43 changes: 43 additions & 0 deletions api/src/main/java/io/opentelemetry/trace/StatusCanonicalCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.trace;

/**
* The set of canonical status codes. If new codes are added over time they must choose a numerical
* value that does not collide with any previously used value.
*
* @since 0.1.0
*/
public enum StatusCanonicalCode {

/**
* The operation has been validated by an Application developers or Operator to have completed
* successfully.
*/
OK(0),

/** The default status. */
UNSET(1),

/** The operation contains an error. */
ERROR(2);

private final int value;

StatusCanonicalCode(int value) {
this.value = value;
}

/**
* Returns the numerical value of the code.
*
* @return the numerical value of the code.
* @since 0.1.0
*/
public int value() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void doNotCrash() {
span.addEvent("event", 0);
span.addEvent("event", Attributes.of(booleanKey("MyBooleanAttributeKey"), true));
span.addEvent("event", Attributes.of(booleanKey("MyBooleanAttributeKey"), true), 0);
span.setStatus(Status.OK);
span.setStatus(StatusCanonicalCode.OK, null);
span.recordException(new IllegalStateException());
span.recordException(new IllegalStateException(), Attributes.empty());
span.end();
Expand Down
41 changes: 0 additions & 41 deletions api/src/test/java/io/opentelemetry/trace/StatusTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import io.opentelemetry.sdk.trace.TestSpanData;
import io.opentelemetry.sdk.trace.TracerSdkProvider;
import io.opentelemetry.sdk.trace.data.ImmutableStatus;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.trace.Span.Kind;
import io.opentelemetry.trace.SpanId;
import io.opentelemetry.trace.Status;
import io.opentelemetry.trace.TraceId;
import io.opentelemetry.trace.Tracer;
import java.util.Collections;
Expand Down Expand Up @@ -94,7 +94,7 @@ static SpanData makeBasicSpan() {
.setName("span")
.setKind(Kind.SERVER)
.setStartEpochNanos(100_000_000_100L)
.setStatus(Status.OK)
.setStatus(ImmutableStatus.OK)
.setEndEpochNanos(200_000_000_200L)
.setTotalRecordedLinks(0)
.setTotalRecordedEvents(0)
Expand Down
Loading

0 comments on commit eb4a18f

Please sign in to comment.