|
18 | 18 | #include "opentelemetry/sdk/trace/sampler.h" |
19 | 19 | #include "opentelemetry/sdk/trace/samplers/always_off.h" |
20 | 20 | #include "opentelemetry/sdk/trace/simple_processor.h" |
| 21 | +#include "opentelemetry/sdk/trace/multi_span_processor.h" |
21 | 22 | #include "opentelemetry/sdk/trace/simple_processor_factory.h" |
22 | 23 | #include "opentelemetry/sdk/trace/tracer.h" |
23 | 24 | #include "opentelemetry/sdk/trace/tracer_context.h" |
@@ -318,6 +319,72 @@ TEST(TracerProvider, GetTracerAbiv2) |
318 | 319 | } |
319 | 320 | #endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ |
320 | 321 |
|
| 322 | +// get the same processor back, not wrapped in a MultiSpanProcessor |
| 323 | +TEST(TracerProvider, GetProcessor) |
| 324 | +{ |
| 325 | + std::unique_ptr<SpanProcessor> processor(new SimpleSpanProcessor(nullptr)); |
| 326 | + std::vector<std::unique_ptr<SpanProcessor>> processors; |
| 327 | + processors.push_back(std::move(processor)); |
| 328 | + |
| 329 | + std::unique_ptr<TracerContext> context1(new TracerContext(std::move(processors))); |
| 330 | + |
| 331 | + auto & span_processor = context1->GetProcessor(); |
| 332 | + |
| 333 | + // Should be the SimpleSpanProcessor processor that was created above. |
| 334 | +#ifdef OPENTELEMETRY_RTTI_ENABLED |
| 335 | + auto processor_typeed = dynamic_cast<SimpleSpanProcessor *>(&span_processor); |
| 336 | +#else |
| 337 | + auto processor_typeed = static_cast<SimpleSpanProcessor *>(&span_processor); |
| 338 | +#endif |
| 339 | + ASSERT_NE(nullptr, processor_typeed); |
| 340 | +} |
| 341 | + |
| 342 | +// get a MultiSpanProcessor back that wraps both processors |
| 343 | +TEST(TracerProvider, GetProcessorsTwo) |
| 344 | +{ |
| 345 | + std::unique_ptr<SpanProcessor> processor1(new SimpleSpanProcessor(nullptr)); |
| 346 | + std::unique_ptr<SpanProcessor> processor2(new SimpleSpanProcessor(nullptr)); |
| 347 | + std::vector<std::unique_ptr<SpanProcessor>> processors; |
| 348 | + processors.push_back(std::move(processor1)); |
| 349 | + processors.push_back(std::move(processor2)); |
| 350 | + |
| 351 | + std::unique_ptr<TracerContext> context1(new TracerContext(std::move(processors))); |
| 352 | + |
| 353 | + auto & span_processor = context1->GetProcessor(); |
| 354 | + |
| 355 | + // Should be the SimpleSpanProcessor processor that was created above. |
| 356 | +#ifdef OPENTELEMETRY_RTTI_ENABLED |
| 357 | + auto processor_typeed = dynamic_cast<MultiSpanProcessor *>(&span_processor); |
| 358 | +#else |
| 359 | + auto processor_typeed = static_cast<MultiSpanProcessor *>(&span_processor); |
| 360 | +#endif |
| 361 | + ASSERT_NE(nullptr, processor_typeed); |
| 362 | +} |
| 363 | + |
| 364 | +// get a MultiSpanProcessor back that wraps all three processors |
| 365 | +TEST(TracerProvider, GetProcessorsThree) |
| 366 | +{ |
| 367 | + std::unique_ptr<SpanProcessor> processor1(new SimpleSpanProcessor(nullptr)); |
| 368 | + std::unique_ptr<SpanProcessor> processor2(new SimpleSpanProcessor(nullptr)); |
| 369 | + std::unique_ptr<SpanProcessor> processor3(new SimpleSpanProcessor(nullptr)); |
| 370 | + std::vector<std::unique_ptr<SpanProcessor>> processors; |
| 371 | + processors.push_back(std::move(processor1)); |
| 372 | + processors.push_back(std::move(processor2)); |
| 373 | + processors.push_back(std::move(processor3)); |
| 374 | + |
| 375 | + std::unique_ptr<TracerContext> context1(new TracerContext(std::move(processors))); |
| 376 | + |
| 377 | + auto & span_processor = context1->GetProcessor(); |
| 378 | + |
| 379 | + // Should be the SimpleSpanProcessor processor that was created above. |
| 380 | +#ifdef OPENTELEMETRY_RTTI_ENABLED |
| 381 | + auto processor_typeed = dynamic_cast<MultiSpanProcessor *>(&span_processor); |
| 382 | +#else |
| 383 | + auto processor_typeed = static_cast<MultiSpanProcessor *>(&span_processor); |
| 384 | +#endif |
| 385 | + ASSERT_NE(nullptr, processor_typeed); |
| 386 | +} |
| 387 | + |
321 | 388 | TEST(TracerProvider, Shutdown) |
322 | 389 | { |
323 | 390 | std::unique_ptr<SpanProcessor> processor(new SimpleSpanProcessor(nullptr)); |
|
0 commit comments