diff options
| author | Stefan Boberg <[email protected]> | 2025-12-11 16:12:02 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-12-11 16:12:02 +0100 |
| commit | 567293ab1baa8cb0eca843977c520e5b8f400b4d (patch) | |
| tree | 1f54f12d3fb19b91695bbfea33fa9abd8de49f69 /src/zentelemetry/include | |
| parent | 5.7.14 (diff) | |
| download | zen-567293ab1baa8cb0eca843977c520e5b8f400b4d.tar.xz zen-567293ab1baa8cb0eca843977c520e5b8f400b4d.zip | |
add otel instrumentation (#581)
this change adds OTEL tracing to a few places
* Top-level application lifecycle (config/init/cleanup, main loop)
* http.sys requests
it also brings some otlptrace optimizations and dynamic configuration of tracing. OTLP tracing is currently always disabled
Diffstat (limited to 'src/zentelemetry/include')
| -rw-r--r-- | src/zentelemetry/include/zentelemetry/otlptrace.h | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/zentelemetry/include/zentelemetry/otlptrace.h b/src/zentelemetry/include/zentelemetry/otlptrace.h index ebecff91a..f191241ed 100644 --- a/src/zentelemetry/include/zentelemetry/otlptrace.h +++ b/src/zentelemetry/include/zentelemetry/otlptrace.h @@ -3,6 +3,7 @@ #pragma once #include <zenbase/refcount.h> +#include <zencore/memcmp.h> #include <zencore/uid.h> #include <span> @@ -30,8 +31,6 @@ using AttributeList = std::span<std::pair<std::string, std::string>>; class Tracer; -Tracer& GetTracer(); - // OLTP Span ID struct SpanId @@ -42,8 +41,16 @@ struct SpanId explicit SpanId(const std::span<const uint8_t, 8> Bytes) noexcept { std::copy(Bytes.begin(), Bytes.end(), Id); } explicit SpanId(const Oid& InId) noexcept { memcpy(Id, reinterpret_cast<const uint8_t*>(InId.OidBits), sizeof Id); } - auto operator<=>(const SpanId& Rhs) const = default; - inline operator bool() const { return *this != SpanId(); } + std::strong_ordering operator<=>(const SpanId& Rhs) const noexcept + { + int cmp = MemCmpFixed<kSize>(Id, Rhs.Id); + if (cmp < 0) + return std::strong_ordering::less; + if (cmp > 0) + return std::strong_ordering::greater; + return std::strong_ordering::equal; + } + inline operator bool() const { return *reinterpret_cast<const uint64_t*>(Id) != 0; } static SpanId NewSpanId(); @@ -64,8 +71,19 @@ struct TraceId inline TraceId() noexcept : Id{0} {} explicit TraceId(const std::span<const uint8_t, kSize> Bytes) noexcept { std::copy(Bytes.begin(), Bytes.end(), Id); } - auto operator<=>(const TraceId& Rhs) const = default; - inline operator bool() const { return *this != TraceId(); } + std::strong_ordering operator<=>(const TraceId& Rhs) const noexcept + { + int cmp = MemCmpFixed<kSize>(Id, Rhs.Id); + if (cmp < 0) + return std::strong_ordering::less; + if (cmp > 0) + return std::strong_ordering::greater; + return std::strong_ordering::equal; + } + inline operator bool() const + { + return !(reinterpret_cast<const uint64_t*>(Id)[0] == 0 && reinterpret_cast<const uint64_t*>(Id)[1] == 0); + } static TraceId NewTraceId(); @@ -194,7 +212,6 @@ private: uint64_t m_StartTime = 0; uint64_t m_EndTime = 0; Kind m_Kind = Kind::kInternal; - bool m_Ended = false; Span(MemoryArena& Arena, std::string_view Name, Span* SpanChain); ~Span(); @@ -209,6 +226,13 @@ class ScopedSpan final { public: ScopedSpan(std::string_view Name); + ScopedSpan(std::string_view Name, std::invocable<Span&> auto&& InitializerFunction) : ScopedSpan(Name) + { + if (m_Span) + { + InitializerFunction(*m_Span); + } + } ScopedSpan() = delete; ~ScopedSpan(); @@ -217,7 +241,8 @@ public: ScopedSpan(ScopedSpan&& Rhs) = default; ScopedSpan(const ScopedSpan& Rhs) = default; - Span* operator->() const { return m_Span.Get(); } + operator bool() const { return !!m_Span; } + void WithSpan(auto Func) const { Func(*m_Span); } private: ScopedSpan(Span* InSpan, Tracer* InTracer); |