Package org.apache.hadoop.hbase.trace
Class OpenTelemetryClassRule
java.lang.Object
org.junit.rules.ExternalResource
org.apache.hadoop.hbase.trace.OpenTelemetryClassRule
- All Implemented Interfaces:
org.junit.rules.TestRule
Like OpenTelemetryRule
, except modeled after the junit5 implementation
OpenTelemetryExtension
. Use this class when you need to make asserts on SpanData
created on a MiniCluster. Make sure this rule initialized before the MiniCluster so that it can
register its instance of OpenTelemetry
as the global instance before any server-side
component can call TraceUtil.getGlobalTracer()
.
For example:
{ @code public class TestMyClass { private static final OpenTelemetryClassRule otelClassRule = OpenTelemetryClassRule.create(); private static final MiniClusterRule miniClusterRule = MiniClusterRule.newBuilder().build(); protected static final ConnectionRule connectionRule = ConnectionRule.createAsyncConnectionRule(miniClusterRule::createAsyncConnection); @ClassRule public static final TestRule classRule = RuleChain.outerRule(otelClassRule).around(miniClusterRule).around(connectionRule); @Rule public final OpenTelemetryTestRule otelTestRule = new OpenTelemetryTestRule(otelClassRule); @Test public void myTest() { // ... // do something that makes spans final Listspans = otelClassRule.getSpans(); // make assertions on them } } }
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate final io.opentelemetry.sdk.OpenTelemetrySdk
private final io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter
-
Constructor Summary
ModifierConstructorDescriptionprivate
OpenTelemetryClassRule
(io.opentelemetry.sdk.OpenTelemetrySdk openTelemetry, io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter spanExporter) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
after()
protected void
before()
void
Clears the collected exportedSpanData
.static OpenTelemetryClassRule
create()
io.opentelemetry.api.OpenTelemetry
Returns theOpenTelemetry
created by this Rule.List<io.opentelemetry.sdk.trace.data.SpanData>
getSpans()
Returns all the exportedSpanData
so far.Methods inherited from class org.junit.rules.ExternalResource
apply
-
Field Details
-
openTelemetry
-
spanExporter
-
-
Constructor Details
-
OpenTelemetryClassRule
private OpenTelemetryClassRule(io.opentelemetry.sdk.OpenTelemetrySdk openTelemetry, io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter spanExporter)
-
-
Method Details
-
create
-
getOpenTelemetry
Returns theOpenTelemetry
created by this Rule. -
getSpans
Returns all the exportedSpanData
so far. -
clearSpans
Clears the collected exportedSpanData
. -
before
- Overrides:
before
in classorg.junit.rules.ExternalResource
- Throws:
Throwable
-
after
- Overrides:
after
in classorg.junit.rules.ExternalResource
-