Skip to content

Commit

Permalink
Merge branch 'main' into b3_propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Jan 28, 2021
2 parents 1a8bb3c + d94a368 commit f52ce7b
Show file tree
Hide file tree
Showing 29 changed files with 311 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ about: Create a report to help us improve
labels: bug
---

**Describe your environment** Describe any aspect of your environment relevant to the problem, including your platform, build system, version numbers of installed dependencies, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on master.
**Describe your environment** Describe any aspect of your environment relevant to the problem, including your platform, build system, version numbers of installed dependencies, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main branch.

**Steps to reproduce**
Describe exactly how to reproduce the error. Include a code sample if applicable.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
cmake_test:
Expand Down
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,29 +217,31 @@ add_subdirectory(ext)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/opentelemetry-cpp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
PATH_VARS OPENTELEMETRY_ABI_VERSION_NO OPENTELEMETRY_VERSION PROJECT_NAME
INCLUDE_INSTALL_DIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

# Write version file for find_packages(opentelemetry-cpp CONFIG)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake"
VERSION ${OPENTELEMETRY_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Export all components
export(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-target.cmake")
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-target.cmake"
)
install(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ example-specific documentation for other build automation tools.
Install the latest bazel version by following the steps listed
[here](https://docs.bazel.build/versions/master/install.html).

Select an example of interest from the [examples folder](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/examples).
Select an example of interest from the [examples folder](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/examples).
Inside each example directory is a `BUILD` file containing instructions for
Bazel. Find the binary name of your example by inspecting the contents of this
`BUILD` file.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenTelemetry C++

[![Gitter chat](https://badges.gitter.im/open-telemetry/opentelemetry-cpp.svg)](https://gitter.im/open-telemetry/opentelemetry-cpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![codecov.io](https://codecov.io/gh/open-telemetry/opentelemetry-cpp/branch/master/graphs/badge.svg?)](https://codecov.io/gh/open-telemetry/opentelemetry-cpp/)
[![codecov.io](https://codecov.io/gh/open-telemetry/opentelemetry-cpp/branch/main/graphs/badge.svg?)](https://codecov.io/gh/open-telemetry/opentelemetry-cpp/)
[![Build Status](https://action-badges.now.sh/open-telemetry/opentelemetry-cpp)](https://github.com/open-telemetry/opentelemetry-cpp/actions)
[![Release](https://img.shields.io/github/v/release/open-telemetry/opentelemetry-cpp?include_prereleases&style=)](https://github.com/open-telemetry/opentelemetry-cpp/releases/)

Expand Down Expand Up @@ -54,7 +54,7 @@ contributors' availability. Check the [OpenTelemetry community
calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com)
for specific dates.

Meetings take place via [Zoom video conference](https://zoom.us/j/8203130519).
Meetings take place via [Zoom video conference](https://zoom.us/j/8203130519). The passcode is _77777_.

Meeting notes are available as a public [Google doc](https://docs.google.com/document/d/1i1E4-_y4uJ083lCutKGDhkpi3n4_e774SBLi9hPLocw/edit?usp=sharing). For edit access, get in touch on [Gitter](https://gitter.im/open-telemetry/opentelemetry-cpp).

Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
```
3. Verify that CHANGELOG.md is updated properly:
```
git diff master
git diff main
```
4. Push the changes to upstream and create a Pull Request on GitHub.
Be sure to include the curated changes from the [Changelog](./CHANGELOG.md) in the description.
Expand Down
6 changes: 5 additions & 1 deletion api/include/opentelemetry/trace/span_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class SpanId final
bool operator!=(const SpanId &that) const noexcept { return !(*this == that); }

// Returns false if the SpanId is all zeros.
bool IsValid() const noexcept { return *this != SpanId(); }
bool IsValid() const noexcept
{
static_assert(kSize == 8, "update is needed if kSize is not 8");
return *reinterpret_cast<const uint64_t *>(&rep_) != 0ull;
}

// Copies the opaque SpanId data to dest.
void CopyBytesTo(nostd::span<uint8_t, kSize> dest) const noexcept
Expand Down
4 changes: 2 additions & 2 deletions buildscripts/pre_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if [ ! grep -q "^\#\# \[Unreleased\]$" $changelog_file ]; then
exit 1
fi

git checkout -b pre_release_${tag} master
git checkout -b pre_release_${tag} main
if [ $? -ne 0 ]; then
echo "Error: Cannot create release branch. Ensure you have sufficient permissions to repo and try again."
exit 1
Expand All @@ -67,5 +67,5 @@ fi
git add CHANGELOG.md
git commit -m "Prepare for releasing ${tag}"

echo "Now validate the chages using git diff master, create the ${tag} and push changes to upstream"
echo "Now validate the changes using git diff main, create the ${tag} and push changes to upstream"
echo
2 changes: 1 addition & 1 deletion examples/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is an example of how to use the [OpenTelemetry Protocol](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/protocol/README.md) (OTLP) exporter.

The application in `main.cc` initializes an `OtlpExporter` instance and uses it to register a tracer provider from the [OpenTelemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then calls a `foo_library` which has been instrumented using the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api).
The application in `main.cc` initializes an `OtlpExporter` instance and uses it to register a tracer provider from the [OpenTelemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then calls a `foo_library` which has been instrumented using the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api).

Resulting spans are exported to the **OpenTelemetry Collector** using the OTLP exporter. The OpenTelemetry Collector can be configured to export to other backends (see list of [supported backends](https://github.com/open-telemetry/opentelemetry-collector/blob/master/exporter/README.md)).

Expand Down
2 changes: 1 addition & 1 deletion examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
In this example, the application in `main.cc` initializes and registers a tracer
provider from the [OpenTelemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp).
The application then calls a `foo_library` which has been instrumented using
the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api).
the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api).
Resulting telemetry is directed to stdout through the StdoutSpanExporter.

See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example.
1 change: 1 addition & 0 deletions exporters/elasticsearch/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cc_library(
strip_include_prefix = "include",
deps = [
"//ext:headers",
"//ext/src/http/client/curl:http_client_curl",
"//sdk/src/logs",
"@curl",
"@github_nlohmann_json//:json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ElasticsearchLogExporter final : public sdklogs::LogExporter
ElasticsearchExporterOptions options_;

// Object that stores the HTTP sessions that have been created
std::unique_ptr<ext::http::client::SessionManager> session_manager_;
std::unique_ptr<ext::http::client::HttpClient> http_client_;
};
} // namespace logs
} // namespace exporter
Expand Down
10 changes: 5 additions & 5 deletions exporters/elasticsearch/src/es_log_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ class ResponseHandler : public http_client::EventHandler

ElasticsearchLogExporter::ElasticsearchLogExporter()
: options_{ElasticsearchExporterOptions()},
session_manager_{new ext::http::client::curl::SessionManager()}
http_client_{new ext::http::client::curl::HttpClient()}
{}

ElasticsearchLogExporter::ElasticsearchLogExporter(const ElasticsearchExporterOptions &options)
: options_{options}, session_manager_{new ext::http::client::curl::SessionManager()}
: options_{options}, http_client_{new ext::http::client::curl::HttpClient()}
{}

std::unique_ptr<sdklogs::Recordable> ElasticsearchLogExporter::MakeRecordable() noexcept
Expand All @@ -151,7 +151,7 @@ sdklogs::ExportResult ElasticsearchLogExporter::Export(
}

// Create a connection to the ElasticSearch instance
auto session = session_manager_->CreateSession(options_.host_, options_.port_);
auto session = http_client_->CreateSession(options_.host_, options_.port_);
auto request = session->CreateRequest();

// Populate the request with headers and methods
Expand Down Expand Up @@ -220,8 +220,8 @@ bool ElasticsearchLogExporter::Shutdown(std::chrono::microseconds timeout) noexc
is_shutdown_ = true;

// Shutdown the session manager
session_manager_->CancelAllSessions();
session_manager_->FinishAllSessions();
http_client_->CancelAllSessions();
http_client_->FinishAllSessions();

return true;
}
Expand Down
5 changes: 4 additions & 1 deletion exporters/elasticsearch/test/es_log_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace logs_api = opentelemetry::logs;
namespace nostd = opentelemetry::nostd;
namespace logs_exporter = opentelemetry::exporter::logs;

#if 0
// Attempt to write a log to an invalid host/port, test that the Export() returns failure
TEST(ElasticsearchLogsExporterTests, InvalidEndpoint)
{
Expand Down Expand Up @@ -70,4 +71,6 @@ TEST(ElasticsearchLogsExporterTests, RecordableCreation)
record->SetResource("key3", 3.142);

exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));
}
}

#endif
4 changes: 2 additions & 2 deletions exporters/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For a full list of backends supported by the Collector, see the [main Collector

## Configuration

The OTLP exporter offers some configuration options. To configure the exporter, create an `OtlpExporterOptions` struct (defined in [exporter.h](https://github.com/open-telemetry/opentelemetry-cpp/blob/master/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_exporter.h)), set the options inside, and pass the struct to the `OtlpExporter` constructor, like so:
The OTLP exporter offers some configuration options. To configure the exporter, create an `OtlpExporterOptions` struct (defined in [exporter.h](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_exporter.h)), set the options inside, and pass the struct to the `OtlpExporter` constructor, like so:

```
OtlpExporterOptions options;
Expand All @@ -24,4 +24,4 @@ auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new otlp::OtlpExporter(o

## Example

For a complete example demonstrating how to use the OTLP exporter, see [examples/otlp](https://github.com/open-telemetry/opentelemetry-cpp/blob/master/examples/otlp/).
For a complete example demonstrating how to use the OTLP exporter, see [examples/otlp](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/examples/otlp/).
100 changes: 76 additions & 24 deletions ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "http_operation_curl.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/version.h"

#include <map>
#include <string>
Expand Down Expand Up @@ -55,7 +57,7 @@ class Request : public http_client::Request
public:
http_client::Method method_;
http_client::Body body_;
Headers headers_;
http_client::Headers headers_;
std::string uri_;
std::chrono::milliseconds timeout_ms_{5000}; // ms
};
Expand Down Expand Up @@ -105,13 +107,13 @@ class Response : public http_client::Response
http_client::StatusCode status_code_;
};

class SessionManager;
class HttpClient;

class Session : public http_client::Session
{
public:
Session(SessionManager &session_manager, const std::string &host, uint16_t port = 80)
: session_manager_(session_manager), is_session_active_(false)
Session(HttpClient &http_client, const std::string &host, uint16_t port = 80)
: http_client_(http_client), is_session_active_(false)
{
if (host.rfind("http://", 0) != 0 && host.rfind("https://", 0) != 0)
{
Expand All @@ -135,9 +137,9 @@ class Session : public http_client::Session
is_session_active_ = true;
std::string url = host_ + std::string(http_request_->uri_);
auto callback_ptr = &callback;
curl_operation_.reset(new HttpOperation(http_request_->method_, url, callback_ptr,
http_request_->headers_, http_request_->body_, false,
http_request_->timeout_ms_));
curl_operation_.reset(new HttpOperation(
http_request_->method_, url, callback_ptr, RequestMode::Sync, http_request_->headers_,
http_request_->body_, false, http_request_->timeout_ms_));
curl_operation_->SendAsync([this, callback_ptr](HttpOperation &operation) {
if (operation.WasAborted())
{
Expand All @@ -148,26 +150,19 @@ class Session : public http_client::Session
if (operation.GetResponseCode() >= CURL_LAST)
{
// we have a http response
auto response = std::unique_ptr<Response>(new Response());
response->headers_ = operation.GetResponseHeaders();
response->body_ = operation.GetResponseBody();
auto response = std::unique_ptr<Response>(new Response());
response->headers_ = operation.GetResponseHeaders();
response->body_ = operation.GetResponseBody();
response->status_code_ = operation.GetResponseCode();
callback_ptr->OnResponse(*response);
}
is_session_active_ = false;
});
}

virtual bool CancelSession() noexcept override
{
curl_operation_->Abort();
return true;
}
virtual bool CancelSession() noexcept override;

virtual bool FinishSession() noexcept override
{
curl_operation_->Finish();
return true;
}
virtual bool FinishSession() noexcept override;

virtual bool IsSessionActive() noexcept override { return is_session_active_; }

Expand All @@ -184,15 +179,72 @@ class Session : public http_client::Session
std::string host_;
std::unique_ptr<HttpOperation> curl_operation_;
uint64_t session_id_;
SessionManager &session_manager_;
HttpClient &http_client_;
bool is_session_active_;
};

class SessionManager : public http_client::SessionManager
class HttpClientSync : public http_client::HttpClientSync
{
public:
HttpClientSync() { curl_global_init(CURL_GLOBAL_ALL); }

http_client::Result Get(const nostd::string_view &url,
const http_client::Headers &headers) noexcept override
{
http_client::Body body;
HttpOperation curl_operation(http_client::Method::Get, url.data(), nullptr, RequestMode::Sync,
headers, body);
curl_operation.SendSync();
auto session_state = curl_operation.GetSessionState();
if (curl_operation.WasAborted())
{
session_state = http_client::SessionState::Cancelled;
}
auto response = std::unique_ptr<Response>(new Response());
if (curl_operation.GetResponseCode() >= CURL_LAST)
{
// we have a http response

response->headers_ = curl_operation.GetResponseHeaders();
response->body_ = curl_operation.GetResponseBody();
response->status_code_ = curl_operation.GetResponseCode();
}
return http_client::Result(std::move(response), session_state);
}

http_client::Result Post(const nostd::string_view &url,
const Data &data,
const http_client::Headers &headers) noexcept override
{
HttpOperation curl_operation(http_client::Method::Post, url.data(), nullptr, RequestMode::Sync,
headers);
curl_operation.SendSync();
auto session_state = curl_operation.GetSessionState();
if (curl_operation.WasAborted())
{
session_state = http_client::SessionState::Cancelled;
}
auto response = std::unique_ptr<Response>(new Response());
if (curl_operation.GetResponseCode() >= CURL_LAST)
{
// we have a http response

response->headers_ = curl_operation.GetResponseHeaders();
response->body_ = curl_operation.GetResponseBody();
response->status_code_ = curl_operation.GetResponseCode();
}

return http_client::Result(std::move(response), session_state);
}

~HttpClientSync() { curl_global_cleanup(); }
};

class HttpClient : public http_client::HttpClient
{
public:
// The call (curl_global_init) is not thread safe. Ensure this is called only once.
SessionManager() : next_session_id_{0} { curl_global_init(CURL_GLOBAL_ALL); }
HttpClient() : next_session_id_{0} { curl_global_init(CURL_GLOBAL_ALL); }

std::shared_ptr<http_client::Session> CreateSession(nostd::string_view host,
uint16_t port = 80) noexcept override
Expand Down Expand Up @@ -228,7 +280,7 @@ class SessionManager : public http_client::SessionManager
sessions_.erase(session_id);
}

~SessionManager() { curl_global_cleanup(); }
~HttpClient() { curl_global_cleanup(); }

private:
std::atomic<uint64_t> next_session_id_;
Expand Down
Loading

0 comments on commit f52ce7b

Please sign in to comment.