open-telemetry / open-telemetry/opentelemetry-cpp-contrib
Offer a GCP resource detector
Open
@esigo is already working on this.
Since Jul 17, 2023.
- Dominant language
- Python
- Stars
- 153
- Forks
- 184
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 26
Description
Objective
- Make it simple for customers to tie telemetry to the GCP resource producing it.
- Get one step closer to a universal OOTB resource detector
Background
- GCP resource detection is a function of the environment variables and the response (if any) from the metadata server
- The call we are making to the metadata server returns json.
- A C++ GCP resource detector exists in googleapis/google-cloud-cpp.
- The existing resource detector depends on
google-cloud-cppinternals - This is convenient for maintainers of said library, but not worth the cost of an extra dependency for customers.
- The existing resource detector depends on
Detailed Design
Location
I would make new directories: opentelemetry-cpp/detectors/gcp/...
$ tree detectors/gcp
detectors/gcp
├── BUILD
├── CMakeLists.txt
├── include
│ └── opentelemetry
│ └── detectors
│ └── gcp
│ ├── internal
│ │ └── resource_detector_impl.h
│ └── resource_detector.h
├── README.md
├── src
│ ├── resource_detector.cc
│ └── resource_detector_impl.cc
└── test
└── resource_detector_test.cc
Dependencies
nlohmann/jsonlibcurl- Well, it will use the
opentelemetry::ext::http::HttpClientSync. I think that forces the dep onlibcurl, but I am not sure.
- Well, it will use the
Interface
namespace opentelemetry::detectors::gcp
{
// Configuration options for the GCP Resource Detector
struct GcpDetectorOptions
{
std::string endpoint = "http://metadata.google.internal";
// ... and more?
};
// Make a GCP Resource Detector.
std::unique_ptr<sdk::resource::ResourceDetector> MakeGcpDetector(GcpDetectorOptions options = {});
} // namespace opentelemetry::detectors::gcp
// The internal namespace is for implementation details only. The symbols within are not part of the
// public API. They are subject to change, including deletion, without notice.
namespace opentelemetry::detectors::gcp::internal
{
// Interface to simplify testing. The default will sleep.
class Retry
{
// Returns `true` if we should keep retrying, `false` if we should stop retrying.
virtual bool OnRetry() = 0;
};
// In tests, we mock the client and the retry policy.
std::unique_ptr<sdk::resource::ResourceDetector> MakeGcpDetector(
std::shared_ptr<ext::http::client::HttpClientSync> client,
std::shared_ptr<Retry> retry,
GcpDetectorOptions options = {});
} // namespace opentelemetry::detectors::gcp::internal
Testing
- Unit tests will be a thing.
- Adding end-to-end integration tests for all platforms is infeasible.
- Note that E2E testing is done on GCP resource detectors in other languages.
- We will just hope that C++
plagiarizescopies those languages' code correctly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.