open-telemetry / open-telemetry/opentelemetry-cpp-contrib

Offer a GCP resource detector

Open
#307 4 comments 2 reactions 1 assignee View on GitHub

@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-cpp internals
    • This is convenient for maintainers of said library, but not worth the cost of an extra dependency for customers.

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/json
  • libcurl
    • Well, it will use the opentelemetry::ext::http::HttpClientSync. I think that forces the dep on libcurl, but I am not sure.

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++ plagiarizes copies those languages' code correctly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.