|
54 | 54 | #include "opentelemetry/trace/trace_state.h"
|
55 | 55 | #include "opentelemetry/trace/tracer.h"
|
56 | 56 |
|
| 57 | +#include <src/trace/span.h> |
| 58 | + |
57 | 59 | using namespace opentelemetry::sdk::trace;
|
58 | 60 | using namespace opentelemetry::sdk::resource;
|
| 61 | +using namespace opentelemetry::sdk::instrumentationscope; |
59 | 62 | using opentelemetry::common::SteadyTimestamp;
|
60 | 63 | using opentelemetry::common::SystemTimestamp;
|
61 | 64 | namespace nostd = opentelemetry::nostd;
|
@@ -142,15 +145,18 @@ std::shared_ptr<opentelemetry::trace::Tracer> initTracer(
|
142 | 145 | std::unique_ptr<SpanExporter> &&exporter,
|
143 | 146 | // For testing, just shove a pointer over, we'll take it over.
|
144 | 147 | Sampler *sampler,
|
145 |
| - IdGenerator *id_generator = new RandomIdGenerator) |
| 148 | + IdGenerator *id_generator = new RandomIdGenerator, |
| 149 | + const ScopeConfigurator<TracerConfig> &tracer_configurator = |
| 150 | + TracerConfig::DefaultConfigurator()) |
146 | 151 | {
|
147 | 152 | auto processor = std::unique_ptr<SpanProcessor>(new SimpleSpanProcessor(std::move(exporter)));
|
148 | 153 | std::vector<std::unique_ptr<SpanProcessor>> processors;
|
149 | 154 | processors.push_back(std::move(processor));
|
150 | 155 | auto resource = Resource::Create({});
|
151 |
| - auto context = std::make_shared<TracerContext>(std::move(processors), resource, |
152 |
| - std::unique_ptr<Sampler>(sampler), |
153 |
| - std::unique_ptr<IdGenerator>(id_generator)); |
| 156 | + auto context = std::make_shared<TracerContext>( |
| 157 | + std::move(processors), resource, std::unique_ptr<Sampler>(sampler), |
| 158 | + std::unique_ptr<IdGenerator>(id_generator), |
| 159 | + std::make_unique<ScopeConfigurator<TracerConfig>>(tracer_configurator)); |
154 | 160 | return std::shared_ptr<opentelemetry::trace::Tracer>(new Tracer(context));
|
155 | 161 | }
|
156 | 162 |
|
@@ -488,6 +494,45 @@ TEST(Tracer, SpanSetEvents)
|
488 | 494 | ASSERT_EQ(1, span_data_events[2].GetAttributes().size());
|
489 | 495 | }
|
490 | 496 |
|
| 497 | +TEST(Tracer, StartSpanWithDisabledConfig) |
| 498 | +{ |
| 499 | +#ifdef OPENTELEMETRY_RTTI_ENABLED |
| 500 | + InMemorySpanExporter *exporter = new InMemorySpanExporter(); |
| 501 | + std::shared_ptr<InMemorySpanData> span_data = exporter->GetData(); |
| 502 | + ScopeConfigurator<TracerConfig> disable_tracer = [](const InstrumentationScope &) { |
| 503 | + return TracerConfig::Disabled(); |
| 504 | + }; |
| 505 | + auto tracer = initTracer(std::unique_ptr<SpanExporter>{exporter}, new AlwaysOnSampler(), |
| 506 | + new RandomIdGenerator(), disable_tracer); |
| 507 | + auto span = tracer->StartSpan("span 1"); |
| 508 | + auto &span_ref = *span.get(); |
| 509 | + |
| 510 | + EXPECT_NE(typeid(span_ref), typeid(trace_api::Span)); |
| 511 | + EXPECT_EQ(typeid(span_ref), typeid(trace_api::NoopSpan)); |
| 512 | +#else |
| 513 | + GTEST_SKIP() << "cannot use 'typeid' with '-fno-rtti'"; |
| 514 | +#endif |
| 515 | +} |
| 516 | + |
| 517 | +TEST(Tracer, StartSpanWithEnabledConfig) |
| 518 | +{ |
| 519 | +#ifdef OPENTELEMETRY_RTTI_ENABLED |
| 520 | + InMemorySpanExporter *exporter = new InMemorySpanExporter(); |
| 521 | + std::shared_ptr<InMemorySpanData> span_data = exporter->GetData(); |
| 522 | + ScopeConfigurator<TracerConfig> enable_tracer = [](const InstrumentationScope &) { |
| 523 | + return TracerConfig::Enabled(); |
| 524 | + }; |
| 525 | + auto tracer = initTracer(std::unique_ptr<SpanExporter>{exporter}, new AlwaysOnSampler(), |
| 526 | + new RandomIdGenerator(), enable_tracer); |
| 527 | + auto span = tracer->StartSpan("span 1"); |
| 528 | + auto &span_ref = *span.get(); |
| 529 | + |
| 530 | + EXPECT_EQ(typeid(span_ref), typeid(Span)); |
| 531 | +#else |
| 532 | + GTEST_SKIP() << "cannot use 'typeid' with '-fno-rtti'"; |
| 533 | +#endif |
| 534 | +} |
| 535 | + |
491 | 536 | TEST(Tracer, SpanSetLinks)
|
492 | 537 | {
|
493 | 538 | InMemorySpanExporter *exporter = new InMemorySpanExporter();
|
|
0 commit comments