Skip to content

Commit f2764cb

Browse files
committed
wip: add api method to check if tracer is enabled
1 parent 2c55339 commit f2764cb

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

api/include/opentelemetry/trace/noop.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class OPENTELEMETRY_EXPORT NoopTracer final : public Tracer,
108108
return noop_span;
109109
}
110110

111+
bool IsEnabled() const noexcept override {
112+
return false;
113+
}
114+
111115
#if OPENTELEMETRY_ABI_VERSION_NO == 1
112116

113117
void ForceFlushWithMicroseconds(uint64_t /*timeout*/) noexcept override {}

api/include/opentelemetry/trace/tracer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ class Tracer
137137
options);
138138
}
139139

140+
/**
141+
* Returns a boolean indicating if the tracer is enabled or not. Disabled tracers behave like
142+
* no-op tracers. By default, tracers are considered enabled.
143+
* @return true if the tracer is enabled, false otherwise.
144+
*/
145+
virtual bool IsEnabled() const noexcept = 0;
146+
140147
/**
141148
* Set the active span. The span will remain active until the returned Scope
142149
* object is destroyed.

sdk/include/opentelemetry/sdk/trace/tracer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class Tracer final : public opentelemetry::trace::Tracer,
9696
return GetInstrumentationScope();
9797
}
9898

99+
bool IsEnabled() const noexcept override {
100+
return tracer_config_->IsEnabled();
101+
}
102+
99103
/** Returns the currently configured resource **/
100104
const opentelemetry::sdk::resource::Resource &GetResource() { return context_->GetResource(); }
101105

0 commit comments

Comments
 (0)