Line data Source code
1 : #pragma once 2 : 3 : #include <map> 4 : #include <memory> 5 : #include <string> 6 : 7 : #include "envoy/config/typed_config.h" 8 : #include "envoy/server/tracer_config.h" 9 : 10 : namespace Envoy { 11 : namespace Extensions { 12 : namespace Tracers { 13 : namespace OpenTelemetry { 14 : 15 : /** 16 : * @brief A string key-value map that stores the resource attributes. 17 : */ 18 : using ResourceAttributes = std::map<std::string, std::string>; 19 : 20 : /** 21 : * @brief A Resource represents the entity producing telemetry as Attributes. 22 : * For example, a process producing telemetry that is running in a container on Kubernetes 23 : * has a Pod name, it is in a namespace and possibly is part of a Deployment which also has a name. 24 : * See: 25 : * https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/resource/sdk.md 26 : */ 27 : struct Resource { 28 : std::string schema_url_{""}; 29 : ResourceAttributes attributes_{}; 30 : 31 0 : virtual ~Resource() = default; 32 : }; 33 : 34 : using ResourceConstSharedPtr = std::shared_ptr<const Resource>; 35 : 36 : /** 37 : * @brief The base type for all resource detectors 38 : * 39 : */ 40 : class ResourceDetector { 41 : public: 42 0 : virtual ~ResourceDetector() = default; 43 : 44 : /** 45 : * @brief Load attributes and returns a Resource object 46 : * populated with them and a possible SchemaUrl. 47 : * @return Resource 48 : */ 49 : virtual Resource detect() PURE; 50 : }; 51 : 52 : using ResourceDetectorPtr = std::unique_ptr<ResourceDetector>; 53 : 54 : /* 55 : * A factory for creating resource detectors. 56 : */ 57 : class ResourceDetectorFactory : public Envoy::Config::TypedFactory { 58 : public: 59 0 : ~ResourceDetectorFactory() override = default; 60 : 61 : /** 62 : * @brief Creates a resource detector based on the configuration type provided. 63 : * 64 : * @param message The resource detector configuration. 65 : * @param context The tracer factory context. 66 : * @return ResourceDetectorPtr A resource detector based on the configuration type provided. 67 : */ 68 : virtual ResourceDetectorPtr 69 : createResourceDetector(const Protobuf::Message& message, 70 : Server::Configuration::TracerFactoryContext& context) PURE; 71 : 72 6 : std::string category() const override { return "envoy.tracers.opentelemetry.resource_detectors"; } 73 : }; 74 : 75 : using ResourceDetectorTypedFactoryPtr = std::unique_ptr<ResourceDetectorFactory>; 76 : 77 : } // namespace OpenTelemetry 78 : } // namespace Tracers 79 : } // namespace Extensions 80 : } // namespace Envoy