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
@@ -229,6 +235,7 @@ TEST(Tracer, StartSpanSampleOff)
229
235
230
236
TEST (Tracer, StartSpanCustomIdGenerator)
231
237
{
238
+ #ifdef OPENTELEMETRY_RTTI_ENABLED
232
239
IdGenerator *id_generator = new MockIdGenerator ();
233
240
InMemorySpanExporter *exporter = new InMemorySpanExporter ();
234
241
std::shared_ptr<InMemorySpanData> span_data = exporter->GetData ();
@@ -241,10 +248,14 @@ TEST(Tracer, StartSpanCustomIdGenerator)
241
248
242
249
EXPECT_EQ (cur_span_data->GetTraceId (), id_generator->GenerateTraceId ());
243
250
EXPECT_EQ (cur_span_data->GetSpanId (), id_generator->GenerateSpanId ());
251
+ #else
252
+ GTEST_SKIP () << " cannot use 'typeid' with '-fno-rtti'"
253
+ #endif
244
254
}
245
255
246
256
TEST (Tracer, StartSpanWithOptionsTime)
247
257
{
258
+ #ifdef OPENTELEMETRY_RTTI_ENABLED
248
259
InMemorySpanExporter *exporter = new InMemorySpanExporter ();
249
260
std::shared_ptr<InMemorySpanData> span_data = exporter->GetData ();
250
261
auto tracer = initTracer (std::unique_ptr<SpanExporter>{exporter});
@@ -264,6 +275,9 @@ TEST(Tracer, StartSpanWithOptionsTime)
264
275
auto &cur_span_data = spans.at (0 );
265
276
ASSERT_EQ (std::chrono::nanoseconds (300 ), cur_span_data->GetStartTime ().time_since_epoch ());
266
277
ASSERT_EQ (std::chrono::nanoseconds (30 ), cur_span_data->GetDuration ());
278
+ #else
279
+ GTEST_SKIP () << " cannot use 'typeid' with '-fno-rtti'"
280
+ #endif
267
281
}
268
282
269
283
TEST (Tracer, StartSpanWithAttributes)
@@ -488,6 +502,37 @@ TEST(Tracer, SpanSetEvents)
488
502
ASSERT_EQ (1 , span_data_events[2 ].GetAttributes ().size ());
489
503
}
490
504
505
+ TEST (Tracer, StartSpanWithDisabledConfig)
506
+ {
507
+ InMemorySpanExporter *exporter = new InMemorySpanExporter ();
508
+ std::shared_ptr<InMemorySpanData> span_data = exporter->GetData ();
509
+ ScopeConfigurator<TracerConfig> disable_tracer = [](const InstrumentationScope &) {
510
+ return TracerConfig::Disabled ();
511
+ };
512
+ auto tracer = initTracer (std::unique_ptr<SpanExporter>{exporter}, new AlwaysOnSampler (),
513
+ new RandomIdGenerator (), disable_tracer);
514
+ auto span = tracer->StartSpan (" span 1" );
515
+ auto &span_ref = *span.get ();
516
+
517
+ EXPECT_NE (typeid (span_ref), typeid (trace_api::Span));
518
+ EXPECT_EQ (typeid (span_ref), typeid (trace_api::NoopSpan));
519
+ }
520
+
521
+ TEST (Tracer, StartSpanWithEnabledConfig)
522
+ {
523
+ InMemorySpanExporter *exporter = new InMemorySpanExporter ();
524
+ std::shared_ptr<InMemorySpanData> span_data = exporter->GetData ();
525
+ ScopeConfigurator<TracerConfig> enable_tracer = [](const InstrumentationScope &) {
526
+ return TracerConfig::Enabled ();
527
+ };
528
+ auto tracer = initTracer (std::unique_ptr<SpanExporter>{exporter}, new AlwaysOnSampler (),
529
+ new RandomIdGenerator (), enable_tracer);
530
+ auto span = tracer->StartSpan (" span 1" );
531
+ auto &span_ref = *span.get ();
532
+
533
+ EXPECT_EQ (typeid (span_ref), typeid (Span));
534
+ }
535
+
491
536
TEST (Tracer, SpanSetLinks)
492
537
{
493
538
InMemorySpanExporter *exporter = new InMemorySpanExporter ();
0 commit comments