Skip to content

Commit

Permalink
[Tracing Framework] Add proper API annotations (opensearch-project#9706)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
Signed-off-by: Ivan Brusic <[email protected]>
  • Loading branch information
reta authored and brusic committed Sep 25, 2023
1 parent 084e854 commit 6f688e0
Show file tree
Hide file tree
Showing 34 changed files with 120 additions and 14 deletions.
2 changes: 2 additions & 0 deletions libs/telemetry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/

dependencies {
api project(':libs:opensearch-common')

testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
testImplementation "junit:junit:${versions.junit}"
testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

package org.opensearch.telemetry;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.metrics.MetricsTelemetry;
import org.opensearch.telemetry.tracing.TracingTelemetry;

/**
* Interface defining telemetry
*
* @opensearch.internal
* @opensearch.experimental
*/
@ExperimentalApi
public interface Telemetry {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

package org.opensearch.telemetry.metrics;

import org.opensearch.common.annotation.ExperimentalApi;

/**
* Interface for metrics telemetry providers
*
* @opensearch.experimental
*/
@ExperimentalApi
public interface MetricsTelemetry {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.InternalApi;

/**
* Base span
*
* @opensearch.internal
*/
@InternalApi
public abstract class AbstractSpan implements Span {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.InternalApi;

import java.util.Objects;

/**
* Default implementation of Scope
*
* @opensearch.internal
*/
@InternalApi
final class DefaultScopedSpan implements ScopedSpan {

private final Span span;
Expand Down Expand Up @@ -73,7 +76,7 @@ public void close() {

/**
* Returns span.
* @return
* @return the span associated with this scope
*/
Span getSpan() {
return span;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.InternalApi;

import java.util.Objects;

/**
* Default implementation for {@link SpanScope}
*
* @opensearch.internal
*/
public class DefaultSpanScope implements SpanScope {
@InternalApi
class DefaultSpanScope implements SpanScope {
private final Span span;
private final SpanScope previousSpanScope;
private static final ThreadLocal<SpanScope> spanScopeThreadLocal = new ThreadLocal<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.InternalApi;
import org.opensearch.telemetry.tracing.attributes.Attributes;

import java.io.Closeable;
Expand All @@ -23,6 +24,7 @@
*
* @opensearch.internal
*/
@InternalApi
class DefaultTracer implements Tracer {
static final String THREAD_NAME = "th_name";

Expand Down Expand Up @@ -77,6 +79,7 @@ private Span getCurrentSpanInternal() {
return tracerContextStorage.get(TracerContextStorage.CURRENT_SPAN);
}

@Override
public SpanContext getCurrentSpan() {
final Span currentSpan = tracerContextStorage.get(TracerContextStorage.CURRENT_SPAN);
return (currentSpan == null) ? null : new SpanContext(currentSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.tracing.noop.NoopScopedSpan;

/**
* An auto-closeable that represents scoped span.
* It provides interface for all the span operations.
*
* @opensearch.experimental
*/
@ExperimentalApi
public interface ScopedSpan extends AutoCloseable {
/**
* No-op Scope implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;

/**
* An interface that represents a tracing span.
* Spans are created by the Tracer.startSpan method.
* Span must be ended by calling SpanScope.close which internally calls Span's endSpan.
*
* @opensearch.internal
* @opensearch.experimental
*/
@ExperimentalApi
public interface Span {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;

/**
* Wrapped Span will be exposed to the code outside of tracing package for sharing the {@link Span} without having access to
* its properties.
*
* @opensearch.experimental
*/
@ExperimentalApi
public final class SpanContext {
private final Span span;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.tracing.attributes.Attributes;

/**
* Context for span details.
*
* @opensearch.experimental
*/
@ExperimentalApi
public final class SpanCreationContext {
private final String spanName;
private final Attributes attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.InternalApi;

/**
* Wrapper class to hold reference of Span
*
* @opensearch.internal
*/
@InternalApi
final class SpanReference {

private Span span;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.tracing.noop.NoopSpanScope;

/**
* An auto-closeable that represents scope of the span.
*
* @opensearch.experimental
*/
@ExperimentalApi
public interface SpanScope extends AutoCloseable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.tracing.attributes.Attributes;
import org.opensearch.telemetry.tracing.http.HttpTracer;

Expand All @@ -18,7 +19,10 @@
* It automatically handles the context propagation between threads, tasks, nodes etc.
*
* All methods on the Tracer object are multi-thread safe.
*
* @opensearch.experimental
*/
@ExperimentalApi
public interface Tracer extends HttpTracer, Closeable {
/**
* Starts the {@link Span} with given {@link SpanCreationContext}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.InternalApi;

/**
* Storage interface used for storing tracing context
* @param <K> key type
* @param <V> value type
*
* @opensearch.internal
*/
@InternalApi
public interface TracerContextStorage<K, V> {
/**
* Key for storing current span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;

import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -16,8 +18,9 @@
/**
* Interface defining the tracing related context propagation
*
* @opensearch.internal
* @opensearch.experimental
*/
@ExperimentalApi
public interface TracingContextPropagator {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

package org.opensearch.telemetry.tracing;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.tracing.attributes.Attributes;

import java.io.Closeable;

/**
* Interface for tracing telemetry providers
*
* @opensearch.internal
* @opensearch.experimental
*/
@ExperimentalApi
public interface TracingTelemetry extends Closeable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@

package org.opensearch.telemetry.tracing.attributes;

import org.opensearch.common.annotation.ExperimentalApi;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Class to create attributes for a span.
*
* @opensearch.experimental
*/
@ExperimentalApi
public class Attributes {
private final Map<String, Object> attributesMap;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/

/**
* Contains No-op implementations
* Contains attributes management
*/
package org.opensearch.telemetry.tracing.attributes;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.telemetry.tracing.http;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.telemetry.tracing.Span;
import org.opensearch.telemetry.tracing.attributes.Attributes;

Expand All @@ -19,7 +20,10 @@
* from the HttpRequest header and propagate the span accordingly.
*
* All methods on the Tracer object are multi-thread safe.
*
* @opensearch.experimental
*/
@ExperimentalApi
public interface HttpTracer {
/**
* Start the span with propagating the tracing info from the HttpRequest header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

package org.opensearch.telemetry.tracing.noop;

import org.opensearch.common.annotation.InternalApi;
import org.opensearch.telemetry.tracing.ScopedSpan;

/**
* No-op implementation of SpanScope
*
* @opensearch.internal
*/
@InternalApi
public final class NoopScopedSpan implements ScopedSpan {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

package org.opensearch.telemetry.tracing.noop;

import org.opensearch.common.annotation.InternalApi;
import org.opensearch.telemetry.tracing.Span;

/**
* No-op implementation of {@link org.opensearch.telemetry.tracing.Span}
*
* @opensearch.internal
*/
@InternalApi
public class NoopSpan implements Span {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

package org.opensearch.telemetry.tracing.noop;

import org.opensearch.common.annotation.InternalApi;
import org.opensearch.telemetry.tracing.Span;
import org.opensearch.telemetry.tracing.SpanScope;

/**
* No-op implementation of {@link SpanScope}
*
* @opensearch.internal
*/
@InternalApi
public class NoopSpanScope implements SpanScope {
/**
* Constructor.
Expand Down
Loading

0 comments on commit 6f688e0

Please sign in to comment.