Skip to content

Commit

Permalink
Merge branch 'main' into fix-prometheus-example
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Mar 16, 2023
2 parents 19a720a + 2462f7c commit e8b7914
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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...
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/common/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>(left)] == ' ' && left <= right)
while (left <= right && str[static_cast<std::size_t>(left)] == ' ')
{
left++;
}
while (str[static_cast<std::size_t>(right)] == ' ' && left <= right)
while (left <= right && str[static_cast<std::size_t>(right)] == ' ')
{
right--;
}
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/logs/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace logs
/**
* Stores the singleton global LoggerProvider.
*/
class Provider
class OPENTELEMETRY_EXPORT Provider
{
public:
/**
Expand Down
4 changes: 2 additions & 2 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion docs/library-distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/using-clang-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion examples/grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sdk/include/opentelemetry/sdk/resource/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/resource/resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion sdk/test/resource/resource_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit e8b7914

Please sign in to comment.