diff --git a/CHANGELOG.md b/CHANGELOG.md index c0317fb452..9ea45e1f48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [RESOURCE SDK] Fix schema URL precedence bug in `Resource::Merge`. + [#2036](https://github.com/open-telemetry/opentelemetry-cpp/pull/2036) + ## [1.8.3] 2023-03-06 * Provide version major/minor/patch macros diff --git a/INSTALL.md b/INSTALL.md index 31cc42dd59..74b8e09b15 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -45,7 +45,7 @@ You can link OpenTelemetry C++ SDK with libraries provided in ### Building as standalone CMake Project -1. Getting the opentelementry-cpp source with its submodules: +1. Getting the opentelemetry-cpp source with its submodules: ```console # Change to the directory where you want to create the code repository @@ -136,7 +136,7 @@ To use the library from a CMake project, you can locate it directly with `find_package` and use the imported targets from generated package configurations. As of now, this will import targets for both API and SDK. In future, there may be separate packages for API and SDK which can be installed - and imported separtely according to need. + and imported separately according to need. ```cmake # CMakeLists.txt @@ -171,7 +171,7 @@ Bazel](https://docs.bazel.build/versions/3.7.0/install.html) guide. ### Building as standalone Bazel Project -1. Getting the opentelementry-cpp source: +1. Getting the opentelemetry-cpp source: ```console # Change to the directory where you want to create the code repository @@ -188,7 +188,7 @@ Bazel](https://docs.bazel.build/versions/3.7.0/install.html) guide. the source code: ```console - $ cd opentelemtry-cpp + $ cd opentelemetry-cpp $ bazel build //... bazel build -- //... -//exporters/otlp/... -//exporters/prometheus/... Extracting Bazel installation... @@ -267,9 +267,9 @@ cc_library( Windows DLL build is supported under **preview**. Please check the [doc](./docs/build-as-dll.md) for more details. -## Generatring binary packages +## Generating binary packages -OpenTelemetry C++ supports generating plateform specific binary packages from CMake +OpenTelemetry C++ supports generating platform specific binary packages from CMake configuration. The packages generated through this mayn't be production ready, and user may have to customize it further before using it as distribution. diff --git a/README.md b/README.md index fac6bcbb4f..9166fa690e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ of the current project. | Windows Server 2022 (Visual Studio Enterprise 2022) | CMake | [1]: Bazel build is disabled for GCC 4.8, as gRPC library 1.38 and above - (required by OTLP expoter) don't build with this compiler. See gRPC [official + (required by OTLP exporter) don't build with this compiler. See gRPC [official support](https://grpc.io/docs/#official-support) document. CMake build doesn't build OTLP exporter with GCC 4.8. diff --git a/api/include/opentelemetry/common/string_util.h b/api/include/opentelemetry/common/string_util.h index 5496f8579e..6dce79f1ba 100644 --- a/api/include/opentelemetry/common/string_util.h +++ b/api/include/opentelemetry/common/string_util.h @@ -14,11 +14,11 @@ class StringUtil public: static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept { - while (str[static_cast(left)] == ' ' && left <= right) + while (left <= right && str[static_cast(left)] == ' ') { left++; } - while (str[static_cast(right)] == ' ' && left <= right) + while (left <= right && str[static_cast(right)] == ' ') { right--; } diff --git a/api/include/opentelemetry/logs/provider.h b/api/include/opentelemetry/logs/provider.h index ed6fe86baa..e361c1e670 100644 --- a/api/include/opentelemetry/logs/provider.h +++ b/api/include/opentelemetry/logs/provider.h @@ -19,7 +19,7 @@ namespace logs /** * Stores the singleton global LoggerProvider. */ -class Provider +class OPENTELEMETRY_EXPORT Provider { public: /** diff --git a/docs/dependencies.md b/docs/dependencies.md index a1724eb76c..06c3806d34 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -46,7 +46,7 @@ Both these dependencies are listed here: - OTLP messages are constructed as protobuf payloads. - `protoc` compiler is used to generate C++ stubs for proto files provided by `opentelemetry-proto`. - - `libprotobuf` library is used for generating serialised trace/metrics/log + - `libprotobuf` library is used for generating serialized trace/metrics/log data to be sent to opentelemetry collector. - License: The library is licensed [here](https://github.com/protocolbuffers/protobuf/blob/master/LICENSE). @@ -80,7 +80,7 @@ Both these dependencies are listed here: - [Thrift](https://github.com/apache/thrift) - Serialization and RPC framework. - `thrift` compiler to generate C++ stubs for IDL data model for Jaeger. - - `libthrift` library to generate serialised trace/metrics/log data to be + - `libthrift` library to generate serialized trace/metrics/log data to be sent to remote Jaeger service. Note: libthrift **0.12.0** doesn't work with this Jaeger exporter. See [#1680](https://github.com/open-telemetry/opentelemetry-cpp/issues/1680). diff --git a/docs/library-distribution.md b/docs/library-distribution.md index 3fcbce4739..00794f87a0 100644 --- a/docs/library-distribution.md +++ b/docs/library-distribution.md @@ -118,7 +118,7 @@ Examples: NGINX's dynamic module capability, tracing can be supported as a plugin. For instance, the [nginx-opentracing module](https://github.com/opentracing-contrib/nginx-opentracing) provides - this type of extension and is used by projects such as Kubernete's [ingress + this type of extension and is used by projects such as Kubernetes [ingress controller](https://kubernetes.github.io/ingress-nginx/user-guide/third-party-addons/opentracing/). * The CPython binary also has no knowledge of OpenTelemetry, but C++ Python extension modules can be instrumented for OpenTelemetry. diff --git a/docs/using-clang-format.md b/docs/using-clang-format.md index 24d2404763..3d1fcc108f 100644 --- a/docs/using-clang-format.md +++ b/docs/using-clang-format.md @@ -48,6 +48,6 @@ For further guidance on editor integration, see these specific pages: No. For the project as a whole, using clang-format is just one optional way to format your code. While it will produce style-guide conformant code, other -formattings would also satisfy the style guide. For certain modules it may be +formats would also satisfy the style guide. For certain modules it may be appropriate to use alternate coding style. In those scenarios a local directory *.clang-format* settings file takes precedence over the one at top-level. diff --git a/examples/grpc/README.md b/examples/grpc/README.md index 96d1dc2797..0b72963233 100644 --- a/examples/grpc/README.md +++ b/examples/grpc/README.md @@ -24,7 +24,7 @@ of tracing such as: ``find_package(gRPC)`` -2. Build and Deploy the opentelementry-cpp as described in +2. Build and Deploy the opentelemetry-cpp as described in [INSTALL.md](../../INSTALL.md). Building the project will build all of the examples and create new folders containing their executables within the 'build' directory NOT the 'examples' directory. diff --git a/examples/http/README.md b/examples/http/README.md index 70285170fc..a02acbe898 100644 --- a/examples/http/README.md +++ b/examples/http/README.md @@ -21,7 +21,7 @@ to server. The example shows several aspects of tracing such as: * [HTTP Server](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/ext/include/opentelemetry/ext/http/server) -2. Build and Deploy the opentelementry-cpp as described in +2. Build and Deploy the opentelemetry-cpp as described in [INSTALL.md](../../INSTALL.md) 3. Start the server from the `examples/http` directory diff --git a/examples/otlp/README.md b/examples/otlp/README.md index 43010e6d79..e845786346 100644 --- a/examples/otlp/README.md +++ b/examples/otlp/README.md @@ -31,7 +31,7 @@ API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). To enable TLS authentication for OTLP grpc exporter, SslCredentials can be used by specifying the path to client certificate pem file, or the string containing this certificate via OtlpGrpcExporterOptions. The path to such a .pem file can be -provided as a command-line argument alongwith the collector endpoint to the main +provided as a command-line argument along with the collector endpoint to the main binary invocation above. ### Running OpenTelemetry Collector as docker container diff --git a/sdk/include/opentelemetry/sdk/resource/resource.h b/sdk/include/opentelemetry/sdk/resource/resource.h index c69b971b04..09da0b8c97 100644 --- a/sdk/include/opentelemetry/sdk/resource/resource.h +++ b/sdk/include/opentelemetry/sdk/resource/resource.h @@ -36,6 +36,10 @@ class Resource * with the other Resource. In case of a collision, the other Resource takes * precedence. * + * The specification notes that if schema urls collide, the resulting + * schema url is implementation-defined. In the C++ implementation, the + * schema url of @param other is picked. + * * @param other the Resource that will be merged with this. * @returns the newly merged Resource. */ diff --git a/sdk/src/resource/resource.cc b/sdk/src/resource/resource.cc index a07f4d3a3c..f71e17a8a7 100644 --- a/sdk/src/resource/resource.cc +++ b/sdk/src/resource/resource.cc @@ -21,7 +21,8 @@ Resource Resource::Merge(const Resource &other) const noexcept { ResourceAttributes merged_resource_attributes(other.attributes_); merged_resource_attributes.insert(attributes_.begin(), attributes_.end()); - return Resource(merged_resource_attributes, other.schema_url_); + return Resource(merged_resource_attributes, + other.schema_url_.empty() ? schema_url_ : other.schema_url_); } Resource Resource::Create(const ResourceAttributes &attributes, const std::string &schema_url) diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 1c14301a57..803d5666d9 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -26,7 +26,9 @@ namespace nostd = opentelemetry::nostd; class TestResource : public Resource { public: - TestResource(ResourceAttributes attributes = ResourceAttributes()) : Resource(attributes) {} + TestResource(ResourceAttributes attributes = ResourceAttributes(), std::string schema_url = {}) + : Resource(attributes, schema_url) + {} }; TEST(ResourceTest, create_without_servicename) @@ -170,6 +172,32 @@ TEST(ResourceTest, MergeEmptyString) EXPECT_EQ(received_attributes.size(), expected_attributes.size()); } +TEST(ResourceTest, MergeSchemaUrl) +{ + const std::string url = "https://opentelemetry.io/schemas/v3.1.4"; + + TestResource resource_empty_url({}, ""); + TestResource resource_some_url({}, url); + TestResource resource_different_url({}, "different"); + + // Specified behavior: + auto merged_both_empty = resource_empty_url.Merge(resource_empty_url); + EXPECT_TRUE(merged_both_empty.GetSchemaURL().empty()); + + auto merged_old_empty = resource_empty_url.Merge(resource_some_url); + EXPECT_EQ(merged_old_empty.GetSchemaURL(), url); + + auto merged_updating_empty = resource_some_url.Merge(resource_empty_url); + EXPECT_EQ(merged_updating_empty.GetSchemaURL(), url); + + auto merged_same_url = resource_some_url.Merge(resource_some_url); + EXPECT_EQ(merged_same_url.GetSchemaURL(), url); + + // Implementation-defined behavior: + auto merged_different_url = resource_different_url.Merge(resource_some_url); + EXPECT_EQ(merged_different_url.GetSchemaURL(), url); +} + #ifndef NO_GETENV TEST(ResourceTest, OtelResourceDetector) {