-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tracer to create new TracerContextStorage
Signed-off-by: Gagan Juneja <gjjuneja@amazon.com>
- Loading branch information
Gagan Juneja
committed
Jul 23, 2023
1 parent
7769682
commit b6f0917
Showing
8 changed files
with
104 additions
and
0 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
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
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
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
63 changes: 63 additions & 0 deletions
63
server/src/test/java/org/opensearch/telemetry/tracing/TracerTests.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,63 @@ | ||
/* | ||
* 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.ArrayList; | ||
import java.util.List; | ||
import org.opensearch.common.lease.Releasable; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.concurrent.ThreadContext; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.test.telemetry.tracing.MockTracingTelemetry; | ||
|
||
public class TracerTests extends OpenSearchTestCase { | ||
|
||
private final ThreadContextBasedTracerContextStorage contextStorage = new ThreadContextBasedTracerContextStorage( | ||
new ThreadContext(Settings.EMPTY), | ||
new MockTracingTelemetry() | ||
); | ||
|
||
public void testIterationScenarioFail() throws Exception { | ||
List<SpanScope> spansToBeClosed = new ArrayList<>(); | ||
DefaultTracer defaultTracer = new DefaultTracer(new MockTracingTelemetry(), contextStorage); | ||
try (SpanScope parentSpanScope = defaultTracer.startSpan("parentSpan")) { | ||
Span parentSpan = defaultTracer.getCurrentSpan(); | ||
Span newWrongParent = null; | ||
for (int i = 0; i < 3; i++) { | ||
String spanName = "childSpan_" + i; | ||
SpanScope child = defaultTracer.startSpan(spanName); | ||
spansToBeClosed.add(child); | ||
if (i == 0) { | ||
assertEquals(parentSpan, defaultTracer.getCurrentSpan().getParentSpan()); | ||
} else { | ||
assertEquals(newWrongParent, defaultTracer.getCurrentSpan().getParentSpan()); | ||
} | ||
newWrongParent = defaultTracer.getCurrentSpan(); | ||
} | ||
} | ||
spansToBeClosed.forEach(a -> a.close()); | ||
} | ||
|
||
public void testIterationScenarioSuccess() throws Exception { | ||
List<SpanScope> spansToBeClosed = new ArrayList<>(); | ||
DefaultTracer defaultTracer = new DefaultTracer(new MockTracingTelemetry(), contextStorage); | ||
try (SpanScope parentSpanScope = defaultTracer.startSpan("parentSpan")) { | ||
Span parentSpan = defaultTracer.getCurrentSpan(); | ||
for (int i = 0; i < 3; i++) { | ||
String spanName = "childSpan_" + i; | ||
try (Releasable releasable = contextStorage.newTracerContextStorage()) { | ||
SpanScope child = defaultTracer.startSpan(spanName); | ||
spansToBeClosed.add(child); | ||
assertEquals(parentSpan, defaultTracer.getCurrentSpan().getParentSpan()); | ||
} | ||
} | ||
} | ||
spansToBeClosed.forEach(a -> a.close()); | ||
} | ||
} |