| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| #ifndef THIRD_PARTY_CREDENTIO_TRACING_NOOP_TRACING_H_ | |
| #define THIRD_PARTY_CREDENTIO_TRACING_NOOP_TRACING_H_ | |
| #include <memory> | |
| #include "absl/base/nullability.h" | |
| #include "absl/status/status.h" | |
| #include "absl/strings/string_view.h" | |
| #include "tracing/span.h" | |
| #include "tracing/tracer.h" | |
| #include "tracing/tracer_factory.h" | |
| namespace credentio_tracing { | |
| // No-op implementation of Span that discards all recorded operations and | |
| // attributes. | |
| class NoopSpan : public Span { | |
| public: | |
| // Discards the attribute key-value pair. | |
| void SetAttribute(absl::string_view, AttributeValue) override {} | |
| // Discards the point-in-time event. | |
| void AddEvent(absl::string_view) override {} | |
| // Discards the status code update. | |
| void SetStatus(const absl::Status&) override {} | |
| // Discards span completion. | |
| void End() override {} | |
| }; | |
| // No-op implementation of Tracer that creates NoopSpan instances with sub-5ns | |
| // overhead. | |
| class NoopTracer : public Tracer { | |
| public: | |
| using Tracer::StartSpan; | |
| // Returns a new NoopSpan instance. | |
| std::unique_ptr<Span> StartSpanImpl( | |
| absl::string_view span_name, | |
| const StartSpanOptions& options) const override; | |
| }; | |
| // No-op implementation of TracerFactory that returns shared NoopTracer | |
| // instances. | |
| class NoopTracerFactory : public TracerFactory { | |
| public: | |
| // Returns a thread-safe singleton NoopTracer instance. | |
| absl_nonnull std::shared_ptr<Tracer> GetTracer( | |
| absl::string_view) const override; | |
| }; | |
| } // namespace credentio_tracing | |
| #endif // THIRD_PARTY_CREDENTIO_TRACING_NOOP_TRACING_H_ |