How can I get the attributes of span? #3376
-
Hi, community~ In my unit test, I need to assert the attributes of span. But, how to get the attributes from the span troubles me a lot. More specifically: @Before
public void setup() {
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(ZipkinSpanExporter.builder().build()).build())
.build();
OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
.buildAndRegisterGlobal();
}
@Test
public void assertMethod() {
// execute method
// ...
Span span = Span.current();
// How can I get attributes here?
} Are there any APIs that can be used here? Or is there a better way to test? |
Beta Was this translation helpful? Give feedback.
Answered by
kenfinnigan
Jul 7, 2021
Replies: 1 comment 1 reply
-
I usually use the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
JooKS-me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I usually use the
InMemorySpanExporter
from https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk/testing to capture the traces/spans and then retrieve them from the exporter for verification of Span attributes, etc