forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tracing Framework] Redefine telemetry context restoration and propag…
…ation (opensearch-project#9617) * Add SpanBuilder support Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Refactor code Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Redefine telemetry context restoration Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Update changelog Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Stores the SpanScope in ThreadLocal Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Revert the context name changes Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Change the span::endSpan and SpanScope::close behaviour Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Supressed warnings Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Add more test cases Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Address review comment Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Address review comment Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Fix java doc Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Address review comment Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Fix failing test Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Empty-Commit Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> * Empty-Commit Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> --------- Signed-off-by: Gagan Juneja <gjjuneja@amazon.com> Signed-off-by: Gagan Juneja <gagandeepjuneja@gmail.com> Co-authored-by: Gagan Juneja <gjjuneja@amazon.com> Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
- Loading branch information
1 parent
261eeaa
commit f40ef19
Showing
27 changed files
with
1,236 additions
and
232 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(); | ||
} |
45 changes: 45 additions & 0 deletions
45
libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanCreationContext.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,45 @@ | ||
/* | ||
* 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.attributes.Attributes; | ||
|
||
/** | ||
* Context for span details. | ||
*/ | ||
public final class SpanCreationContext { | ||
private final String spanName; | ||
private final Attributes attributes; | ||
|
||
/** | ||
* Constructor. | ||
* @param spanName span name. | ||
* @param attributes attributes. | ||
*/ | ||
public SpanCreationContext(String spanName, Attributes attributes) { | ||
this.spanName = spanName; | ||
this.attributes = attributes; | ||
} | ||
|
||
/** | ||
* Returns the span name. | ||
* @return span name | ||
*/ | ||
public String getSpanName() { | ||
return spanName; | ||
} | ||
|
||
/** | ||
* Returns the span attributes. | ||
* @return attributes. | ||
*/ | ||
public Attributes getAttributes() { | ||
return attributes; | ||
} | ||
} |
Oops, something went wrong.