aboutsummaryrefslogtreecommitdiff
path: root/src/zentelemetry/otelprotozero.h
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-22 17:57:29 +0200
committerGitHub Enterprise <[email protected]>2025-10-22 17:57:29 +0200
commit5c139e2d8a260544bc5e730de0440edbab4b0f03 (patch)
treeb477208925fe3b373d4833460b90d61a8051cf05 /src/zentelemetry/otelprotozero.h
parent5.7.7-pre3 (diff)
downloadzen-5c139e2d8a260544bc5e730de0440edbab4b0f03.tar.xz
zen-5c139e2d8a260544bc5e730de0440edbab4b0f03.zip
add support for OTLP logging/tracing (#599)
- adds `zentelemetry` project which houses new functionality for serializing logs and traces in OpenTelemetry Protocol format (OTLP) - moved existing stats functionality from `zencore` to `zentelemetry` - adds `TRefCounted<T>` for vtable-less refcounting - adds `MemoryArena` class which allows for linear allocation of memory from chunks - adds `protozero` which is used to encode OTLP protobuf messages
Diffstat (limited to 'src/zentelemetry/otelprotozero.h')
-rw-r--r--src/zentelemetry/otelprotozero.h166
1 files changed, 166 insertions, 0 deletions
diff --git a/src/zentelemetry/otelprotozero.h b/src/zentelemetry/otelprotozero.h
new file mode 100644
index 000000000..8ad69e766
--- /dev/null
+++ b/src/zentelemetry/otelprotozero.h
@@ -0,0 +1,166 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <protozero/types.hpp>
+
+//////////////////////////////////////////////////////////////////////////
+//
+// OTEL .proto definitions, for reference
+//
+
+#if 0
+
+// clang-format off
+
+////////////////////////////////////////////////////////////////////////
+// resource/v1/resource.proto
+//
+
+// Resource information.
+message Resource {
+ // Set of attributes that describe the resource.
+ // Attribute keys MUST be unique (it is not allowed to have more than one
+ // attribute with the same key).
+ //
+ // The attribute values SHOULD NOT contain empty values.
+ // The attribute values SHOULD NOT contain bytes values.
+ // The attribute values SHOULD NOT contain array values different than array of string values, bool values, int values,
+ // double values.
+ // The attribute values SHOULD NOT contain kvlist values.
+ // The behavior of software that receives attributes containing such values can be unpredictable.
+ // These restrictions can change in a minor release.
+ // The restrictions take origin from the OpenTelemetry specification:
+ // https://github.com/open-telemetry/opentelemetry-specification/blob/v1.47.0/specification/common/README.md#attribute.
+ repeated opentelemetry.proto.common.v1.KeyValue attributes = 1;
+
+ // The number of dropped attributes. If the value is 0, then
+ // no attributes were dropped.
+ uint32 dropped_attributes_count = 2;
+
+ // Set of entities that participate in this Resource.
+ //
+ // Note: keys in the references MUST exist in attributes of this message.
+ //
+ // Status: [Development]
+ repeated opentelemetry.proto.common.v1.EntityRef entity_refs = 3;
+}
+
+/////////////////////////////////////////////////////////////////////////
+// common/v1/commmon.proto
+//
+
+// Represents any type of attribute value. AnyValue may contain a
+// primitive value such as a string or integer or it may contain an arbitrary nested
+// object containing arrays, key-value lists and primitives.
+message AnyValue {
+ // The value is one of the listed fields. It is valid for all values to be unspecified
+ // in which case this AnyValue is considered to be "empty".
+ oneof value {
+ string string_value = 1;
+ bool bool_value = 2;
+ int64 int_value = 3;
+ double double_value = 4;
+ ArrayValue array_value = 5;
+ KeyValueList kvlist_value = 6;
+ bytes bytes_value = 7;
+ }
+}
+
+// ArrayValue is a list of AnyValue messages. We need ArrayValue as a message
+// since oneof in AnyValue does not allow repeated fields.
+message ArrayValue {
+ // Array of values. The array may be empty (contain 0 elements).
+ repeated AnyValue values = 1;
+}
+
+// KeyValueList is a list of KeyValue messages. We need KeyValueList as a message
+// since `oneof` in AnyValue does not allow repeated fields. Everywhere else where we need
+// a list of KeyValue messages (e.g. in Span) we use `repeated KeyValue` directly to
+// avoid unnecessary extra wrapping (which slows down the protocol). The 2 approaches
+// are semantically equivalent.
+message KeyValueList {
+ // A collection of key/value pairs of key-value pairs. The list may be empty (may
+ // contain 0 elements).
+ // The keys MUST be unique (it is not allowed to have more than one
+ // value with the same key).
+ repeated KeyValue values = 1;
+}
+
+// Represents a key-value pair that is used to store Span attributes, Link
+// attributes, etc.
+message KeyValue {
+ // The key name of the pair.
+ string key = 1;
+
+ // The value of the pair.
+ AnyValue value = 2;
+}
+
+// InstrumentationScope is a message representing the instrumentation scope information
+// such as the fully qualified name and version.
+message InstrumentationScope {
+ // A name denoting the Instrumentation scope.
+ // An empty instrumentation scope name means the name is unknown.
+ string name = 1;
+
+ // Defines the version of the instrumentation scope.
+ // An empty instrumentation scope version means the version is unknown.
+ string version = 2;
+
+ // Additional attributes that describe the scope. [Optional].
+ // Attribute keys MUST be unique (it is not allowed to have more than one
+ // attribute with the same key).
+ repeated KeyValue attributes = 3;
+
+ // The number of attributes that were discarded. Attributes
+ // can be discarded because their keys are too long or because there are too many
+ // attributes. If this value is 0, then no attributes were dropped.
+ uint32 dropped_attributes_count = 4;
+}
+
+// clang-format on
+#endif
+
+//////////////////////////////////////////////////////////////////////////
+
+namespace zen::otel {
+
+enum class KeyValueList : protozero::pbf_tag_type
+{
+ repeated_KeyValue_values = 1
+};
+
+enum class KeyValue : protozero::pbf_tag_type
+{
+ string_key = 1,
+ AnyValue_value = 2
+};
+
+enum class Resource : protozero::pbf_tag_type
+{
+ repeated_KeyValue_attributes = 1,
+ uint32_dropped_attributes_count = 2,
+ repeated_EntityRef_entity_refs = 3
+};
+
+enum class AnyValue : protozero::pbf_tag_type
+{
+ string_string_value = 1,
+ bool_bool_value = 2,
+ int64_int_value = 3,
+ double_double_value = 4,
+ ArrayValue_array_value = 5,
+ KeyValueList_kvlist_value = 6,
+ bytes_bytes_value = 7
+};
+
+enum class InstrumentationScope : protozero::pbf_tag_type
+{
+ string_name = 1,
+ string_version = 2,
+ repeated_KeyValue_attributes = 3,
+ uint32_dropped_attributes_count = 4
+};
+
+} // namespace zen::otel