-
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.
Merge branch '2.x' into backport-9622-to-2.x
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
- Loading branch information
Showing
61 changed files
with
2,412 additions
and
324 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
89 changes: 89 additions & 0 deletions
89
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultScopedSpan.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,89 @@ | ||
/* | ||
* 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.Objects; | ||
|
||
/** | ||
* Default implementation of Scope | ||
* | ||
* @opensearch.internal | ||
*/ | ||
final class DefaultScopedSpan implements ScopedSpan { | ||
|
||
private final Span span; | ||
|
||
private final SpanScope spanScope; | ||
|
||
/** | ||
* Creates Scope instance for the given span | ||
* | ||
* @param span underlying span | ||
* @param spanScope span scope. | ||
*/ | ||
public DefaultScopedSpan(Span span, SpanScope spanScope) { | ||
this.span = Objects.requireNonNull(span); | ||
this.spanScope = Objects.requireNonNull(spanScope); | ||
} | ||
|
||
@Override | ||
public void addAttribute(String key, String value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addAttribute(String key, long value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addAttribute(String key, double value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addAttribute(String key, boolean value) { | ||
span.addAttribute(key, value); | ||
} | ||
|
||
@Override | ||
public void addEvent(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() { | ||
span.endSpan(); | ||
spanScope.close(); | ||
} | ||
|
||
/** | ||
* Returns span. | ||
* @return | ||
*/ | ||
Span getSpan() { | ||
return span; | ||
} | ||
|
||
/** | ||
* Returns {@link SpanScope} | ||
* @return spanScope | ||
*/ | ||
SpanScope getSpanScope() { | ||
return spanScope; | ||
} | ||
} |
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
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/ScopedSpan.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.NoopScopedSpan; | ||
|
||
/** | ||
* An auto-closeable that represents scoped span. | ||
* It provides interface for all the span operations. | ||
*/ | ||
public interface ScopedSpan extends AutoCloseable { | ||
/** | ||
* No-op Scope implementation | ||
*/ | ||
ScopedSpan NO_OP = new NoopScopedSpan(); | ||
|
||
/** | ||
* Adds string attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addAttribute(String key, String value); | ||
|
||
/** | ||
* Adds long attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addAttribute(String key, long value); | ||
|
||
/** | ||
* Adds double attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addAttribute(String key, double value); | ||
|
||
/** | ||
* Adds boolean attribute to the {@link Span}. | ||
* | ||
* @param key attribute key | ||
* @param value attribute value | ||
*/ | ||
void addAttribute(String key, boolean value); | ||
|
||
/** | ||
* Adds an event to the {@link Span}. | ||
* | ||
* @param event event name | ||
*/ | ||
void addEvent(String event); | ||
|
||
/** | ||
* Records error in the span | ||
* | ||
* @param exception exception to be recorded | ||
*/ | ||
void setError(Exception exception); | ||
|
||
/** | ||
* closes the scope | ||
*/ | ||
@Override | ||
void close(); | ||
} |
Oops, something went wrong.