-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * Move span operation to Scope from Tracer (#8411) * Move span operation to Scope from Tracer Signed-off-by: suranjay <[email protected]> * Add changelog entry Signed-off-by: suranjay <[email protected]> * Change method to setError Signed-off-by: suranjay <[email protected]> * Removed unused classes Signed-off-by: suranjay <[email protected]> * Fix merge issue Signed-off-by: suranjay <[email protected]> --------- Signed-off-by: suranjay <[email protected]> * Empty-Commit Signed-off-by: suranjay <[email protected]> --------- Signed-off-by: suranjay <[email protected]>
- Loading branch information
Showing
15 changed files
with
309 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultSpanScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.function.Consumer; | ||
|
||
/** | ||
* Default implementation of Scope | ||
*/ | ||
public class DefaultSpanScope implements SpanScope { | ||
|
||
private final Span span; | ||
|
||
private final Consumer<Span> onCloseConsumer; | ||
|
||
/** | ||
* Creates Scope instance for the given span | ||
* | ||
* @param span underlying span | ||
* @param onCloseConsumer consumer to execute on scope close | ||
*/ | ||
public DefaultSpanScope(Span span, Consumer<Span> onCloseConsumer) { | ||
this.span = span; | ||
this.onCloseConsumer = onCloseConsumer; | ||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, String value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, long value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, double value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, boolean value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addSpanEvent(String event) { | ||
span.addEvent(event); | ||
} | ||
|
||
@Override | ||
public void setError(Exception exception) { | ||
span.setError(exception); | ||
} | ||
|
||
/** | ||
* Executes the runnable to end the scope | ||
*/ | ||
@Override | ||
public void close() { | ||
onCloseConsumer.accept(span); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Scope.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/ScopeImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 org.opensearch.telemetry.tracing.noop.NoopSpanScope; | ||
|
||
/** | ||
* An auto-closeable that represents scope of the span. | ||
* It provides interface for all the span operations. | ||
*/ | ||
public interface SpanScope extends AutoCloseable { | ||
/** | ||
* No-op Scope implementation | ||
*/ | ||
SpanScope NO_OP = new NoopSpanScope(); | ||
|
||
/** | ||
* Adds string attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addSpanAttribute(String key, String value); | ||
|
||
/** | ||
* Adds long attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addSpanAttribute(String key, long value); | ||
|
||
/** | ||
* Adds double attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addSpanAttribute(String key, double value); | ||
|
||
/** | ||
* Adds boolean attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addSpanAttribute(String key, boolean value); | ||
|
||
/** | ||
* Adds an event to the {@link Span}. | ||
* | ||
* @param event event name | ||
*/ | ||
void addSpanEvent(String event); | ||
|
||
/** | ||
* Records error in the span | ||
* | ||
* @param exception exception to be recorded | ||
*/ | ||
void setError(Exception exception); | ||
|
||
/** | ||
* closes the scope | ||
*/ | ||
@Override | ||
void close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpanScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.noop; | ||
|
||
import org.opensearch.telemetry.tracing.SpanScope; | ||
|
||
/** | ||
* No-op implementation of SpanScope | ||
*/ | ||
public final class NoopSpanScope implements SpanScope { | ||
|
||
/** | ||
* No-args constructor | ||
*/ | ||
public NoopSpanScope() {} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, String value) { | ||
|
||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, long value) { | ||
|
||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, double value) { | ||
|
||
} | ||
|
||
@Override | ||
public void addSpanAttribute(String key, boolean value) { | ||
|
||
} | ||
|
||
@Override | ||
public void addSpanEvent(String event) { | ||
|
||
} | ||
|
||
@Override | ||
public void setError(Exception exception) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
} |
Oops, something went wrong.