Repository: conan-io/conan-center-index

Issue:
[package] opentelemetry-cpp/1.8 1: option to enable Logs support  with ENABLE_LOGS_PREVIEW
### Description

This is not a bug actually but a request to improvement for the current recipe because this library support this setting. 

The Logs feature in opentelemetry-cpp 1.8.1 is still experimental but can be enabled via the define ENABLE_LOGS_PREVIEW that is handled by CMake  ` WITH_LOGS_PREVIEW`.
 I would like to be able set this via an recipe option. 
This will allow us to enable this support in our `conanfile.txt` like this:

```
[requires]
opentelemetry-cpp/1.8.1

[generators]
cmake

[options]
opentelemetry-cpp:with_logs_preview=True
```
This option is required in order to build the includes and libs that support ostream, OTLP HTTP and gRPC exporters for logs especification.

Here is my proposal of PR for the package maintainer: 
https://github.com/MrSparc/conan-center-index/commit/88c94d0400f4ef2210bceb5949f9ba7ad504b7fc

### Package and Environment Details

* Package Name/Version: **opentelemetry-cpp/1.8.1**
* Operating System+version: **Linux Ubuntu 22.04**
* Compiler+version: **GCC 11.3**
* Conan version: **conan 1.53.0**

### Conan profile


N/A

### Steps to reproduce

N/A.

### Logs

N/A.



Discussion:

Resolving patch:
diff --git a/recipes/opentelemetry-cpp/all/conanfile.py b/recipes/opentelemetry-cpp/all/conanfile.py
--- a/recipes/opentelemetry-cpp/all/conanfile.py
+++ b/recipes/opentelemetry-cpp/all/conanfile.py
@@ -22,10 +22,12 @@ class OpenTelemetryCppConan(ConanFile):
     options = {
         "fPIC": [True, False],
         "shared": [True, False],
+        "with_logs_preview": [True, False],
     }
     default_options = {
         "fPIC": True,
         "shared": False,
+        "with_logs_preview": False,
     }
     short_paths = True
 
@@ -100,6 +102,8 @@ def generate(self):
         tc.variables["WITH_JAEGER"] = True
         tc.variables["WITH_OTLP"] = True
         tc.variables["WITH_ZIPKIN"] = True
+        if self.options.with_logs_preview:
+            tc.variables["WITH_LOGS_PREVIEW"] = True
         tc.generate()
 
         tc = CMakeDeps(self)
@@ -190,6 +194,14 @@ def _otel_libraries(self):
         if Version(self.version) >= "1.7.0":
             libraries.append("opentelemetry_exporter_otlp_grpc_client")
 
+        if self.options.with_logs_preview:
+            libraries.extend([
+                "opentelemetry_logs",
+                "opentelemetry_exporter_ostream_logs",
+                "opentelemetry_exporter_otlp_grpc_log",
+                "opentelemetry_exporter_otlp_http_log",
+            ])
+
         if self.settings.os == "Windows":
             libraries.extend([
                 "opentelemetry_exporter_etw",
@@ -304,5 +316,25 @@ def package_info(self):
             "opentelemetry_resources",
         ])
 
+        if self.options.with_logs_preview:
+            self.cpp_info.components["opentelemetry_logs"].requires.extend([
+                "opentelemetry_resources",
+                "opentelemetry_common",
+            ])
+
+            self.cpp_info.components["opentelemetry_exporter_ostream_logs"].requires.extend([
+                "opentelemetry_logs",
+            ])
+
+            self.cpp_info.components["opentelemetry_exporter_otlp_grpc_log"].requires.extend([
+                "opentelemetry_otlp_recordable",
+                "opentelemetry_exporter_otlp_grpc_client",
+            ])
+
+            self.cpp_info.components["opentelemetry_exporter_otlp_http_log"].requires.extend([
+                "opentelemetry_otlp_recordable",
+                "opentelemetry_exporter_otlp_http_client",
+            ])
+
         if self.settings.os in ("Linux", "FreeBSD"):
             self.cpp_info.components["opentelemetry_common"].system_libs.extend(["pthread"])


Test patch: