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/.github/workflows/ci-instrumentation-canary.yml b/.github/workflows/ci-instrumentation-canary.yml index 4dd45a722..ae32dd9bb 100644 --- a/.github/workflows/ci-instrumentation-canary.yml +++ b/.github/workflows/ci-instrumentation-canary.yml @@ -33,6 +33,7 @@ jobs: - koala - lmdb - net_http + - httpx - rack - rails - restclient diff --git a/.github/workflows/ci-instrumentation.yml b/.github/workflows/ci-instrumentation.yml index b5bacdeb2..d06fe5d5b 100644 --- a/.github/workflows/ci-instrumentation.yml +++ b/.github/workflows/ci-instrumentation.yml @@ -34,6 +34,7 @@ jobs: - gruf - http - http_client + - httpx - koala - lmdb - net_http diff --git a/.github/workflows/release-hook-on-closed.yml b/.github/workflows/release-hook-on-closed.yml index bbbcfd735..6a80f4146 100644 --- a/.github/workflows/release-hook-on-closed.yml +++ b/.github/workflows/release-hook-on-closed.yml @@ -18,7 +18,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Install Toys - run: "gem install --no-document toys" + run: "gem install --no-document toys -v 0.15.3" - name: Process release request env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-hook-on-push.yml b/.github/workflows/release-hook-on-push.yml index 1dfc480fd..d3a85043d 100644 --- a/.github/workflows/release-hook-on-push.yml +++ b/.github/workflows/release-hook-on-push.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Install Toys - run: "gem install --no-document toys" + run: "gem install --no-document toys -v 0.15.3" - name: Update open releases env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-perform.yml b/.github/workflows/release-perform.yml index 4e8b37bc6..60ebeaee5 100644 --- a/.github/workflows/release-perform.yml +++ b/.github/workflows/release-perform.yml @@ -28,7 +28,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Install Toys - run: "gem install --no-document toys" + run: "gem install --no-document toys -v 0.15.3" - name: Perform release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-request.yml b/.github/workflows/release-request.yml index 964847450..00997a9ba 100644 --- a/.github/workflows/release-request.yml +++ b/.github/workflows/release-request.yml @@ -22,7 +22,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Install Toys - run: "gem install --no-document toys" + run: "gem install --no-document toys -v 0.15.3" - name: Open release pull request env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-retry.yml b/.github/workflows/release-retry.yml index dd5c3a81c..381987aec 100644 --- a/.github/workflows/release-retry.yml +++ b/.github/workflows/release-retry.yml @@ -25,7 +25,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Install Toys - run: "gem install --no-document toys" + run: "gem install --no-document toys -v 0.15.3" - name: Retry release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.toys/.data/releases.yml b/.toys/.data/releases.yml index 8b78685f3..30d6cde6c 100644 --- a/.toys/.data/releases.yml +++ b/.toys/.data/releases.yml @@ -6,6 +6,7 @@ repo: open-telemetry/opentelemetry-ruby-contrib main_branch: main # Time in seconds for release scripts to wait for CI to complete. required_checks_timeout: 1200 +required_jobs: "^(ci|CI).*" # Git user attached to commits for release pull requests. git_user_name: Ariel Valentin git_user_email: ariel@arielvalentin.com @@ -106,6 +107,10 @@ gems: directory: instrumentation/http_client version_constant: [OpenTelemetry, Instrumentation, HttpClient, VERSION] + - name: opentelemetry-instrumentation-httpx + directory: instrumentation/httpx + version_constant: [OpenTelemetry, Instrumentation, HTTPX, VERSION] + - name: opentelemetry-instrumentation-koala directory: instrumentation/koala version_constant: [OpenTelemetry, Instrumentation, Koala, VERSION] @@ -203,11 +208,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/.toys/.toys.rb b/.toys/.toys.rb index 76d3765c5..d723a7a4a 100644 --- a/.toys/.toys.rb +++ b/.toys/.toys.rb @@ -1,7 +1,7 @@ -toys_version! "0.14.7" +toys_version! "0.15.3" load_git remote: "https://github.com/dazuma/toys.git", path: ".toys/release", as: "release", - commit: "toys/v0.14.7", + commit: "toys/v0.15.3", update: 3600 diff --git a/CODEOWNERS b/CODEOWNERS index ee9e46837..8c2435bb4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -12,7 +12,7 @@ # https://help.github.com/en/articles/about-code-owners # -* @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd +* @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle @open-telemetry/ruby-contrib-approvers resources/container/ @scbjans @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @@ -22,6 +22,8 @@ instrumentation/grape/ @muripic @fbogsany @mwear @robertlaurin @dazuma @ericmust instrumentation/graphql/ @swalkinshaw @rmosolgo @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd +instrumentation/httpx/ @HoneyryderChuck @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd + instrumentation/mongo/ @johnnyshields @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd instrumentation/racecar/ @chrisholmes @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd 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/Gemfile b/Gemfile index d39b109d8..79b6ff11e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,4 @@ source 'https://rubygems.org' gem 'rake', '~> 13.0' -gem 'rubocop', '~> 1.56.2' +gem 'rubocop', '~> 1.57.1' 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/instrumentation/action_pack/CHANGELOG.md b/instrumentation/action_pack/CHANGELOG.md index 957d32f8d..422b99960 100644 --- a/instrumentation/action_pack/CHANGELOG.md +++ b/instrumentation/action_pack/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-action_pack +### v0.7.1 / 2023-10-16 + +* FIXED: Add Rails 7.1 compatibility + ### v0.7.0 / 2023-06-05 * ADDED: Use Rack Middleware Helper diff --git a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/version.rb b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/version.rb index 0f344d159..a33cf47dd 100644 --- a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/version.rb +++ b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module ActionPack - VERSION = '0.7.0' + VERSION = '0.7.1' end end end diff --git a/instrumentation/action_view/Appraisals b/instrumentation/action_view/Appraisals index 03f29edc9..895a185d4 100644 --- a/instrumentation/action_view/Appraisals +++ b/instrumentation/action_view/Appraisals @@ -15,3 +15,7 @@ end appraise 'rails-7.0' do gem 'rails', '~> 7.0.0' end + +appraise 'rails-7.1' do + gem 'rails', '~> 7.1.0' +end diff --git a/instrumentation/action_view/CHANGELOG.md b/instrumentation/action_view/CHANGELOG.md index 2cdacb9d1..c6d8759b9 100644 --- a/instrumentation/action_view/CHANGELOG.md +++ b/instrumentation/action_view/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-action_view +### v0.6.1 / 2023-10-16 + +* FIXED: Add Rails 7.1 compatibility + ### v0.6.0 / 2023-06-05 * ADDED: Render layout for action view diff --git a/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/version.rb b/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/version.rb index 7fdbddebc..9daf5e233 100644 --- a/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/version.rb +++ b/instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module ActionView - VERSION = '0.6.0' + VERSION = '0.6.1' end end end diff --git a/instrumentation/active_job/Appraisals b/instrumentation/active_job/Appraisals index 5ebb30636..a318df014 100644 --- a/instrumentation/active_job/Appraisals +++ b/instrumentation/active_job/Appraisals @@ -4,14 +4,8 @@ # # SPDX-License-Identifier: Apache-2.0 -appraise 'activejob-6.0' do - gem 'activejob', '~> 6.0.0' -end - -appraise 'activejob-6.1' do - gem 'activejob', '~> 6.1.0' -end - -appraise 'activejob-7.0' do - gem 'activejob', '~> 7.0.0' +%w[6.0.0 6.1.0 7.0.0 7.1.0].each do |version| + appraise "activejob-#{version}" do + gem 'activejob', "~> #{version}" + end end diff --git a/instrumentation/active_job/CHANGELOG.md b/instrumentation/active_job/CHANGELOG.md index fdc4420c9..2bccc6b3a 100644 --- a/instrumentation/active_job/CHANGELOG.md +++ b/instrumentation/active_job/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-active_job +### v0.6.1 / 2023-10-16 + +* FIXED: Add Rails 7.1 compatibility + ### v0.6.0 / 2023-09-07 * FIXED: Align messaging instrumentation operation names diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb index c3f612599..973025352 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb @@ -73,7 +73,7 @@ def job_attributes(job) 'messaging.destination' => job.queue_name, 'messaging.message_id' => job.job_id, 'messaging.active_job.provider_job_id' => job.provider_job_id, - 'messaging.active_job.scheduled_at' => job.scheduled_at, + 'messaging.active_job.scheduled_at' => job.scheduled_at&.to_f, 'messaging.active_job.priority' => job.priority } diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/version.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/version.rb index 5d7f6add4..2a4dc878d 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/version.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module ActiveJob - VERSION = '0.6.0' + VERSION = '0.6.1' end end end diff --git a/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb b/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb index f2c6f996c..c5c59d95e 100644 --- a/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb +++ b/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb @@ -162,14 +162,21 @@ end end - it 'is set correctly for jobs that do wait' do + it 'records the scheduled at time for apps running Rails 7.1 and newer' do + skip 'scheduled jobs behave differently in Rails 7.1+' if ActiveJob.version < Gem::Version.new('7.1') + job = TestJob.set(wait: 0.second).perform_later - # Only the sending span is a 'scheduled' thing - _(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at) - assert(publish_span.attributes['messaging.active_job.scheduled_at']) + _(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f) + _(process_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f) + end + + it 'records the scheduled at time for apps running Rails 7.0 or older' do + skip 'scheduled jobs behave differently in Rails 7.1+' if ActiveJob.version >= Gem::Version.new('7.1') + + job = TestJob.set(wait: 0.second).perform_later - # The processing span isn't a 'scheduled' thing + _(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f) _(process_span.attributes['messaging.active_job.scheduled_at']).must_be_nil end end diff --git a/instrumentation/active_record/Appraisals b/instrumentation/active_record/Appraisals index 7a6f38c98..75952e9f4 100644 --- a/instrumentation/active_record/Appraisals +++ b/instrumentation/active_record/Appraisals @@ -15,3 +15,7 @@ end appraise 'activerecord-7.0' do gem 'activerecord', '~> 7.0.0' end + +appraise 'activerecord-7.1' do + gem 'activerecord', '~> 7.1.0' +end diff --git a/instrumentation/active_record/CHANGELOG.md b/instrumentation/active_record/CHANGELOG.md index 1d0d48f84..4896addb4 100644 --- a/instrumentation/active_record/CHANGELOG.md +++ b/instrumentation/active_record/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-active_record +### v0.6.3 / 2023-10-16 + +* FIXED: Add Rails 7.1 compatibility + ### v0.6.2 / 2023-08-14 * FIXED: Ensure that transaction name property is used, rather than self diff --git a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/version.rb b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/version.rb index add97fb06..bdd1f1083 100644 --- a/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/version.rb +++ b/instrumentation/active_record/lib/opentelemetry/instrumentation/active_record/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module ActiveRecord - VERSION = '0.6.2' + VERSION = '0.6.3' end end end diff --git a/instrumentation/active_support/Appraisals b/instrumentation/active_support/Appraisals index 9b71bf262..aaad18a9c 100644 --- a/instrumentation/active_support/Appraisals +++ b/instrumentation/active_support/Appraisals @@ -15,3 +15,7 @@ end appraise 'activesupport-7.0' do gem 'activesupport', '~> 7.0.0' end + +appraise 'activesupport-7.1' do + gem 'activesupport', '~> 7.1.0' +end diff --git a/instrumentation/active_support/CHANGELOG.md b/instrumentation/active_support/CHANGELOG.md index b2ad56d80..6254326a6 100644 --- a/instrumentation/active_support/CHANGELOG.md +++ b/instrumentation/active_support/CHANGELOG.md @@ -1,5 +1,13 @@ # Release History: opentelemetry-instrumentation-active_support +### v0.4.4 / 2023-10-31 + +* FIXED: Remove call to ActiveSupport::Notifications.notifier#synchronize deprecated in Rails 7.2 + +### v0.4.3 / 2023-10-16 + +* FIXED: Add Rails 7.1 compatibility + ### v0.4.2 / 2023-09-07 FIXED: Reduce Object allocation diff --git a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb index 72e8f04a9..e2ab1d700 100644 --- a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb +++ b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb @@ -30,19 +30,23 @@ def self.subscribe( subscriber_object = ::ActiveSupport::Notifications.subscribe(pattern, subscriber) - ::ActiveSupport::Notifications.notifier.synchronize do - subscribers = ::ActiveSupport::Notifications.notifier.instance_variable_get(:@string_subscribers)[pattern] - - if subscribers.nil? - OpenTelemetry.handle_error( - message: 'Unable to move OTEL ActiveSupport Notifications subscriber to the front of the notifications list which may cause incomplete traces.' \ - 'Please report an issue here: ' \ - 'https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues/new?labels=bug&template=bug_report.md&title=ActiveSupport%20Notifications%20subscribers%20list%20is%20nil' - ) - else - subscribers.unshift( - subscribers.delete(subscriber_object) - ) + # this can be removed once we drop support for Rails < 7.2 + # see https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/707 for more context + if ::ActiveSupport::Notifications.notifier.respond_to?(:synchronize) + ::ActiveSupport::Notifications.notifier.synchronize do + subscribers = ::ActiveSupport::Notifications.notifier.instance_variable_get(:@string_subscribers)[pattern] + + if subscribers.nil? + OpenTelemetry.handle_error( + message: 'Unable to move OTEL ActiveSupport Notifications subscriber to the front of the notifications list which may cause incomplete traces.' \ + 'Please report an issue here: ' \ + 'https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues/new?labels=bug&template=bug_report.md&title=ActiveSupport%20Notifications%20subscribers%20list%20is%20nil' + ) + else + subscribers.unshift( + subscribers.delete(subscriber_object) + ) + end end end subscriber_object diff --git a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb index bb7b408cc..96965c3e7 100644 --- a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb +++ b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module ActiveSupport - VERSION = '0.4.2' + VERSION = '0.4.4' end end end diff --git a/instrumentation/all/CHANGELOG.md b/instrumentation/all/CHANGELOG.md index c81851ebf..33399ca51 100644 --- a/instrumentation/all/CHANGELOG.md +++ b/instrumentation/all/CHANGELOG.md @@ -1,5 +1,13 @@ # Release History: opentelemetry-instrumentation-all +### v0.51.1 / 2023-10-27 + +* ADDED: Instrument connect and ping (Trilogy) + +### v0.51.0 / 2023-10-16 + +* CHANGED: See [#695](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/695) for details + ### v0.50.1 / 2023-09-07 * FIXED: Align messaging instrumentation operation names (Resque) diff --git a/instrumentation/all/lib/opentelemetry/instrumentation/all/version.rb b/instrumentation/all/lib/opentelemetry/instrumentation/all/version.rb index 038f4e9a2..0b3de5313 100644 --- a/instrumentation/all/lib/opentelemetry/instrumentation/all/version.rb +++ b/instrumentation/all/lib/opentelemetry/instrumentation/all/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module All - VERSION = '0.50.1' + VERSION = '0.51.1' end end end diff --git a/instrumentation/all/opentelemetry-instrumentation-all.gemspec b/instrumentation/all/opentelemetry-instrumentation-all.gemspec index 0bb1151ac..fabc00315 100644 --- a/instrumentation/all/opentelemetry-instrumentation-all.gemspec +++ b/instrumentation/all/opentelemetry-instrumentation-all.gemspec @@ -30,8 +30,8 @@ Gem::Specification.new do |spec| spec.add_dependency 'opentelemetry-instrumentation-aws_sdk', '~> 0.5.0' spec.add_dependency 'opentelemetry-instrumentation-bunny', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-concurrent_ruby', '~> 0.21.1' - spec.add_dependency 'opentelemetry-instrumentation-dalli', '~> 0.24.1' - spec.add_dependency 'opentelemetry-instrumentation-delayed_job', '~> 0.21.0' + spec.add_dependency 'opentelemetry-instrumentation-dalli', '~> 0.25.0' + spec.add_dependency 'opentelemetry-instrumentation-delayed_job', '~> 0.22.0' spec.add_dependency 'opentelemetry-instrumentation-ethon', '~> 0.21.1' spec.add_dependency 'opentelemetry-instrumentation-excon', '~> 0.21.1' spec.add_dependency 'opentelemetry-instrumentation-faraday', '~> 0.23.1' @@ -43,9 +43,9 @@ Gem::Specification.new do |spec| spec.add_dependency 'opentelemetry-instrumentation-koala', '~> 0.20.1' spec.add_dependency 'opentelemetry-instrumentation-lmdb', '~> 0.22.1' spec.add_dependency 'opentelemetry-instrumentation-mongo', '~> 0.22.1' - spec.add_dependency 'opentelemetry-instrumentation-mysql2', '~> 0.24.2' + spec.add_dependency 'opentelemetry-instrumentation-mysql2', '~> 0.25.0' spec.add_dependency 'opentelemetry-instrumentation-net_http', '~> 0.22.1' - spec.add_dependency 'opentelemetry-instrumentation-pg', '~> 0.25.2' + spec.add_dependency 'opentelemetry-instrumentation-pg', '~> 0.26.0' spec.add_dependency 'opentelemetry-instrumentation-que', '~> 0.7.0' spec.add_dependency 'opentelemetry-instrumentation-racecar', '~> 0.3.0' spec.add_dependency 'opentelemetry-instrumentation-rack', '~> 0.23.1' @@ -58,7 +58,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'opentelemetry-instrumentation-ruby_kafka', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-sidekiq', '~> 0.25.0' spec.add_dependency 'opentelemetry-instrumentation-sinatra', '~> 0.23.1' - spec.add_dependency 'opentelemetry-instrumentation-trilogy', '~> 0.56.1' + spec.add_dependency 'opentelemetry-instrumentation-trilogy', '~> 0.57.0' spec.add_development_dependency 'active_model_serializers' spec.add_development_dependency 'activesupport' diff --git a/instrumentation/base/opentelemetry-instrumentation-base.gemspec b/instrumentation/base/opentelemetry-instrumentation-base.gemspec index f40f75af0..98ab793c7 100644 --- a/instrumentation/base/opentelemetry-instrumentation-base.gemspec +++ b/instrumentation/base/opentelemetry-instrumentation-base.gemspec @@ -32,7 +32,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'minitest', '~> 5.0' spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3' spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rubocop', '~> 1.56.1' + spec.add_development_dependency 'rubocop', '~> 1.57.1' spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'yard', '~> 0.9' diff --git a/instrumentation/dalli/CHANGELOG.md b/instrumentation/dalli/CHANGELOG.md index 3b2e198bd..1a89d2a85 100644 --- a/instrumentation/dalli/CHANGELOG.md +++ b/instrumentation/dalli/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History: opentelemetry-instrumentation-dalli +### v0.25.0 / 2023-10-16 + +* BREAKING CHANGE: Obfuscation for mysql2, dalli and postgresql as default option for db_statement + +* ADDED: Obfuscation for mysql2, dalli and postgresql as default option for db_statement + ### v0.24.2 / 2023-07-21 * ADDED: Update `opentelemetry-common` from [0.19.3 to 0.20.0](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/537) diff --git a/instrumentation/dalli/README.md b/instrumentation/dalli/README.md index 3f0efd4c6..bf4f988fa 100644 --- a/instrumentation/dalli/README.md +++ b/instrumentation/dalli/README.md @@ -30,6 +30,22 @@ OpenTelemetry::SDK.configure do |c| end ``` +### Configuration options + +```ruby +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::Dalli', { + # You may optionally set a value for 'peer.service', which + # will be included on all spans from this instrumentation: + peer_service: '', + + # The obfuscation of query in the db.statement attribute is enabled by default. + # To disable, set db_statement to :include; to omit the query completely, set db_statement to :omit + db_statement: :include, + } +end +``` + ## How can I get involved? The `opentelemetry-instrumentation-dalli` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`. diff --git a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb index 014f38ccd..610bf5a5f 100644 --- a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb +++ b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb @@ -20,7 +20,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end option :peer_service, default: nil, validate: :string - option :db_statement, default: :include, validate: %I[omit obfuscate include] + option :db_statement, default: :obfuscate, validate: %I[omit obfuscate include] private diff --git a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb index 424f56834..a5f393b3b 100644 --- a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb +++ b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Dalli - VERSION = '0.24.2' + VERSION = '0.25.0' end end end diff --git a/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb b/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb index d426a4bf3..512ba0359 100644 --- a/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb +++ b/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb @@ -28,7 +28,7 @@ describe 'tracing' do before do - instrumentation.install + instrumentation.install(db_statement: :include) end it 'accepts peer service name from config' do diff --git a/instrumentation/delayed_job/CHANGELOG.md b/instrumentation/delayed_job/CHANGELOG.md index 67b9f9441..be2e302cb 100644 --- a/instrumentation/delayed_job/CHANGELOG.md +++ b/instrumentation/delayed_job/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History: opentelemetry-instrumentation-delayed_job +### v0.22.0 / 2023-10-16 + +* BREAKING CHANGE: Drop DelayedJob ActiveRecord in Tests + +* FIXED: Drop DelayedJob ActiveRecord in Tests + ### v0.21.0 / 2023-09-07 * FIXED: Align messaging instrumentation operation names diff --git a/instrumentation/delayed_job/lib/opentelemetry/instrumentation/delayed_job/version.rb b/instrumentation/delayed_job/lib/opentelemetry/instrumentation/delayed_job/version.rb index 989bf86fb..8f3f46f79 100644 --- a/instrumentation/delayed_job/lib/opentelemetry/instrumentation/delayed_job/version.rb +++ b/instrumentation/delayed_job/lib/opentelemetry/instrumentation/delayed_job/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module DelayedJob - VERSION = '0.21.0' + VERSION = '0.22.0' end end end diff --git a/instrumentation/faraday/CHANGELOG.md b/instrumentation/faraday/CHANGELOG.md index 6c9384049..fa06abffe 100644 --- a/instrumentation/faraday/CHANGELOG.md +++ b/instrumentation/faraday/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-faraday +### v0.23.3 / 2023-10-16 + +* FIXED: Omit `nil` `net.peer.name` attributes + ### v0.23.2 / 2023-07-21 * ADDED: Update `opentelemetry-common` from [0.19.3 to 0.20.0](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/537) diff --git a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb index be880c0ae..c6b73c3c9 100644 --- a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb +++ b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb @@ -44,9 +44,9 @@ def call(env) def span_creation_attributes(http_method:, url:) instrumentation_attrs = { 'http.method' => http_method, - 'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s), - 'net.peer.name' => url.host + 'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s) } + instrumentation_attrs['net.peer.name'] = url.host if url.host config = Faraday::Instrumentation.instance.config instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service] instrumentation_attrs.merge!( diff --git a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb index 2df7a1f27..f4cb955f3 100644 --- a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb +++ b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Faraday - VERSION = '0.23.2' + VERSION = '0.23.3' end end end diff --git a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb index f9f9617fb..417c0c367 100644 --- a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb +++ b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb @@ -42,89 +42,114 @@ instrumentation.install end - it 'has http 200 attributes' do - response = client.get('/success') - - _(span.name).must_equal 'HTTP GET' - _(span.attributes['http.method']).must_equal 'GET' - _(span.attributes['http.status_code']).must_equal 200 - _(span.attributes['http.url']).must_equal 'http://example.com/success' - _(span.attributes['net.peer.name']).must_equal 'example.com' - _(response.env.request_headers['Traceparent']).must_equal( - "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" - ) - end + describe 'given a client with a base url' do + it 'has http 200 attributes' do + response = client.get('/success') + + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.status_code']).must_equal 200 + _(span.attributes['http.url']).must_equal 'http://example.com/success' + _(span.attributes['net.peer.name']).must_equal 'example.com' + _(response.env.request_headers['Traceparent']).must_equal( + "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" + ) + end - it 'has http.status_code 404' do - response = client.get('/not_found') - - _(span.name).must_equal 'HTTP GET' - _(span.attributes['http.method']).must_equal 'GET' - _(span.attributes['http.status_code']).must_equal 404 - _(span.attributes['http.url']).must_equal 'http://example.com/not_found' - _(span.attributes['net.peer.name']).must_equal 'example.com' - _(response.env.request_headers['Traceparent']).must_equal( - "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" - ) - end + it 'has http.status_code 404' do + response = client.get('/not_found') + + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.status_code']).must_equal 404 + _(span.attributes['http.url']).must_equal 'http://example.com/not_found' + _(span.attributes['net.peer.name']).must_equal 'example.com' + _(response.env.request_headers['Traceparent']).must_equal( + "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" + ) + end - it 'has http.status_code 500' do - response = client.get('/failure') - - _(span.name).must_equal 'HTTP GET' - _(span.attributes['http.method']).must_equal 'GET' - _(span.attributes['http.status_code']).must_equal 500 - _(span.attributes['http.url']).must_equal 'http://example.com/failure' - _(span.attributes['net.peer.name']).must_equal 'example.com' - _(response.env.request_headers['Traceparent']).must_equal( - "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" - ) - end + it 'has http.status_code 500' do + response = client.get('/failure') + + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.status_code']).must_equal 500 + _(span.attributes['http.url']).must_equal 'http://example.com/failure' + _(span.attributes['net.peer.name']).must_equal 'example.com' + _(response.env.request_headers['Traceparent']).must_equal( + "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" + ) + end - it 'merges http client attributes' do - client_context_attrs = { - 'test.attribute' => 'test.value', 'http.method' => 'OVERRIDE' - } - response = OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do - client.get('/success') + it 'merges http client attributes' do + client_context_attrs = { + 'test.attribute' => 'test.value', 'http.method' => 'OVERRIDE' + } + response = OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do + client.get('/success') + end + + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'OVERRIDE' + _(span.attributes['http.status_code']).must_equal 200 + _(span.attributes['http.url']).must_equal 'http://example.com/success' + _(span.attributes['net.peer.name']).must_equal 'example.com' + _(span.attributes['test.attribute']).must_equal 'test.value' + _(response.env.request_headers['Traceparent']).must_equal( + "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" + ) end - _(span.name).must_equal 'HTTP GET' - _(span.attributes['http.method']).must_equal 'OVERRIDE' - _(span.attributes['http.status_code']).must_equal 200 - _(span.attributes['http.url']).must_equal 'http://example.com/success' - _(span.attributes['net.peer.name']).must_equal 'example.com' - _(span.attributes['test.attribute']).must_equal 'test.value' - _(response.env.request_headers['Traceparent']).must_equal( - "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" - ) - end + it 'accepts peer service name from config' do + instrumentation.instance_variable_set(:@installed, false) + instrumentation.install(peer_service: 'example:faraday') - it 'accepts peer service name from config' do - instrumentation.instance_variable_set(:@installed, false) - instrumentation.install(peer_service: 'example:faraday') + client.get('/success') - client.get('/success') + _(span.attributes['peer.service']).must_equal 'example:faraday' + end - _(span.attributes['peer.service']).must_equal 'example:faraday' - end + it 'prioritizes context attributes over config for peer service name' do + instrumentation.instance_variable_set(:@installed, false) + instrumentation.install(peer_service: 'example:faraday') - it 'prioritizes context attributes over config for peer service name' do - instrumentation.instance_variable_set(:@installed, false) - instrumentation.install(peer_service: 'example:faraday') + client_context_attrs = { 'peer.service' => 'example:custom' } + OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do + client.get('/success') + end - client_context_attrs = { 'peer.service' => 'example:custom' } - OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do - client.get('/success') + _(span.attributes['peer.service']).must_equal 'example:custom' end - _(span.attributes['peer.service']).must_equal 'example:custom' + it 'does not leak authentication credentials' do + client.run_request(:get, 'http://username:password@example.com/success', nil, {}) + + _(span.attributes['http.url']).must_equal 'http://example.com/success' + end end - it 'does not leak authentication credentials' do - client.run_request(:get, 'http://username:password@example.com/success', nil, {}) + describe 'given a client without a base url' do + let(:client) do + Faraday.new do |builder| + builder.adapter(:test) do |stub| + stub.get('/success') { |_| [200, {}, 'OK'] } + end + end + end - _(span.attributes['http.url']).must_equal 'http://example.com/success' + it 'omits missing attributes' do + response = client.get('/success') + + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.status_code']).must_equal 200 + _(span.attributes['http.url']).must_equal 'http:/success' + _(span.attributes).wont_include('net.peer.name') + _(response.env.request_headers['Traceparent']).must_equal( + "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" + ) + end end end end diff --git a/instrumentation/grape/CHANGELOG.md b/instrumentation/grape/CHANGELOG.md index f1fe30822..a6a55b96e 100644 --- a/instrumentation/grape/CHANGELOG.md +++ b/instrumentation/grape/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-grape +### v0.1.5 / 2023-10-31 + +* FIXED: Remove dependency on ActiveSupport core extensions from Grape instrumentation + ### v0.1.4 / 2023-08-02 * FIXED: Fix opentelemetry-api version constraint in grape gemspec diff --git a/instrumentation/grape/lib/opentelemetry/instrumentation/grape/event_handler.rb b/instrumentation/grape/lib/opentelemetry/instrumentation/grape/event_handler.rb index b39fafe33..7228247fc 100644 --- a/instrumentation/grape/lib/opentelemetry/instrumentation/grape/event_handler.rb +++ b/instrumentation/grape/lib/opentelemetry/instrumentation/grape/event_handler.rb @@ -96,7 +96,7 @@ def path(endpoint) version = endpoint.routes.first.options[:version] || '' prefix = endpoint.routes.first.options[:prefix]&.to_s || '' parts = [prefix, version] + namespace.split('/') + endpoint.options[:path] - parts.reject { |p| p.blank? || p.eql?('/') }.join('/').prepend('/') + parts.reject { |p| p.nil? || p.empty? || p.eql?('/') }.join('/').prepend('/') end def formatter_type(formatter) diff --git a/instrumentation/grape/lib/opentelemetry/instrumentation/grape/version.rb b/instrumentation/grape/lib/opentelemetry/instrumentation/grape/version.rb index 48400673f..4bf132dcd 100644 --- a/instrumentation/grape/lib/opentelemetry/instrumentation/grape/version.rb +++ b/instrumentation/grape/lib/opentelemetry/instrumentation/grape/version.rb @@ -8,7 +8,7 @@ module OpenTelemetry module Instrumentation module Grape # Current gem version - VERSION = '0.1.4' + VERSION = '0.1.5' end end end diff --git a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb index 26b2cf6a2..5d4111b74 100644 --- a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb +++ b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb @@ -97,8 +97,7 @@ after do # Reset various instance variables to clear state between tests - SomeOtherGraphQLAppSchema.instance_variable_set(:@own_tracers, []) - SomeOtherGraphQLAppSchema.instance_variable_set(:@own_plugins, SomeOtherGraphQLAppSchema.plugins[0..1]) + [GraphQL::Schema, SomeOtherGraphQLAppSchema, SomeGraphQLAppSchema].each(&:_reset_tracer_for_testing) end it 'traces the provided schemas' do diff --git a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_tracer_test.rb b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_tracer_test.rb index 496580bee..35e5e4b0d 100644 --- a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_tracer_test.rb +++ b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_tracer_test.rb @@ -97,13 +97,11 @@ after do # Reset various instance variables to clear state between tests - SomeOtherGraphQLAppSchema.instance_variable_set(:@own_tracers, []) - SomeOtherGraphQLAppSchema.instance_variable_set(:@own_plugins, SomeOtherGraphQLAppSchema.plugins[0..1]) + [GraphQL::Schema, SomeOtherGraphQLAppSchema, SomeGraphQLAppSchema].each(&:_reset_tracer_for_testing) end it 'traces the provided schemas' do SomeOtherGraphQLAppSchema.execute('query SimpleQuery{ __typename }') - _(spans.size).must_equal(8) end diff --git a/instrumentation/graphql/test/test_helper.rb b/instrumentation/graphql/test/test_helper.rb index 330b3d836..75f349b28 100644 --- a/instrumentation/graphql/test/test_helper.rb +++ b/instrumentation/graphql/test/test_helper.rb @@ -25,7 +25,7 @@ module SchemaTestPatches # Reseting @graphql_definition is needed for tests running against version `1.9.x` # Other variables are used by ~> 2.0.19 def _reset_tracer_for_testing - %w[own_tracers trace_modes trace_class tracers graphql_definition].each do |ivar| + %w[own_tracers trace_modes trace_class tracers graphql_definition own_trace_modes].each do |ivar| remove_instance_variable("@#{ivar}") if instance_variable_defined?("@#{ivar}") end end diff --git a/instrumentation/gruf/CHANGELOG.md b/instrumentation/gruf/CHANGELOG.md index 8cdbb4f4a..43137ffc8 100644 --- a/instrumentation/gruf/CHANGELOG.md +++ b/instrumentation/gruf/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-gruf +### v0.1.1 / 2023-10-16 + +* FIXED: Remove activesupport dependency + ### v0.1.0 / 2023-08-07 * Initial release! diff --git a/instrumentation/gruf/lib/opentelemetry/instrumentation/gruf/version.rb b/instrumentation/gruf/lib/opentelemetry/instrumentation/gruf/version.rb index 0c87d64fe..2b36b7e53 100644 --- a/instrumentation/gruf/lib/opentelemetry/instrumentation/gruf/version.rb +++ b/instrumentation/gruf/lib/opentelemetry/instrumentation/gruf/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Gruf - VERSION = '0.1.0' + VERSION = '0.1.1' end end end diff --git a/instrumentation/httpx/.yardopts b/instrumentation/httpx/.yardopts new file mode 100644 index 000000000..66530b20f --- /dev/null +++ b/instrumentation/httpx/.yardopts @@ -0,0 +1,9 @@ +--no-private +--title=OpenTelemetry HTTPX Instrumentation +--markup=markdown +--main=README.md +./lib/opentelemetry/instrumentation/**/*.rb +./lib/opentelemetry/instrumentation.rb +- +README.md +CHANGELOG.md diff --git a/instrumentation/httpx/Appraisals b/instrumentation/httpx/Appraisals new file mode 100644 index 000000000..6d5b4793c --- /dev/null +++ b/instrumentation/httpx/Appraisals @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +appraise 'httpx-1' do + gem 'httpx', '~> 1.0' +end + +appraise 'httpx-0' do + gem 'httpx', '~> 0.24' +end diff --git a/instrumentation/httpx/CHANGELOG.md b/instrumentation/httpx/CHANGELOG.md new file mode 100644 index 000000000..8f13d82f7 --- /dev/null +++ b/instrumentation/httpx/CHANGELOG.md @@ -0,0 +1,5 @@ +# Release History: opentelemetry-instrumentation-httpx + +### v0.1.0 / 2023-11-06 + +* Initial Release. diff --git a/resource_detectors/Gemfile b/instrumentation/httpx/Gemfile similarity index 57% rename from resource_detectors/Gemfile rename to instrumentation/httpx/Gemfile index 6ae9e48bc..8b038cdcb 100644 --- a/resource_detectors/Gemfile +++ b/instrumentation/httpx/Gemfile @@ -8,7 +8,7 @@ source 'https://rubygems.org' gemspec -group :development, :test do - gem 'byebug' unless RUBY_PLATFORM == 'java' - gem 'pry' +group :test do + gem 'opentelemetry-instrumentation-base', path: '../base' + gem 'pry-byebug', platform: 'ruby' end diff --git a/resource_detectors/LICENSE b/instrumentation/httpx/LICENSE similarity index 100% rename from resource_detectors/LICENSE rename to instrumentation/httpx/LICENSE diff --git a/instrumentation/httpx/README.md b/instrumentation/httpx/README.md new file mode 100644 index 000000000..2053e8ab1 --- /dev/null +++ b/instrumentation/httpx/README.md @@ -0,0 +1,49 @@ +# OpenTelemetry Http Instrumentation + +The HTTPX instrumentation is a community-maintained instrumentation for the [HTTPX][httpx-home] gem. + +## How do I get started? + +Install the gem using: + +``` +gem install opentelemetry-instrumentation-httpx +``` + +Or, if you use [bundler][bundler-home], include `opentelemetry-instrumentation-httpx` in your `Gemfile`. + +## Usage + +To use the instrumentation, call `use` with the name of the instrumentation: + +```ruby +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::HTTPX' +end +``` + +Alternatively, you can also call `use_all` to install all the available instrumentation. + +```ruby +OpenTelemetry::SDK.configure do |c| + c.use_all +end +``` + +## How can I get involved? + +The `opentelemetry-instrumentation-httpx` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`. + +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][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig]. + +## License + +The `opentelemetry-instrumentation-httpx` gem is distributed under the Apache 2.0 license. See [LICENSE][license-github] for more information. + +[http-home]: https://gitlab.com/os85/httpx +[bundler-home]: https://bundler.io +[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby +[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE +[ruby-sig]: https://github.com/open-telemetry/community#ruby-sig +[community-meetings]: https://github.com/open-telemetry/community#community-meetings +[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions diff --git a/resource_detectors/Rakefile b/instrumentation/httpx/Rakefile similarity index 100% rename from resource_detectors/Rakefile rename to instrumentation/httpx/Rakefile diff --git a/instrumentation/httpx/example/trace_demonstration.rb b/instrumentation/httpx/example/trace_demonstration.rb new file mode 100644 index 000000000..f0afdbf11 --- /dev/null +++ b/instrumentation/httpx/example/trace_demonstration.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'bundler/inline' + +gemfile(true) do + source 'https://rubygems.org' + gem 'opentelemetry-api' + gem 'opentelemetry-instrumentation-base' + gem 'opentelemetry-instrumentation-httpx' + gem 'opentelemetry-sdk' + gem 'httpx' +end + +require 'opentelemetry-api' +require 'opentelemetry-sdk' +require 'opentelemetry-instrumentation-httpx' +require 'httpx' + +# Export traces to console by default +ENV['OTEL_TRACES_EXPORTER'] ||= 'console' + +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::HTTPX' +end + +# A basic HTTP example +HTTPX.get('https://github.com') diff --git a/resource_detectors/lib/opentelemetry-resource_detectors.rb b/instrumentation/httpx/lib/opentelemetry-instrumentation-httpx.rb similarity index 67% rename from resource_detectors/lib/opentelemetry-resource_detectors.rb rename to instrumentation/httpx/lib/opentelemetry-instrumentation-httpx.rb index c84a217e4..c034f140f 100644 --- a/resource_detectors/lib/opentelemetry-resource_detectors.rb +++ b/instrumentation/httpx/lib/opentelemetry-instrumentation-httpx.rb @@ -4,4 +4,4 @@ # # SPDX-License-Identifier: Apache-2.0 -require_relative 'opentelemetry/resource/detectors' +require_relative 'opentelemetry/instrumentation' diff --git a/resource_detectors/lib/opentelemetry/resource/detectors.rb b/instrumentation/httpx/lib/opentelemetry/instrumentation.rb similarity index 52% rename from resource_detectors/lib/opentelemetry/resource/detectors.rb rename to instrumentation/httpx/lib/opentelemetry/instrumentation.rb index 78494b65a..b9459a853 100644 --- a/resource_detectors/lib/opentelemetry/resource/detectors.rb +++ b/instrumentation/httpx/lib/opentelemetry/instrumentation.rb @@ -4,12 +4,6 @@ # # 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. @@ -17,10 +11,9 @@ # 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 + # Instrumentation should be able to handle the case when the library is not installed on a user's system. + module Instrumentation end end + +require_relative 'instrumentation/httpx' diff --git a/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx.rb b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx.rb new file mode 100644 index 000000000..70e00f6cc --- /dev/null +++ b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'opentelemetry' +require 'opentelemetry-instrumentation-base' + +module OpenTelemetry + module Instrumentation + # Contains the OpenTelemetry instrumentation for the Http gem + module HTTPX + end + end +end + +require_relative 'httpx/instrumentation' +require_relative 'httpx/version' diff --git a/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/instrumentation.rb b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/instrumentation.rb new file mode 100644 index 000000000..9174343b4 --- /dev/null +++ b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/instrumentation.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Instrumentation + module HTTPX + # The Instrumentation class contains logic to detect and install the Http instrumentation + class Instrumentation < OpenTelemetry::Instrumentation::Base + install do |_config| + require_dependencies + patch + end + + compatible do + Gem::Version.new(::HTTPX::VERSION) >= Gem::Version.new('0.24.7') + end + + present do + defined?(::HTTPX) + end + + option :peer_service, default: nil, validate: :string + + def patch + otel_session = ::HTTPX.plugin(Plugin) + + ::HTTPX.send(:remove_const, :Session) + ::HTTPX.send(:const_set, :Session, otel_session.class) + end + + def require_dependencies + require_relative 'plugin' + end + end + end + end +end diff --git a/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/plugin.rb b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/plugin.rb new file mode 100644 index 000000000..10738e1ed --- /dev/null +++ b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/plugin.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Instrumentation + module HTTPX + module Plugin + # Instruments around HTTPX's request/response lifecycle in order to generate + # an OTEL trace. + class RequestTracer + def initialize(request) + @request = request + end + + def call + @request.on(:response, &method(:finish)) + + uri = @request.uri + request_method = @request.verb + span_name = "HTTP #{request_method}" + + attributes = { + OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => uri.host, + OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => request_method, + OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme, + OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path, + OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}", + OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => uri.host, + OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => uri.port + } + config = HTTPX::Instrumentation.instance.config + attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service] + attributes.merge!( + OpenTelemetry::Common::HTTP::ClientContext.attributes + ) + + @span = tracer.start_span(span_name, attributes: attributes, kind: :client) + trace_ctx = OpenTelemetry::Trace.context_with_span(@span) + @trace_token = OpenTelemetry::Context.attach(trace_ctx) + + OpenTelemetry.propagation.inject(@request.headers) + rescue StandardError => e + OpenTelemetry.handle_error(exception: e) + end + + def finish(response) + return unless @span + + if response.is_a?(::HTTPX::ErrorResponse) + @span.record_exception(response.error) + @span.status = Trace::Status.error("Unhandled exception of type: #{response.error.class}") + else + @span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, response.status) + @span.status = Trace::Status.error unless (100..399).include?(response.status) + end + + OpenTelemetry::Context.detach(@trace_token) if @trace_token + @span.finish + end + + private + + def tracer + HTTPX::Instrumentation.instance.tracer + end + end + + # HTTPX::Request overrides + module RequestMethods + def __otel_enable_trace! + return if @__otel_enable_trace + + RequestTracer.new(self).call + @__otel_enable_trace = true + end + end + + # HTTPX::Connection overrides + module ConnectionMethods + def send(request) + request.__otel_enable_trace! + + super + end + end + end + end + end +end diff --git a/resource_detectors/lib/opentelemetry/resource/detectors/version.rb b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/version.rb similarity index 69% rename from resource_detectors/lib/opentelemetry/resource/detectors/version.rb rename to instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/version.rb index d500bc012..b05472d1e 100644 --- a/resource_detectors/lib/opentelemetry/resource/detectors/version.rb +++ b/instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/version.rb @@ -5,9 +5,9 @@ # SPDX-License-Identifier: Apache-2.0 module OpenTelemetry - module Resource - module Detectors - VERSION = '0.24.2' + module Instrumentation + module HTTPX + VERSION = '0.1.0' end end end diff --git a/resource_detectors/opentelemetry-resource_detectors.gemspec b/instrumentation/httpx/opentelemetry-instrumentation-httpx.gemspec similarity index 61% rename from resource_detectors/opentelemetry-resource_detectors.gemspec rename to instrumentation/httpx/opentelemetry-instrumentation-httpx.gemspec index 0f6eb3693..6531619a7 100644 --- a/resource_detectors/opentelemetry-resource_detectors.gemspec +++ b/instrumentation/httpx/opentelemetry-instrumentation-httpx.gemspec @@ -6,16 +6,16 @@ lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'opentelemetry/resource/detectors/version' +require 'opentelemetry/instrumentation/httpx/version' Gem::Specification.new do |spec| - spec.name = 'opentelemetry-resource_detectors' - spec.version = OpenTelemetry::Resource::Detectors::VERSION + spec.name = 'opentelemetry-instrumentation-httpx' + spec.version = OpenTelemetry::Instrumentation::HTTPX::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.summary = 'HTTPX instrumentation for the OpenTelemetry framework' + spec.description = 'HTTPX instrumentation for the OpenTelemetry framework' spec.homepage = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib' spec.license = 'Apache-2.0' @@ -25,23 +25,25 @@ Gem::Specification.new do |spec| 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_dependency 'opentelemetry-api', '~> 1.0' + spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' + spec.add_development_dependency 'appraisal', '~> 2.5' spec.add_development_dependency 'bundler', '~> 2.4' + spec.add_development_dependency 'httpx' spec.add_development_dependency 'minitest', '~> 5.0' + spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1' + spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3' spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec-mocks' spec.add_development_dependency 'rubocop', '~> 1.56.1' - spec.add_development_dependency 'simplecov', '~> 0.17' + spec.add_development_dependency 'simplecov', '~> 0.17.1' 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['source_code_uri'] = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/http' 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 diff --git a/instrumentation/httpx/test/instrumentation/httpx/instrumentation_test.rb b/instrumentation/httpx/test/instrumentation/httpx/instrumentation_test.rb new file mode 100644 index 000000000..70dda9013 --- /dev/null +++ b/instrumentation/httpx/test/instrumentation/httpx/instrumentation_test.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'test_helper' + +require_relative '../../../lib/opentelemetry/instrumentation/httpx' + +describe OpenTelemetry::Instrumentation::HTTPX do + let(:instrumentation) { OpenTelemetry::Instrumentation::HTTPX::Instrumentation.instance } + + it 'has #name' do + _(instrumentation.name).must_equal 'OpenTelemetry::Instrumentation::HTTPX' + end + + it 'has #version' do + _(instrumentation.version).wont_be_nil + _(instrumentation.version).wont_be_empty + end + + describe '#install' do + it 'accepts argument' do + _(instrumentation.install({})).must_equal(true) + end + end +end diff --git a/instrumentation/httpx/test/instrumentation/plugin_test.rb b/instrumentation/httpx/test/instrumentation/plugin_test.rb new file mode 100644 index 000000000..585e8f50f --- /dev/null +++ b/instrumentation/httpx/test/instrumentation/plugin_test.rb @@ -0,0 +1,139 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'test_helper' + +require_relative '../../lib/opentelemetry/instrumentation/httpx' +require_relative '../../lib/opentelemetry/instrumentation/httpx/plugin' + +describe OpenTelemetry::Instrumentation::HTTPX::Plugin do + let(:instrumentation) { OpenTelemetry::Instrumentation::HTTPX::Instrumentation.instance } + let(:exporter) { EXPORTER } + let(:span) { exporter.finished_spans.first } + + before do + exporter.reset + stub_request(:get, 'http://example.com/success').to_return(status: 200) + stub_request(:get, 'http://example.com/failure').to_return(status: 500) + stub_request(:get, 'http://example.com/timeout').to_timeout + end + + # Force re-install of instrumentation + after { instrumentation.instance_variable_set(:@installed, false) } + + describe 'tracing' do + before do + instrumentation.install + end + + it 'before request' do + _(exporter.finished_spans.size).must_equal 0 + end + + it 'after request with success code' do + HTTPX.get('http://example.com/success') + + _(exporter.finished_spans.size).must_equal 1 + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.status_code']).must_equal 200 + _(span.attributes['http.scheme']).must_equal 'http' + _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.target']).must_equal '/success' + assert_requested( + :get, + 'http://example.com/success', + headers: { 'Traceparent' => "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" } + ) + end + + it 'after request with failure code' do + HTTPX.get('http://example.com/failure') + + _(exporter.finished_spans.size).must_equal 1 + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.status_code']).must_equal 500 + _(span.attributes['http.scheme']).must_equal 'http' + _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.target']).must_equal '/failure' + assert_requested( + :get, + 'http://example.com/failure', + headers: { 'Traceparent' => "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" } + ) + end + + it 'after request timeout' do + response = HTTPX.get('http://example.com/timeout') + assert response.is_a?(HTTPX::ErrorResponse) + assert response.error.is_a?(HTTPX::TimeoutError) + + _(exporter.finished_spans.size).must_equal 1 + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'GET' + _(span.attributes['http.scheme']).must_equal 'http' + _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.target']).must_equal '/timeout' + _(span.status.code).must_equal( + OpenTelemetry::Trace::Status::ERROR + ) + _(span.status.description).must_equal( + 'Unhandled exception of type: HTTPX::TimeoutError' + ) + assert_requested( + :get, + 'http://example.com/timeout', + headers: { 'Traceparent' => "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" } + ) + end + + it 'merges HTTP client context' do + client_context_attrs = { + 'test.attribute' => 'test.value', 'http.method' => 'OVERRIDE' + } + + OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do + HTTPX.get('http://example.com/success') + end + + _(exporter.finished_spans.size).must_equal 1 + _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.method']).must_equal 'OVERRIDE' + _(span.attributes['http.status_code']).must_equal 200 + _(span.attributes['http.scheme']).must_equal 'http' + _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.target']).must_equal '/success' + _(span.attributes['test.attribute']).must_equal 'test.value' + assert_requested( + :get, + 'http://example.com/success', + headers: { 'Traceparent' => "00-#{span.hex_trace_id}-#{span.hex_span_id}-01" } + ) + end + + it 'accepts peer service name from config' do + instrumentation.instance_variable_set(:@installed, false) + instrumentation.install(peer_service: 'example:httpx') + + HTTPX.get('http://example.com/success') + + _(span.attributes['peer.service']).must_equal 'example:httpx' + end + + it 'prioritizes context attributes over config for peer service name' do + instrumentation.instance_variable_set(:@installed, false) + instrumentation.install(peer_service: 'example:static') + + client_context_attrs = { 'peer.service' => 'example:custom' } + OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do + HTTPX.get('http://example.com/success') + end + + _(span.attributes['peer.service']).must_equal 'example:custom' + end + end +end diff --git a/instrumentation/httpx/test/test_helper.rb b/instrumentation/httpx/test/test_helper.rb new file mode 100644 index 000000000..10c09f2da --- /dev/null +++ b/instrumentation/httpx/test/test_helper.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'bundler/setup' +Bundler.require(:default, :development, :test) + +require 'minitest/autorun' +require 'httpx/adapters/webmock' +require 'webmock/minitest' + +# global opentelemetry-sdk setup: +EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new +span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER) + +OpenTelemetry::SDK.configure do |c| + c.error_handler = ->(exception:, message:) { raise(exception || message) } + c.logger = Logger.new($stderr, level: ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym) + c.add_span_processor span_processor +end diff --git a/instrumentation/mysql2/CHANGELOG.md b/instrumentation/mysql2/CHANGELOG.md index 4b56ee1a2..c27f08105 100644 --- a/instrumentation/mysql2/CHANGELOG.md +++ b/instrumentation/mysql2/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History: opentelemetry-instrumentation-mysql2 +### v0.25.0 / 2023-10-16 + +* BREAKING CHANGE: Obfuscation for mysql2, dalli and postgresql as default option for db_statement + +* ADDED: Obfuscation for mysql2, dalli and postgresql as default option for db_statement + ### v0.24.3 / 2023-08-03 * FIXED: Remove inline linter rules diff --git a/instrumentation/mysql2/README.md b/instrumentation/mysql2/README.md index 66af9c6bb..7ba249e74 100644 --- a/instrumentation/mysql2/README.md +++ b/instrumentation/mysql2/README.md @@ -46,9 +46,9 @@ end ```ruby OpenTelemetry::SDK.configure do |c| c.use 'OpenTelemetry::Instrumentation::Mysql2', { - # The obfuscation of SQL in the db.statement attribute is disabled by default. - # To enable, set db_statement to :obfuscate. - db_statement: :obfuscate, + # The obfuscation of SQL in the db.statement attribute is enabled by default. + # To disable, set db_statement to :include; to omit the query completely, set db_statement to :omit + db_statement: :include, } end ``` diff --git a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb index 3e85c3ff3..9a7b78ccb 100644 --- a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb +++ b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb @@ -20,7 +20,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end option :peer_service, default: nil, validate: :string - option :db_statement, default: :include, validate: %I[omit include obfuscate] + option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate] option :span_name, default: :statement_type, validate: %I[statement_type db_name db_operation_and_name] option :obfuscation_limit, default: 2000, validate: :integer diff --git a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/version.rb b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/version.rb index 8c5258e97..cfc7c95f6 100644 --- a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/version.rb +++ b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Mysql2 - VERSION = '0.24.3' + VERSION = '0.25.0' end end end diff --git a/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb b/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb index e363980c7..6eb1ada72 100644 --- a/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb +++ b/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb @@ -22,7 +22,7 @@ let(:instrumentation) { OpenTelemetry::Instrumentation::Mysql2::Instrumentation.instance } let(:exporter) { EXPORTER } let(:span) { exporter.finished_spans.first } - let(:config) { {} } + let(:config) { { db_statement: :include } } before do exporter.reset diff --git a/instrumentation/pg/CHANGELOG.md b/instrumentation/pg/CHANGELOG.md index a85f110f6..f5d811f66 100644 --- a/instrumentation/pg/CHANGELOG.md +++ b/instrumentation/pg/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History: opentelemetry-instrumentation-pg +### v0.26.0 / 2023-10-16 + +* BREAKING CHANGE: Obfuscation for mysql2, dalli and postgresql as default option for db_statement + +* ADDED: Obfuscation for mysql2, dalli and postgresql as default option for db_statement + ### v0.25.3 / 2023-07-29 * FIXED: Pass block explicitly in `define_method` calls for PG instrumentation query methods diff --git a/instrumentation/pg/README.md b/instrumentation/pg/README.md index a9261dce6..12c4c167d 100644 --- a/instrumentation/pg/README.md +++ b/instrumentation/pg/README.md @@ -50,9 +50,9 @@ OpenTelemetry::SDK.configure do |c| # will be included on all spans from this instrumentation: peer_service: 'postgres:readonly', - # By default, this instrumentation includes the executed SQL as the `db.statement` + # By default, this instrumentation obfuscate/sanitize the executed SQL as the `db.statement` # semantic attribute. Optionally, you may disable the inclusion of this attribute entirely by - # setting this option to :omit or sanitize the attribute by setting to :obfuscate + # setting this option to :omit or disbale sanitization the attribute by setting to :include db_statement: :include, } end diff --git a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb index bf6a4dcdc..2eeb6ac66 100644 --- a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb +++ b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb @@ -25,7 +25,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end option :peer_service, default: nil, validate: :string - option :db_statement, default: :include, validate: %I[omit include obfuscate] + option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate] option :obfuscation_limit, default: 2000, validate: :integer private diff --git a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/version.rb b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/version.rb index 7e5b54983..35f70e60f 100644 --- a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/version.rb +++ b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module PG - VERSION = '0.25.3' + VERSION = '0.26.0' end end end diff --git a/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb b/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb index 57bef4797..32dedf646 100644 --- a/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb +++ b/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb @@ -51,7 +51,7 @@ let(:user) { ENV.fetch('TEST_POSTGRES_USER', 'postgres') } let(:dbname) { ENV.fetch('TEST_POSTGRES_DB', 'postgres') } let(:password) { ENV.fetch('TEST_POSTGRES_PASSWORD', 'postgres') } - + let(:config) { { db_statement: :include } } before do instrumentation.install(config) end diff --git a/instrumentation/rails/Appraisals b/instrumentation/rails/Appraisals index 03f29edc9..895a185d4 100644 --- a/instrumentation/rails/Appraisals +++ b/instrumentation/rails/Appraisals @@ -15,3 +15,7 @@ end appraise 'rails-7.0' do gem 'rails', '~> 7.0.0' end + +appraise 'rails-7.1' do + gem 'rails', '~> 7.1.0' +end diff --git a/instrumentation/rails/CHANGELOG.md b/instrumentation/rails/CHANGELOG.md index 2ff2b00e9..09c338f0f 100644 --- a/instrumentation/rails/CHANGELOG.md +++ b/instrumentation/rails/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-rails +### v0.28.1 / 2023-10-16 + +* FIXED: Add Rails 7.1 compatibility + ### v0.28.0 / 2023-09-07 * FIXED: Align messaging instrumentation operation names diff --git a/instrumentation/rails/lib/opentelemetry/instrumentation/rails/version.rb b/instrumentation/rails/lib/opentelemetry/instrumentation/rails/version.rb index f5d46002f..a53ef0c6c 100644 --- a/instrumentation/rails/lib/opentelemetry/instrumentation/rails/version.rb +++ b/instrumentation/rails/lib/opentelemetry/instrumentation/rails/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Rails - VERSION = '0.28.0' + VERSION = '0.28.1' end end end diff --git a/instrumentation/trilogy/CHANGELOG.md b/instrumentation/trilogy/CHANGELOG.md index f2da9da4d..1cd9e405d 100644 --- a/instrumentation/trilogy/CHANGELOG.md +++ b/instrumentation/trilogy/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-trilogy +### v0.57.0 / 2023-10-27 + +* ADDED: Instrument connect and ping + ### v0.56.3 / 2023-08-03 * FIXED: Remove inline linter rules diff --git a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb index 1efccd029..9858d5981 100644 --- a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb +++ b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb @@ -48,6 +48,28 @@ module Client # rubocop:disable Metrics/ModuleLength FULL_SQL_REGEXP = Regexp.union(MYSQL_COMPONENTS.map { |component| COMPONENTS_REGEX_MAP[component] }) + def initialize(options = {}) + @connection_options = options # This is normally done by Trilogy#initialize + + tracer.in_span( + 'connect', + attributes: client_attributes.merge!(OpenTelemetry::Instrumentation::Trilogy.attributes), + kind: :client + ) do + super + end + end + + def ping(...) + tracer.in_span( + 'ping', + attributes: client_attributes.merge!(OpenTelemetry::Instrumentation::Trilogy.attributes), + kind: :client + ) do + super + end + end + def query(sql) tracer.in_span( database_span_name(sql), @@ -60,10 +82,10 @@ def query(sql) private - def client_attributes(sql) + def client_attributes(sql = nil) attributes = { ::OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM => 'mysql', - ::OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => connection_options.fetch(:host, 'unknown sock') + ::OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => connection_options&.fetch(:host, 'unknown sock') || 'unknown sock' } attributes[::OpenTelemetry::SemanticConventions::Trace::DB_NAME] = database_name if database_name @@ -71,11 +93,13 @@ def client_attributes(sql) attributes[::OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] unless config[:peer_service].nil? attributes['db.mysql.instance.address'] = @connected_host if defined?(@connected_host) - case config[:db_statement] - when :obfuscate - attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = obfuscate_sql(sql) - when :include - attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = sql + if sql + case config[:db_statement] + when :obfuscate + attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = obfuscate_sql(sql) + when :include + attributes[::OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT] = sql + end end attributes diff --git a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/version.rb b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/version.rb index 8d71c1ee3..a88022366 100644 --- a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/version.rb +++ b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Trilogy - VERSION = '0.56.3' + VERSION = '0.57.0' end end end diff --git a/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb b/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb index 1e395f03f..b4cf1e6d7 100644 --- a/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb +++ b/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb @@ -12,7 +12,7 @@ describe OpenTelemetry::Instrumentation::Trilogy do let(:instrumentation) { OpenTelemetry::Instrumentation::Trilogy::Instrumentation.instance } let(:exporter) { EXPORTER } - let(:span) { exporter.finished_spans.first } + let(:span) { exporter.finished_spans[1] } let(:config) { {} } let(:driver_options) do { @@ -166,6 +166,37 @@ end end + describe 'when connecting' do + let(:span) { exporter.finished_spans.first } + + it 'spans will include database name' do + _(client.connected_host).wont_be_nil + + _(span.name).must_equal 'connect' + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_NAME]).must_equal(database) + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_USER]).must_equal(username) + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql' + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal(host) + _(span.attributes['db.mysql.instance.address']).must_be_nil + end + end + + describe 'when pinging' do + let(:span) { exporter.finished_spans[2] } + + it 'spans will include database name' do + _(client.connected_host).wont_be_nil + + client.ping + + _(span.name).must_equal 'ping' + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_NAME]).must_equal(database) + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_USER]).must_equal(username) + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql' + _(span.attributes[OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME]).must_equal(host) + end + end + describe 'when quering for the connected host' do it 'spans will include the net.peer.name attribute' do _(client.connected_host).wont_be_nil diff --git a/propagator/ottrace/opentelemetry-propagator-ottrace.gemspec b/propagator/ottrace/opentelemetry-propagator-ottrace.gemspec index 7e4c36003..cacacdd6c 100644 --- a/propagator/ottrace/opentelemetry-propagator-ottrace.gemspec +++ b/propagator/ottrace/opentelemetry-propagator-ottrace.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |spec| 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.56.1' + spec.add_development_dependency 'rubocop', '~> 1.57.1' spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'yard', '~> 0.9' diff --git a/propagator/xray/opentelemetry-propagator-xray.gemspec b/propagator/xray/opentelemetry-propagator-xray.gemspec index b5fb7b330..66da780a5 100644 --- a/propagator/xray/opentelemetry-propagator-xray.gemspec +++ b/propagator/xray/opentelemetry-propagator-xray.gemspec @@ -31,7 +31,7 @@ Gem::Specification.new do |spec| 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.56.1' + spec.add_development_dependency 'rubocop', '~> 1.57.1' spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'yard', '~> 0.9' 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/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/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/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)