diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bc622e2e7..5485d59f1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -173,10 +173,6 @@ updates: directory: "/instrumentation/rails" schedule: interval: weekly -- package-ecosystem: bundler - directory: "/resource_detectors" - schedule: - interval: weekly - package-ecosystem: bundler directory: "/resources/azure" schedule: diff --git a/.github/workflows/ci-contrib-canary.yml b/.github/workflows/ci-contrib-canary.yml index ebf4f534a..214a516a7 100644 --- a/.github/workflows/ci-contrib-canary.yml +++ b/.github/workflows/ci-contrib-canary.yml @@ -63,7 +63,6 @@ jobs: fail-fast: false matrix: gem: - - resource_detectors - resource-detector-azure - resource-detector-container - resource-detector-google_cloud_platform diff --git a/.github/workflows/ci-contrib.yml b/.github/workflows/ci-contrib.yml index c2a86e1b0..75e970310 100644 --- a/.github/workflows/ci-contrib.yml +++ b/.github/workflows/ci-contrib.yml @@ -54,7 +54,6 @@ jobs: fail-fast: false matrix: gem: - - resource_detectors - resource-detector-azure - resource-detector-container - resource-detector-google_cloud_platform diff --git a/.toys/.data/releases.yml b/.toys/.data/releases.yml index 8b78685f3..4cb72bc97 100644 --- a/.toys/.data/releases.yml +++ b/.toys/.data/releases.yml @@ -203,11 +203,6 @@ gems: directory: propagator/xray version_constant: [OpenTelemetry, Propagator, XRay, VERSION] - - name: opentelemetry-resource_detectors - directory: resource_detectors - version_rb_path: lib/opentelemetry/resource/detectors/version.rb - version_constant: [OpenTelemetry, Resource, Detectors, VERSION] - - name: opentelemetry-resource-detector-azure directory: resources/azure version_rb_path: lib/opentelemetry/resource/detector/azure/version.rb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 391929061..aad37a276 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,15 +67,15 @@ _Setting up a running Ruby environment is outside the scope of this document._ This repository contains multiple Ruby gems: * Various instrumentation gems located in subdirectories of `instrumentation` + * Various resource detector gems located in subdirectories of `resources` * `opentelemetry-propagator-xray` located in the `propagator/xray` directory * `opentelemetry-propagator-ottrace` located in the `propagator/ottrace` directory - * `opentelemetry-resource_detectors` located in the `resource_detectors` directory Each of these gems has its configuration and tests. -For example, to test `opentelemetry-resource_detectors` you would: +For example, to test `opentelemetry-instrumentation-action_pack` you would: - 1. Change directory to `resource_detectors` + 1. Change directory to `instrumentation/action_pack` 2. Install the bundle with `bundle install` 3. Run the tests with `bundle exec rake` diff --git a/README.md b/README.md index ea2c37820..67216b2b9 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ using OpenTelemetry with minimal changes to your application. See the This repository also contains libraries to aid with interoperablity with vendor specific tracing solutions: - [Context Propagation](propagator/): OTTrace and Amazon X-Ray -- [Resource Detectors](resource_detectors/): +- [Resource Detectors](resources/): - Azure - Container - Google Cloud Platform diff --git a/releases/Gemfile b/releases/Gemfile index bfc49848d..c9cd38765 100644 --- a/releases/Gemfile +++ b/releases/Gemfile @@ -36,7 +36,6 @@ gem 'trilogy' gem 'opentelemetry-api' gem 'opentelemetry-sdk' -gem 'opentelemetry-resource_detectors' Dir['../propagator/**/version.rb'].each do |f| name = f.match(%r{propagator/(\w+)/lib})[1] diff --git a/resource_detectors/.rubocop.yml b/resource_detectors/.rubocop.yml deleted file mode 100644 index fc2019d46..000000000 --- a/resource_detectors/.rubocop.yml +++ /dev/null @@ -1 +0,0 @@ -inherit_from: ../.rubocop.yml diff --git a/resource_detectors/.yardopts b/resource_detectors/.yardopts deleted file mode 100644 index 1b25699e2..000000000 --- a/resource_detectors/.yardopts +++ /dev/null @@ -1,9 +0,0 @@ ---no-private ---title=OpenTelemetry Resource Detectors ---markup=markdown ---main=README.md -./lib/opentelemetry/resource/detectors/**/*.rb -./lib/opentelemetry/resource/detectors.rb -- -README.md -CHANGELOG.md diff --git a/resource_detectors/CHANGELOG.md b/resource_detectors/CHANGELOG.md deleted file mode 100644 index 5d6b2c0e6..000000000 --- a/resource_detectors/CHANGELOG.md +++ /dev/null @@ -1,106 +0,0 @@ -# Release History: opentelemetry-resource_detectors - -### v0.24.2 / 2023-09-07 - -* CHANGED: split resource_detectors into their own gems - -### v0.24.1 / 2023-08-03 - -* FIXED: Remove inline linter rules - -### v0.24.0 / 2023-08-02 - -* ADDED: Add container resource detector - -### v0.23.0 / 2023-04-17 - -* BREAKING CHANGE: Drop support for EoL Ruby 2.7 - -* ADDED: Drop support for EoL Ruby 2.7 - -### v0.22.0 / 2023-01-14 - -* ADDED: Add azure resource detector. -* DOCS: Fix gem homepage -* DOCS: More gem documentation fixes - -### v0.21.0 / 2022-06-09 - -* BREAKING CHANGE: This requires upgrading both the SDK and Instrumentation gem in tandem - - -### v0.20.0 / 2022-05-02 - -* ADDED: Added Google Cloud Function Resource Detection - -### v0.19.1 / 2021-09-29 - -* (No significant changes) - -### v0.19.0 / 2021-08-12 - -* BREAKING CHANGE: Use auto-generated resource constants in sdk and resource_detectors - -* ADDED: Use auto-generated resource constants in sdk and resource_detectors - -### v0.18.1 / 2021-06-23 - -* (No significant changes) - -### v0.18.0 / 2021-05-21 - -* FIXED: Rename cloud.zone to cloud.availability_zone - -### v0.17.0 / 2021-04-22 - -* (No significant changes) - -### v0.16.0 / 2021-03-17 - -* ADDED: Add k8s node to gcp resource detector -* DOCS: Replace Gitter with GitHub Discussions - -### v0.15.0 / 2021-02-18 - -* (No significant changes) - -### v0.14.0 / 2021-02-03 - -* DOCS: Updated gem name to match gemspec - -### v0.13.0 / 2021-01-29 - -* (No significant changes) - -### v0.12.0 / 2020-12-24 - -* (No significant changes) - -### v0.11.0 / 2020-12-11 - -* FIXED: Copyright comments to not reference year - -### v0.10.0 / 2020-12-03 - -* (No significant changes) - -### v0.9.0 / 2020-11-27 - -* BREAKING CHANGE: Add timeout for force_flush and shutdown - -* ADDED: Add timeout for force_flush and shutdown - -### v0.8.0 / 2020-10-27 - -* (No significant changes) - -### v0.7.0 / 2020-10-07 - -* DOCS: Standardize toplevel docs structure and readme - -### v0.6.0 / 2020-09-10 - -* BREAKING CHANGE: Rename Resource labels to attributes - -* FIXED: Rename Resource labels to attributes -* ADDED: Environment variable resource detection diff --git a/resource_detectors/Gemfile b/resource_detectors/Gemfile deleted file mode 100644 index 6ae9e48bc..000000000 --- a/resource_detectors/Gemfile +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -source 'https://rubygems.org' - -gemspec - -group :development, :test do - gem 'byebug' unless RUBY_PLATFORM == 'java' - gem 'pry' -end diff --git a/resource_detectors/LICENSE b/resource_detectors/LICENSE deleted file mode 100644 index 1ef7dad2c..000000000 --- a/resource_detectors/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright The OpenTelemetry Authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/resource_detectors/README.md b/resource_detectors/README.md deleted file mode 100644 index a0ffaa622..000000000 --- a/resource_detectors/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# Opentelemetry::Resource::Detectors - -The `opentelemetry-resource_detectors` gem provides resource detectors for OpenTelemetry. - -## What is OpenTelemetry? - -OpenTelemetry is an open source observability framework, providing a general-purpose API, SDK, and related tools required for the instrumentation of cloud-native software, frameworks, and libraries. - -OpenTelemetry provides a single set of APIs, libraries, agents, and collector services to capture distributed traces and metrics from your application. You can analyze them using Prometheus, Jaeger, and other observability tools. - -## How does this gem fit in? - -The `opentelemetry-resource-detectors` gem provides a means of retrieving a resource for supported environments following the resource semantic conventions. - -## How do I get started? - -Install the gem using: - -``` -gem install opentelemetry-sdk -gem install opentelemetry-resource_detectors -``` - -Or, if you use Bundler, include `opentelemetry-sdk` and `opentelemetry-resource_detectors` in your `Gemfile`. - -```rb -require 'opentelemetry/sdk' -require 'opentelemetry/resource/detectors' - -# For a specific platform -OpenTelemetry::SDK.configure do |c| - c.resource = OpenTelemetry::Resource::Detectors::GoogleCloudPlatform.detect -end - -# Or if you would like for it to run all detectors available -OpenTelemetry::SDK.configure do |c| - c.resource = OpenTelemetry::Resource::Detectors::AutoDetector.detect -end -``` - -## How can I get involved? - -The `opentelemetry-resource_detectors` gem source is on github, along with related gems. - -The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the meeting calendar for dates and times. For more information on this and other language SIGs, see the OpenTelemetry community page. - -## License - -The `opentelemetry-resource_detectors` gem is distributed under the Apache 2.0 license. See LICENSE for more information. - -[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions diff --git a/resource_detectors/Rakefile b/resource_detectors/Rakefile deleted file mode 100644 index 1a64ba842..000000000 --- a/resource_detectors/Rakefile +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'bundler/gem_tasks' -require 'rake/testtask' -require 'yard' -require 'rubocop/rake_task' - -RuboCop::RakeTask.new - -Rake::TestTask.new :test do |t| - t.libs << 'test' - t.libs << 'lib' - t.test_files = FileList['test/**/*_test.rb'] -end - -YARD::Rake::YardocTask.new do |t| - t.stats_options = ['--list-undoc'] -end - -if RUBY_ENGINE == 'truffleruby' - task default: %i[test] -else - task default: %i[test rubocop yard] -end diff --git a/resource_detectors/lib/opentelemetry-resource_detectors.rb b/resource_detectors/lib/opentelemetry-resource_detectors.rb deleted file mode 100644 index c84a217e4..000000000 --- a/resource_detectors/lib/opentelemetry-resource_detectors.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require_relative 'opentelemetry/resource/detectors' diff --git a/resource_detectors/lib/opentelemetry/resource/detectors.rb b/resource_detectors/lib/opentelemetry/resource/detectors.rb deleted file mode 100644 index 78494b65a..000000000 --- a/resource_detectors/lib/opentelemetry/resource/detectors.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'opentelemetry/sdk' -require 'opentelemetry/resource/detectors/version' -require 'opentelemetry/resource/detectors/google_cloud_platform' -require 'opentelemetry/resource/detectors/azure' -require 'opentelemetry/resource/detectors/auto_detector' - -# OpenTelemetry is an open source observability framework, providing a -# general-purpose API, SDK, and related tools required for the instrumentation -# of cloud-native software, frameworks, and libraries. -# -# The OpenTelemetry module provides global accessors for telemetry objects. -# See the documentation for the `opentelemetry-api` gem for details. -module OpenTelemetry - module Resource - # Detectors contains the resource detectors as well as the AutoDetector - # that can run all the detectors and return an accumlated resource - module Detectors - end - end -end diff --git a/resource_detectors/lib/opentelemetry/resource/detectors/auto_detector.rb b/resource_detectors/lib/opentelemetry/resource/detectors/auto_detector.rb deleted file mode 100644 index 2eb873bdc..000000000 --- a/resource_detectors/lib/opentelemetry/resource/detectors/auto_detector.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -module OpenTelemetry - module Resource - module Detectors - # AutoDetector contains detect class method for running all detectors - module AutoDetector - extend self - - DETECTORS = [ - OpenTelemetry::Resource::Detectors::Azure, - OpenTelemetry::Resource::Detectors::GoogleCloudPlatform - ].freeze - - def detect - DETECTORS.map(&:detect).reduce(:merge) - end - end - end - end -end diff --git a/resource_detectors/lib/opentelemetry/resource/detectors/azure.rb b/resource_detectors/lib/opentelemetry/resource/detectors/azure.rb deleted file mode 100644 index c27ccc012..000000000 --- a/resource_detectors/lib/opentelemetry/resource/detectors/azure.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'net/http' - -module OpenTelemetry - module Resource - module Detectors - # Azure contains detect class method for determining Azure environment resource attributes - # - # This gem has been moved into a separate gem: - # opentelemetry-resource-detector-azure - # - # Log a warning if someone still uses this gem for Azure Resource Detection - module Azure - extend self - - AZURE_METADATA_URI = 'http://169.254.169.254/metadata/instance/compute?api-version=2019-08-15' - - def detect - OpenTelemetry.logger.warn('Azure resource detector - The Azure resource detector has been moved to a separate gem. ' \ - 'Please use the "opentelemetry-resource-detector-azure" gem onwards.') - - metadata = azure_metadata - resource_attributes = {} - - unless metadata.nil? - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_PROVIDER] = 'azure' - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID] = metadata['subscriptionId'] - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_PLATFORM] = cloud_platform(metadata['provider']) - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_REGION] = metadata['location'] - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_AVAILABILITY_ZONE] = metadata['zone'] - - resource_attributes[OpenTelemetry::SemanticConventions::Resource::HOST_ID] = metadata['vmId'] - resource_attributes[OpenTelemetry::SemanticConventions::Resource::HOST_IMAGE_ID] = metadata.dig('storageProfile', 'imageReference', 'id') - resource_attributes[OpenTelemetry::SemanticConventions::Resource::HOST_TYPE] = metadata['vmSize'] - resource_attributes[OpenTelemetry::SemanticConventions::Resource::HOST_NAME] = metadata['name'] - end - - resource_attributes.delete_if { |_key, value| value.nil? || value.empty? } - OpenTelemetry::SDK::Resources::Resource.create(resource_attributes) - end - - private - - def azure_metadata - uri = URI(AZURE_METADATA_URI) - - req = Net::HTTP::Get.new(uri) - req['Metadata'] = 'true' - - response = Net::HTTP.start(uri.hostname, uri.port, open_timeout: 2) do |http| - http.request(req) - end - - return unless response.code == '200' - - JSON.parse(response.body) - rescue Errno::EHOSTDOWN, Net::OpenTimeout, SocketError - nil - end - - def cloud_platform(metadata) - case metadata - when 'Microsoft.Compute' - 'azure_vm' - else - '' - end - end - end - end - end -end diff --git a/resource_detectors/lib/opentelemetry/resource/detectors/google_cloud_platform.rb b/resource_detectors/lib/opentelemetry/resource/detectors/google_cloud_platform.rb deleted file mode 100644 index 17795ebf4..000000000 --- a/resource_detectors/lib/opentelemetry/resource/detectors/google_cloud_platform.rb +++ /dev/null @@ -1,80 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'google-cloud-env' - -module OpenTelemetry - module Resource - module Detectors - # GoogleCloudPlatform contains detect class method for determining gcp environment resource attributes - # - # This gem has been moved into a separate gem: - # opentelemetry-resource-detector-google_cloud_platform - # - # Log a warning if someone still uses this gem for GoogleCloudPlatform Resource Detection - module GoogleCloudPlatform - extend self - - def detect - OpenTelemetry.logger.warn('GoogleCloudPlatform resource detector - The GoogleCloudPlatform resource detector has been moved to a separate gem. ' \ - 'Please use the "opentelemetry-resource-detector-google_cloud_platform" gem onwards.') - - gcp_env = Google::Cloud::Env.new - resource_attributes = {} - - if gcp_env.compute_engine? - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_PROVIDER] = 'gcp' - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID] = gcp_env.project_id - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_REGION] = gcp_env.instance_attribute('cluster-location') - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_AVAILABILITY_ZONE] = gcp_env.instance_zone - - resource_attributes[OpenTelemetry::SemanticConventions::Resource::HOST_ID] = gcp_env.lookup_metadata('instance', 'id') - resource_attributes[OpenTelemetry::SemanticConventions::Resource::HOST_NAME] = ENV['HOSTNAME'] || - gcp_env.lookup_metadata('instance', 'hostname') || - safe_gethostname - end - - if gcp_env.kubernetes_engine? - resource_attributes[OpenTelemetry::SemanticConventions::Resource::K8S_CLUSTER_NAME] = gcp_env.instance_attribute('cluster-name') - resource_attributes[OpenTelemetry::SemanticConventions::Resource::K8S_NAMESPACE_NAME] = gcp_env.kubernetes_engine_namespace_id - resource_attributes[OpenTelemetry::SemanticConventions::Resource::K8S_POD_NAME] = ENV['HOSTNAME'] || safe_gethostname - resource_attributes[OpenTelemetry::SemanticConventions::Resource::K8S_NODE_NAME] = gcp_env.lookup_metadata('instance', 'hostname') - - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CONTAINER_NAME] = ENV.fetch('CONTAINER_NAME', nil) - end - - if gcp_env.knative? - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_PROVIDER] = 'gcp' - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID] = gcp_env.project_id - resource_attributes[OpenTelemetry::SemanticConventions::Resource::FAAS_NAME] = gcp_env.knative_service_id - resource_attributes[OpenTelemetry::SemanticConventions::Resource::FAAS_VERSION] = gcp_env.knative_service_revision - zone = gcp_env.instance_zone - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_REGION] = get_region zone - resource_attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_AVAILABILITY_ZONE] = zone - end - - resource_attributes.delete_if { |_key, value| value.nil? || value.empty? } - OpenTelemetry::SDK::Resources::Resource.create(resource_attributes) - end - - private - - def get_region(zone) - return if zone.nil? || zone.empty? - - split_arr = zone.split('-', 3) - split_arr[0].concat('-', split_arr[1]) - end - - def safe_gethostname - Socket.gethostname - rescue StandardError - '' - end - end - end - end -end diff --git a/resource_detectors/lib/opentelemetry/resource/detectors/version.rb b/resource_detectors/lib/opentelemetry/resource/detectors/version.rb deleted file mode 100644 index d500bc012..000000000 --- a/resource_detectors/lib/opentelemetry/resource/detectors/version.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -module OpenTelemetry - module Resource - module Detectors - VERSION = '0.24.2' - end - end -end diff --git a/resource_detectors/opentelemetry-resource_detectors.gemspec b/resource_detectors/opentelemetry-resource_detectors.gemspec deleted file mode 100644 index 3613cf69f..000000000 --- a/resource_detectors/opentelemetry-resource_detectors.gemspec +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'opentelemetry/resource/detectors/version' - -Gem::Specification.new do |spec| - spec.name = 'opentelemetry-resource_detectors' - spec.version = OpenTelemetry::Resource::Detectors::VERSION - spec.authors = ['OpenTelemetry Authors'] - spec.email = ['cncf-opentelemetry-contributors@lists.cncf.io'] - - spec.summary = 'Resource detection helpers for OpenTelemetry' - spec.description = 'Resource detection helpers for OpenTelemetry' - spec.homepage = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib' - spec.license = 'Apache-2.0' - - spec.files = Dir.glob('lib/**/*.rb') + - Dir.glob('*.md') + - ['LICENSE', '.yardopts'] - spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 3.0' - - spec.add_dependency 'google-cloud-env' - spec.add_dependency 'opentelemetry-sdk', '~> 1.0' - - spec.add_development_dependency 'bundler', '~> 2.4' - spec.add_development_dependency 'minitest', '~> 5.0' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rubocop', '~> 1.57.1' - spec.add_development_dependency 'simplecov', '~> 0.17' - spec.add_development_dependency 'webmock', '~> 3.19' - spec.add_development_dependency 'yard', '~> 0.9' - - spec.post_install_message = 'This gem has been deprecated. Please use opentelemetry-resource-detector-azure ' \ - 'or opentelemetry-resource-detector-google_cloud_platform onwards.' - - if spec.respond_to?(:metadata) - spec.metadata['changelog_uri'] = "https://rubydoc.info/gems/#{spec.name}/#{spec.version}/file/CHANGELOG.md" - spec.metadata['source_code_uri'] = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/resource_detectors' - spec.metadata['bug_tracker_uri'] = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues' - spec.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{spec.name}/#{spec.version}" - end -end diff --git a/resource_detectors/test/opentelemetry/detectors/auto_detector_test.rb b/resource_detectors/test/opentelemetry/detectors/auto_detector_test.rb deleted file mode 100644 index c9b583601..000000000 --- a/resource_detectors/test/opentelemetry/detectors/auto_detector_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'test_helper' - -describe OpenTelemetry::Resource::Detectors::AutoDetector do - before do - WebMock.disable_net_connect! - # Azure stub - stub_request(:get, 'http://169.254.169.254/metadata/instance/compute?api-version=2019-08-15') - .with( - headers: { - 'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Host' => '169.254.169.254', - 'Metadata' => 'true', - 'User-Agent' => 'Ruby' - } - ).to_raise(SocketError) - - # GCP stub - stub_request(:get, 'http://169.254.169.254/') - .with( - headers: { - 'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Metadata-Flavor' => 'Google', - 'User-Agent' => 'Ruby' - } - ) - .to_return(status: 200, body: '', headers: {}) - end - - after do - WebMock.allow_net_connect! - end - - let(:auto_detector) { OpenTelemetry::Resource::Detectors::AutoDetector } - let(:detected_resource) { auto_detector.detect } - let(:detected_resource_attributes) { detected_resource.attribute_enumerator.to_h } - let(:expected_resource_attributes) { {} } - - describe '.detect' do - it 'returns detected resources' do - _(detected_resource).must_be_instance_of(OpenTelemetry::SDK::Resources::Resource) - _(detected_resource_attributes).must_equal(expected_resource_attributes) - end - end -end diff --git a/resource_detectors/test/opentelemetry/detectors/azure_test.rb b/resource_detectors/test/opentelemetry/detectors/azure_test.rb deleted file mode 100644 index 8da61cb20..000000000 --- a/resource_detectors/test/opentelemetry/detectors/azure_test.rb +++ /dev/null @@ -1,120 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'test_helper' - -describe OpenTelemetry::Resource::Detectors::Azure do - before do - WebMock.disable_net_connect! - stub_request(:get, 'http://169.254.169.254/metadata/instance/compute?api-version=2019-08-15') - .with( - headers: { - 'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Host' => '169.254.169.254', - 'Metadata' => 'true', - 'User-Agent' => 'Ruby' - } - ).to_raise(SocketError) - end - - after do - WebMock.allow_net_connect! - end - - let(:detector) { OpenTelemetry::Resource::Detectors::Azure } - - describe '.detect' do - let(:detected_resource) { detector.detect } - let(:detected_resource_attributes) { detected_resource.attribute_enumerator.to_h } - let(:expected_resource_attributes) { {} } - - describe 'when NOT in an azure environment' do - it 'returns an empty resource' do - _(detected_resource).must_be_instance_of(OpenTelemetry::SDK::Resources::Resource) - _(detected_resource_attributes).must_equal(expected_resource_attributes) - end - end - - describe 'when in an azure VM environment' do - let(:project_id) { 'opentelemetry' } - let(:azure_metadata) do - { - 'subscriptionId' => project_id, - 'provider' => 'Microsoft.Compute', - 'location' => 'westeurope', - 'zone' => '2', - 'vmId' => '012345671234-abcd-1234-0123456789ab', - 'storageProfile' => { - 'imageReference' => { - 'id' => '/subscriptions/12345678-abcd-1234-abcd-0123456789ab/resourceGroups/AKS-Ubuntu/providers/Microsoft.Compute/galleries/AKSUbuntu/images/1804gen2containerd/versions/2022.06.22' - } - }, - 'vmSize' => 'Standard_D2s_v3', - 'name' => 'opentelemetry' - }.to_json - end - - before do - metadata = Minitest::Mock.new - metadata.expect(:code, 200) - metadata.expect(:body, azure_metadata) - metadata.expect(:nil?, false) - - WebMock.disable_net_connect! - stub_request(:get, 'http://169.254.169.254/metadata/instance/compute?api-version=2019-08-15') - .with( - headers: { - 'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Host' => '169.254.169.254', - 'Metadata' => 'true', - 'User-Agent' => 'Ruby' - } - ).to_return(status: 200, body: azure_metadata, headers: {}) - end - - after do - WebMock.allow_net_connect! - end - - let(:expected_resource_attributes) do - { - 'cloud.provider' => 'azure', - 'cloud.account.id' => 'opentelemetry', - 'cloud.platform' => 'azure_vm', - 'cloud.region' => 'westeurope', - 'cloud.availability_zone' => '2', - 'host.id' => '012345671234-abcd-1234-0123456789ab', - 'host.image.id' => '/subscriptions/12345678-abcd-1234-abcd-0123456789ab/resourceGroups/AKS-Ubuntu/providers/Microsoft.Compute/galleries/AKSUbuntu/images/1804gen2containerd/versions/2022.06.22', - 'host.name' => 'opentelemetry', - 'host.type' => 'Standard_D2s_v3' - } - end - - it 'returns a resource with azure attributes' do - _(detected_resource).must_be_instance_of(OpenTelemetry::SDK::Resources::Resource) - _(detected_resource_attributes).must_equal(expected_resource_attributes) - end - - describe 'and a nil resource value is detected' do - let(:project_id) { nil } - - it 'returns a resource without that attribute' do - _(detected_resource_attributes.key?('cloud.account.id')).must_equal(false) - end - end - - describe 'and an empty string resource value is detected' do - let(:project_id) { '' } - - it 'returns a resource without that attribute' do - _(detected_resource_attributes.key?('cloud.account.id')).must_equal(false) - end - end - end - end -end diff --git a/resource_detectors/test/opentelemetry/detectors/google_cloud_platform_test.rb b/resource_detectors/test/opentelemetry/detectors/google_cloud_platform_test.rb deleted file mode 100644 index c537bef2d..000000000 --- a/resource_detectors/test/opentelemetry/detectors/google_cloud_platform_test.rb +++ /dev/null @@ -1,110 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'test_helper' - -describe OpenTelemetry::Resource::Detectors::GoogleCloudPlatform do - let(:detector) { OpenTelemetry::Resource::Detectors::GoogleCloudPlatform } - - describe '.detect' do - before do - WebMock.disable_net_connect! - stub_request(:get, 'http://169.254.169.254/') - .with( - headers: { - 'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Metadata-Flavor' => 'Google', - 'User-Agent' => 'Ruby' - } - ) - .to_return(status: 200, body: '', headers: {}) - end - - after do - WebMock.allow_net_connect! - end - - let(:detected_resource) { detector.detect } - let(:detected_resource_attributes) { detected_resource.attribute_enumerator.to_h } - let(:expected_resource_attributes) { {} } - - it 'returns an empty resource' do - _(detected_resource).must_be_instance_of(OpenTelemetry::SDK::Resources::Resource) - _(detected_resource_attributes).must_equal(expected_resource_attributes) - end - - describe 'when in a gcp environment' do - let(:project_id) { 'opentelemetry' } - - before do - gcp_env_mock = Minitest::Mock.new - gcp_env_mock.expect(:compute_engine?, true) - gcp_env_mock.expect(:project_id, project_id) - gcp_env_mock.expect(:instance_attribute, 'us-central1', %w[cluster-location]) - gcp_env_mock.expect(:instance_zone, 'us-central1-a') - gcp_env_mock.expect(:lookup_metadata, 'opentelemetry-test', %w[instance id]) - gcp_env_mock.expect(:lookup_metadata, 'opentelemetry-node-1', %w[instance hostname]) - gcp_env_mock.expect(:instance_attribute, 'opentelemetry-cluster', %w[cluster-name]) - gcp_env_mock.expect(:kubernetes_engine?, true) - gcp_env_mock.expect(:kubernetes_engine_namespace_id, 'default') - gcp_env_mock.expect(:knative?, true) - gcp_env_mock.expect(:project_id, project_id) - gcp_env_mock.expect(:knative_service_id, 'test-google-cloud-function') - gcp_env_mock.expect(:knative_service_revision, '2') - gcp_env_mock.expect(:instance_zone, 'us-central1-a') - - Socket.stub(:gethostname, 'opentelemetry-test') do - old_hostname = ENV.fetch('HOSTNAME', nil) - ENV['HOSTNAME'] = 'opentelemetry-host-name-1' - begin - Google::Cloud::Env.stub(:new, gcp_env_mock) { detected_resource } - ensure - ENV['HOSTNAME'] = old_hostname - end - end - end - - let(:expected_resource_attributes) do - { - 'cloud.provider' => 'gcp', - 'cloud.account.id' => 'opentelemetry', - 'cloud.region' => 'us-central1', - 'cloud.availability_zone' => 'us-central1-a', - 'host.id' => 'opentelemetry-test', - 'host.name' => 'opentelemetry-host-name-1', - 'k8s.cluster.name' => 'opentelemetry-cluster', - 'k8s.namespace.name' => 'default', - 'k8s.pod.name' => 'opentelemetry-host-name-1', - 'k8s.node.name' => 'opentelemetry-node-1', - 'faas.name' => 'test-google-cloud-function', - 'faas.version' => '2' - } - end - - it 'returns a resource with gcp attributes' do - _(detected_resource).must_be_instance_of(OpenTelemetry::SDK::Resources::Resource) - _(detected_resource_attributes).must_equal(expected_resource_attributes) - end - - describe 'and a nil resource value is detected' do - let(:project_id) { nil } - - it 'returns a resource without that attribute' do - _(detected_resource_attributes.key?('cloud.account.id')).must_equal(false) - end - end - - describe 'and an empty string resource value is detected' do - let(:project_id) { '' } - - it 'returns a resource without that attribute' do - _(detected_resource_attributes.key?('cloud.account.id')).must_equal(false) - end - end - end - end -end diff --git a/resource_detectors/test/test_helper.rb b/resource_detectors/test/test_helper.rb deleted file mode 100644 index aee3060a7..000000000 --- a/resource_detectors/test/test_helper.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -# Copyright The OpenTelemetry Authors -# -# SPDX-License-Identifier: Apache-2.0 - -require 'bundler/setup' -Bundler.require(:default, :development, :test) - -SimpleCov.minimum_coverage 85 -SimpleCov.start - -require 'opentelemetry-resource_detectors' -require 'minitest/autorun' -require 'webmock/minitest' - -OpenTelemetry.logger = Logger.new($stderr, level: ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym)