From b8eaddb9467282aedc29d3f32412266f6b01fdf4 Mon Sep 17 00:00:00 2001 From: __stan__ Date: Sun, 21 Nov 2021 03:52:19 +0800 Subject: [PATCH] Feat add manticore instrumentation (#3) * initial code complete * chore: fix tests for sidekiq to support inline lua changes (#1011) * chore: fix tests for sidekiq to support inline lua changes to redis calls * chore: add additional sidekiq appraisal * feat: add dalli obfuscation for db_statement (#1013) * feat: add dalli obfuscation for db_statement * chore: linting * Link to website spec pages (#1018) Co-authored-by: Matthew Wear * Feat: Add custom getters to common (#1006) Co-authored-by: Matthew Wear Co-authored-by: Eric Mustin Co-authored-by: Patrice Chalin Co-authored-by: Matthew Wear Co-authored-by: Robert --- common/lib/opentelemetry/common.rb | 1 + .../lib/opentelemetry/common/propagation.rb | 33 +++ .../common/propagation/rack_env_getter.rb | 48 +++++ .../common/propagation/symbol_key_getter.rb | 26 +++ .../propagation/rack_env_getter_test.rb | 45 ++++ .../propagation/symbol_key_getter_test.rb | 24 +++ .../instrumentation/dalli/instrumentation.rb | 2 +- .../instrumentation/dalli/patches/server.rb | 7 +- .../dalli/instrumentation_test.rb | 11 + instrumentation/manticore/.rubocop.yml | 5 + instrumentation/manticore/.yardopts | 9 + instrumentation/manticore/CHANGELOG.md | 1 + instrumentation/manticore/Gemfile | 17 ++ instrumentation/manticore/LICENSE | 201 ++++++++++++++++++ instrumentation/manticore/README.md | 56 +++++ instrumentation/manticore/Rakefile | 28 +++ instrumentation/manticore/example/Gemfile | 9 + .../manticore/example/manticore.rb | 38 ++++ ...opentelemetry-instrumentation-manticore.rb | 7 + .../lib/opentelemetry/instrumentation.rb | 22 ++ .../instrumentation/manticore.rb | 19 ++ .../manticore/instrumentation.rb | 43 ++++ .../manticore/patches/response.rb | 103 +++++++++ .../manticore/util/wrapped_request.rb | 50 +++++ .../manticore/util/wrapped_response.rb | 37 ++++ .../instrumentation/manticore/version.rb | 13 ++ ...elemetry-instrumentation-manticore.gemspec | 49 +++++ instrumentation/manticore/test/.rubocop.yml | 4 + .../manticore/instrumentation_test.rb | 108 ++++++++++ instrumentation/manticore/test/test_helper.rb | 20 ++ instrumentation/sidekiq/Appraisals | 4 + .../sidekiq/patches/poller_test.rb | 3 +- website_docs/getting_started.md | 2 +- website_docs/manual_instrumentation.md | 7 +- 34 files changed, 1045 insertions(+), 7 deletions(-) create mode 100644 common/lib/opentelemetry/common/propagation.rb create mode 100644 common/lib/opentelemetry/common/propagation/rack_env_getter.rb create mode 100644 common/lib/opentelemetry/common/propagation/symbol_key_getter.rb create mode 100644 common/test/opentelemetry/common/propagation/rack_env_getter_test.rb create mode 100644 common/test/opentelemetry/common/propagation/symbol_key_getter_test.rb create mode 100644 instrumentation/manticore/.rubocop.yml create mode 100644 instrumentation/manticore/.yardopts create mode 100644 instrumentation/manticore/CHANGELOG.md create mode 100644 instrumentation/manticore/Gemfile create mode 100644 instrumentation/manticore/LICENSE create mode 100644 instrumentation/manticore/README.md create mode 100644 instrumentation/manticore/Rakefile create mode 100644 instrumentation/manticore/example/Gemfile create mode 100644 instrumentation/manticore/example/manticore.rb create mode 100644 instrumentation/manticore/lib/opentelemetry-instrumentation-manticore.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation/manticore.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/instrumentation.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/patches/response.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_request.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_response.rb create mode 100644 instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/version.rb create mode 100644 instrumentation/manticore/opentelemetry-instrumentation-manticore.gemspec create mode 100644 instrumentation/manticore/test/.rubocop.yml create mode 100644 instrumentation/manticore/test/opentelemetry/instrumentation/manticore/instrumentation_test.rb create mode 100644 instrumentation/manticore/test/test_helper.rb diff --git a/common/lib/opentelemetry/common.rb b/common/lib/opentelemetry/common.rb index f8127ee57d..8141cc9ff6 100644 --- a/common/lib/opentelemetry/common.rb +++ b/common/lib/opentelemetry/common.rb @@ -6,6 +6,7 @@ require 'opentelemetry' require 'opentelemetry/common/http' +require 'opentelemetry/common/propagation' require 'opentelemetry/common/utilities' require 'opentelemetry/common/version' diff --git a/common/lib/opentelemetry/common/propagation.rb b/common/lib/opentelemetry/common/propagation.rb new file mode 100644 index 0000000000..35d1d11c5d --- /dev/null +++ b/common/lib/opentelemetry/common/propagation.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require_relative './propagation/rack_env_getter' +require_relative './propagation/symbol_key_getter' + +module OpenTelemetry + module Common + # Propagation contains common helpers for context propagation. + module Propagation + extend self + + RACK_ENV_GETTER = RackEnvGetter.new + SYMBOL_KEY_GETTER = SymbolKeyGetter.new + private_constant :RACK_ENV_GETTER, :SYMBOL_KEY_GETTER + + # Returns a {RackEnvGetter} instance suitable for reading values from a + # Rack environment. + def rack_env_getter + RACK_ENV_GETTER + end + + # Returns a {SymbolKeyGetter} instance for reading values from a + # symbol keyed hash. + def symbol_key_getter + SYMBOL_KEY_GETTER + end + end + end +end diff --git a/common/lib/opentelemetry/common/propagation/rack_env_getter.rb b/common/lib/opentelemetry/common/propagation/rack_env_getter.rb new file mode 100644 index 0000000000..a6be221964 --- /dev/null +++ b/common/lib/opentelemetry/common/propagation/rack_env_getter.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Common + module Propagation + # The RackEnvGetter class provides a common methods for reading + # keys from a rack environment. It abstracts away the rack-normalization + # process so that keys can be looked up without having to transform them + # first. With this class you can get +traceparent+ instead of + # +HTTP_TRACEPARENT+ + class RackEnvGetter + # Converts key into a rack-normalized key and reads it from the carrier. + # Useful for extract operations. + def get(carrier, key) + carrier[to_rack_key(key)] || carrier[key] + end + + # Reads all keys from a carrier and converts them from the rack-normalized + # form to the original. The resulting keys will be lowercase and + # underscores will be replaced with dashes. + def keys(carrier) + carrier.keys.map(&method(:from_rack_key)) + end + + private + + def to_rack_key(key) + ret = 'HTTP_' + key + ret.tr!('-', '_') + ret.upcase! + ret + end + + def from_rack_key(key) + start = key.start_with?('HTTP_') ? 5 : 0 + ret = key[start..-1] + ret.tr!('_', '-') + ret.downcase! + ret + end + end + end + end +end diff --git a/common/lib/opentelemetry/common/propagation/symbol_key_getter.rb b/common/lib/opentelemetry/common/propagation/symbol_key_getter.rb new file mode 100644 index 0000000000..02300d1050 --- /dev/null +++ b/common/lib/opentelemetry/common/propagation/symbol_key_getter.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Common + module Propagation + # The SymbolKeyGetter class provides a common method for reading + # symbol keys from a hash. + class SymbolKeyGetter + # Converts key into a symbol and reads it from the carrier. + # Useful for extract operations. + def get(carrier, key) + carrier[key.to_sym] + end + + # Reads all keys from a carrier + def keys(carrier) + carrier.keys.map(&:to_s) + end + end + end + end +end diff --git a/common/test/opentelemetry/common/propagation/rack_env_getter_test.rb b/common/test/opentelemetry/common/propagation/rack_env_getter_test.rb new file mode 100644 index 0000000000..b53bc40f4b --- /dev/null +++ b/common/test/opentelemetry/common/propagation/rack_env_getter_test.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'test_helper' + +describe OpenTelemetry::Common::Propagation::RackEnvGetter do + let(:getter) do + OpenTelemetry::Context::Propagation::RackEnvGetter.new + end + + let(:carrier) do + { + 'HTTP_TRACEPARENT' => 'tp', + 'HTTP_TRACESTATE' => 'ts', + 'HTTP_X_SOURCE_ID' => '123', + 'rack.hijack?' => true + } + end + + describe '#get' do + it 'reads key from carrier' do + _(getter.get(carrier, 'traceparent')).must_equal('tp') + _(getter.get(carrier, 'tracestate')).must_equal('ts') + _(getter.get(carrier, 'x-source-id')).must_equal('123') + _(getter.get(carrier, 'rack.hijack?')).must_equal(true) + end + + it 'returns nil for non-existent key' do + _(getter.get(carrier, 'not-here')).must_be_nil + end + end + + describe '#keys' do + it 'returns carrier keys' do + _(getter.keys(carrier)).must_equal(%w[traceparent tracestate x-source-id rack.hijack?]) + end + + it 'returns empty array for empty carrier' do + _(getter.keys({})).must_equal([]) + end + end +end diff --git a/common/test/opentelemetry/common/propagation/symbol_key_getter_test.rb b/common/test/opentelemetry/common/propagation/symbol_key_getter_test.rb new file mode 100644 index 0000000000..d744e96de6 --- /dev/null +++ b/common/test/opentelemetry/common/propagation/symbol_key_getter_test.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'test_helper' + +describe OpenTelemetry::Common::Propagation::SymbolKeyGetter do + let(:symbol_key_getter) { OpenTelemetry::Common::Propagation::SymbolKeyGetter.new } + let(:carrier) { { foo: 'bar' } } + + describe '#get' do + it 'retrieves the value' do + _(symbol_key_getter.get(carrier, 'foo')).must_equal('bar') + end + end + + describe '#keys' do + it 'returns all the keys as strings' do + _(symbol_key_getter.keys(carrier)).must_equal(['foo']) + end + end +end diff --git a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb index d03e6734ca..18a21cb146 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: ->(opt) { %I[omit include].include?(opt) } + option :db_statement, default: :include, validate: ->(opt) { %I[omit obfuscate include].include?(opt) } private diff --git a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/patches/server.rb b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/patches/server.rb index 886ed5374c..a8b8458be7 100644 --- a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/patches/server.rb +++ b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/patches/server.rb @@ -17,7 +17,12 @@ def request(op, *args) 'net.peer.name' => hostname, 'net.peer.port' => port } - attributes['db.statement'] = Utils.format_command(operation, args) if config[:db_statement] == :include + if config[:db_statement] == :include + attributes['db.statement'] = Utils.format_command(operation, args) + elsif config[:db_statement] == :obfuscate + attributes['db.statement'] = "#{operation} ?" + end + attributes['peer.service'] = config[:peer_service] if config[:peer_service] tracer.in_span(operation, attributes: attributes, kind: :client) do super diff --git a/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb b/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb index 866a47d93f..b6f4acac31 100644 --- a/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb +++ b/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb @@ -107,5 +107,16 @@ _(span.name).must_equal 'set' _(span.attributes).wont_include 'db.statement' end + + it 'obfuscates db.statement' do + instrumentation.instance_variable_set(:@installed, false) + instrumentation.install(db_statement: :obfuscate) + + dalli.set('foo', 'bar') + + _(exporter.finished_spans.size).must_equal 1 + _(span.name).must_equal 'set' + _(span.attributes['db.statement']).must_equal 'set ?' + end end end unless ENV['OMIT_SERVICES'] diff --git a/instrumentation/manticore/.rubocop.yml b/instrumentation/manticore/.rubocop.yml new file mode 100644 index 0000000000..003928f6b3 --- /dev/null +++ b/instrumentation/manticore/.rubocop.yml @@ -0,0 +1,5 @@ +inherit_from: ../.rubocop-examples.yml + +Naming/FileName: + Exclude: + - "lib/opentelemetry-instrumentation-manticore.rb" diff --git a/instrumentation/manticore/.yardopts b/instrumentation/manticore/.yardopts new file mode 100644 index 0000000000..3f55be6615 --- /dev/null +++ b/instrumentation/manticore/.yardopts @@ -0,0 +1,9 @@ +--no-private +--title=OpenTelemetry Manticore Instrumentation +--markup=markdown +--main=README.md +./lib/opentelemetry/instrumentation/**/*.rb +./lib/opentelemetry/instrumentation.rb +- +README.md +CHANGELOG.md diff --git a/instrumentation/manticore/CHANGELOG.md b/instrumentation/manticore/CHANGELOG.md new file mode 100644 index 0000000000..55046e1eca --- /dev/null +++ b/instrumentation/manticore/CHANGELOG.md @@ -0,0 +1 @@ +# Release History: opentelemetry-instrumentation-manticore diff --git a/instrumentation/manticore/Gemfile b/instrumentation/manticore/Gemfile new file mode 100644 index 0000000000..78e3eff47d --- /dev/null +++ b/instrumentation/manticore/Gemfile @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +source 'https://rubygems.org' + +gemspec + +gem 'opentelemetry-api', path: '../../api' +gem 'opentelemetry-instrumentation-base', path: '../base' + +group :test do + gem 'opentelemetry-common', path: '../../common' + gem 'opentelemetry-sdk', path: '../../sdk' +end diff --git a/instrumentation/manticore/LICENSE b/instrumentation/manticore/LICENSE new file mode 100644 index 0000000000..1ef7dad2c5 --- /dev/null +++ b/instrumentation/manticore/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright The OpenTelemetry Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/instrumentation/manticore/README.md b/instrumentation/manticore/README.md new file mode 100644 index 0000000000..09019e6ee6 --- /dev/null +++ b/instrumentation/manticore/README.md @@ -0,0 +1,56 @@ +# OpenTelemetry Manticore Instrumentation + +The OpenTelemetry RestClient gem is a community maintained instrumentation for the [RestClient][manticore-home] library. + +## How do I get started? + +Install the gem using: + +``` +gem install opentelemetry-instrumentation-manticore +``` + +Or, if you use [bundler][bundler-home], include `opentelemetry-instrumentation-manticore` in your `Gemfile`. + +## Usage + +To install the instrumentation, call `use` with the name of the instrumentation. + +```ruby +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::Manticore' +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-manticore` 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 + +Apache 2.0 license. See [LICENSE][license-github] for more information. + +[manticore-home]: https://github.com/cheald/manticore +[bundler-home]: https://bundler.io +[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby +[license-github]: https://github.com/open-telemetry/opentelemetry-ruby/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 + + + +TODO read +https://github.com/open-telemetry/opentelemetry-ruby/blob/da4d74781a06731f4f990458f2410ae314565a77/CONTRIBUTING.md +https://github.com/open-telemetry/opentelemetry-ruby/blob/da4d74781a06731f4f990458f2410ae314565a77/CODE_OF_CONDUCT.md + diff --git a/instrumentation/manticore/Rakefile b/instrumentation/manticore/Rakefile new file mode 100644 index 0000000000..1a64ba842e --- /dev/null +++ b/instrumentation/manticore/Rakefile @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'bundler/gem_tasks' +require 'rake/testtask' +require 'yard' +require 'rubocop/rake_task' + +RuboCop::RakeTask.new + +Rake::TestTask.new :test do |t| + t.libs << 'test' + t.libs << 'lib' + t.test_files = FileList['test/**/*_test.rb'] +end + +YARD::Rake::YardocTask.new do |t| + t.stats_options = ['--list-undoc'] +end + +if RUBY_ENGINE == 'truffleruby' + task default: %i[test] +else + task default: %i[test rubocop yard] +end diff --git a/instrumentation/manticore/example/Gemfile b/instrumentation/manticore/example/Gemfile new file mode 100644 index 0000000000..8c1adb2956 --- /dev/null +++ b/instrumentation/manticore/example/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'opentelemetry-api', path: '../../../api' +gem 'opentelemetry-common', path: '../../../common' +gem 'opentelemetry-instrumentation-manticore', path: '../../../instrumentation/manticore' +gem 'opentelemetry-sdk', path: '../../../sdk' +gem 'manticore' diff --git a/instrumentation/manticore/example/manticore.rb b/instrumentation/manticore/example/manticore.rb new file mode 100644 index 0000000000..4638002ae3 --- /dev/null +++ b/instrumentation/manticore/example/manticore.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'rubygems' +require 'bundler/setup' +require 'manticore' + +Bundler.require + +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::Manticore' + c.add_span_processor( + OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new( + OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new + ) + ) + c.service_name = 'demo example' +end + +# sync call +resp = Manticore.get('https://example.com?query=1') +puts "*" * 20, "sync call" +puts "response code: #{resp.code}" + +# async call +client = Manticore::Client.new +async_resp1 = client.parallel.get("http://www.example1.com") +async_resp1.on_complete do |r| + puts "*" * 20, "parallel call #{r.request.uri.to_s }" + puts "response code: #{r.code}" +end + +async_resp2 = client.parallel.get("http://www.example2.com") +async_resp2.on_complete do |r| + puts "*" * 20, "parallel call #{r.request.uri.to_s }" + puts "response code: #{r.code}" +end + +client.execute! \ No newline at end of file diff --git a/instrumentation/manticore/lib/opentelemetry-instrumentation-manticore.rb b/instrumentation/manticore/lib/opentelemetry-instrumentation-manticore.rb new file mode 100644 index 0000000000..baceb3cb76 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry-instrumentation-manticore.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require_relative './opentelemetry/instrumentation' diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation.rb new file mode 100644 index 0000000000..327e46a3f3 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +# OpenTelemetry is an open source observability framework, providing a +# general-purpose API, SDK, and related tools required for the instrumentation +# of cloud-native software, frameworks, and libraries. +# +# The OpenTelemetry module provides global accessors for telemetry objects. +# See the documentation for the `opentelemetry-api` gem for details. +module OpenTelemetry + # "Instrumentation" are specified by + # https://github.com/open-telemetry/opentelemetry-specification/blob/784635d01d8690c8f5fcd1f55bdbc8a13cf2f4f2/specification/glossary.md#instrumentation-library + # + # 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/manticore' diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore.rb new file mode 100644 index 0000000000..1cffccf4c2 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore.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 RestClient gem + module Manticore + end + end +end + +require_relative './manticore/instrumentation' +require_relative './manticore/version' diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/instrumentation.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/instrumentation.rb new file mode 100644 index 0000000000..6c0d9a09b3 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/instrumentation.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Instrumentation + module Manticore + # The Instrumentation class contains logic to detect and install the Manticore instrumentation + class Instrumentation < OpenTelemetry::Instrumentation::Base + present do + defined?(::Manticore::Client) && defined?(::Manticore::Response) + end + + install do |_config| + require_dependencies + patch_response + end + + option :sanitize_headers, default:%w[authorization signature oauth_signature], validate: :array + option :record_all_response_headers, default: false, validate: :boolean + option :record_all_request_headers, default: false, validate: :boolean + + private + + def require_dependencies + require_relative 'util/wrapped_request' + require_relative 'util/wrapped_response' + require_relative 'patches/response' + end + + def patch_response + ::Manticore::Response.prepend(Patches::Response) + ::Manticore::Response.class_eval do + alias_method :call_without_otel_trace!, :call + alias_method :call, :call_with_otel_trace! + end + end + end + end + end +end diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/patches/response.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/patches/response.rb new file mode 100644 index 0000000000..d95b673412 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/patches/response.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Instrumentation + module Manticore + module Patches + # Module to prepend to RestClient::Request for instrumentation + module Response + + # Hooks into the #.call function which is executed for any verbs like: + # [:get, :post, :put, :options, :header] + # @api #.call_with_otel_trace! - is the entry point to creating the OpenTelemetry + # traces and spans if the class is loaded. + # it has direct to Manticore::Response methods and instance variables. + # Take great care of any unintentional mutations: + # [@request, @response, .on_complete] - are being invoked directly from Manticore::Response + def call_with_otel_trace! + wrapped_request = OpenTelemetry::Instrumentation::Manticore::Util::WrappedRequest.new(@request) + merged_attr = request_attr(wrapped_request) + .merge(header_attr(wrapped_request.headers)) + .merge(OpenTelemetry::Common::HTTP::ClientContext.attributes) + span = tracer.start_span("HTTP #{wrapped_request.method}", attributes: merged_attr, kind: :client) + OpenTelemetry::Trace.with_span(span) do + OpenTelemetry.propagation.inject(wrapped_request) + end + on_complete do |response| + process_resp_attr(span, OpenTelemetry::Instrumentation::Manticore::Util::WrappedResponse.new(response)) + end + call_without_otel_trace! + rescue ::Manticore::ManticoreException => e + span.set_attribute('http.response.status_code', 500) + span.set_attribute('http.response.status_text', 'Internal Server Error') + span.set_attribute('http.response.exception', e.message) + span.status = OpenTelemetry::Trace::Status.http_to_status(500) + ensure + span.finish + end + + private + + # @param [OpenTelemetry::Instrumentation::Manticore::Util::WrappedRequest] wrapped_request A request object that contains + # information of an HTTP call to be made + # @return [Hash] returns request attributes to be added to span + def request_attr(wrapped_request) + uri = URI.parse(wrapped_request.uri) + attr = { + 'library' => 'Manticore', + 'component' => 'http', + 'http.method' => wrapped_request.method, + 'http.host' => uri.host + } + attr['http.path'] = uri.path unless uri.path.empty? + attr['http.query'] = uri.query if uri.query + attr + rescue StandardError => e + OpenTelemetry.logger.debug("Error while fetching request attributes: #{e}",) + {} + end + + # @param [OpenTelemetry::Trace::Tracer.in_span] span A running span that has not been completed + # @param [OpenTelemetry::Instrumentation::Manticore::Util::WrappedResponse] response A wrapped response with limited exposed methods. + def process_resp_attr(span, response) + attr = { + 'http.response.status_code' => response.status_code, + 'http.response.status_text' => response.status_text + } + if Manticore::Instrumentation.instance.config[:record_all_response_headers] + response.headers.each { |k, v| attr["http.response.#{k}"] = v unless v.nil? } + end + span.add_attributes(attr) + span.status = OpenTelemetry::Trace::Status.http_to_status( + response.status_code + ) + rescue StandardError => e + OpenTelemetry.logger.debug("Error while adding span attributes #{e}") + end + + # @param [OpenTelemetry::Instrumentation::Manticore::Util::WrappedRequest.headers] headers receives the headers hash of the manticore request object + # @return [Hash] A duplicated headers attributes hash with sanitized values for security reasons. + def header_attr(headers) + return {} if headers.empty? + return {} unless Manticore::Instrumentation.instance.config[:record_all_request_headers] + attr = {} + sanitize_headers = Manticore::Instrumentation.instance.config[:sanitize_headers] + headers.keys.each do |key| + key_s = key.to_s + attr["http.headers.#{key_s}"] = sanitize_headers.include?(key_s.downcase) ? '' : headers[key] + end + attr + end + + def tracer + Manticore::Instrumentation.instance.tracer + end + end + end + end + end +end diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_request.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_request.rb new file mode 100644 index 0000000000..8b9b257025 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_request.rb @@ -0,0 +1,50 @@ +module OpenTelemetry + module Instrumentation + module Manticore + module Util + # A Class that for protecting direct access to the original Manticore::Response::request object + # that has not yet made an outgoing network call yet. + class WrappedRequest + def initialize(request) + @request = request + end + + # headers related exposure + def [](key) + _, value = @request.headers.find { |k, _| k.casecmp(key).zero? } + value + end + + def set(key, value) + @request.set_header(key, value) + end + + def []=(key, value) + @request.set_header(key, value) + end + + def headers + @request.headers + end + + def keys + @request.headers.keys + end + + def uri + @request.uri.to_s + end + + def method + @request.method + end + + def host + self['Host'] + end + end + end + end + end +end + diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_response.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_response.rb new file mode 100644 index 0000000000..fcb2343501 --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/util/wrapped_response.rb @@ -0,0 +1,37 @@ +module OpenTelemetry + module Instrumentation + module Manticore + module Util + # A Class that for protecting direct access to the original Manticore::Response object that + # represents a response object as already been completed + class WrappedResponse + def initialize(response) + raise ArgumentError, 'expected a http response but received nil' if response.nil? + + @wrapped_response = response + @headers = response.headers + end + + def [](key) + _, value = @headers.find { |k, _| k.casecmp(key).zero? } + value + end + + def headers + @headers + end + + def status_code + @wrapped_response.code + end + + def status_text + @wrapped_response.message + end + + end + end + end + end +end + diff --git a/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/version.rb b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/version.rb new file mode 100644 index 0000000000..d59f3df03a --- /dev/null +++ b/instrumentation/manticore/lib/opentelemetry/instrumentation/manticore/version.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Instrumentation + module Manticore + VERSION = '0.17.0' + end + end +end diff --git a/instrumentation/manticore/opentelemetry-instrumentation-manticore.gemspec b/instrumentation/manticore/opentelemetry-instrumentation-manticore.gemspec new file mode 100644 index 0000000000..56be9a9004 --- /dev/null +++ b/instrumentation/manticore/opentelemetry-instrumentation-manticore.gemspec @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'opentelemetry/instrumentation/manticore/version' + +Gem::Specification.new do |spec| + spec.name = 'opentelemetry-instrumentation-manticore' + spec.version = OpenTelemetry::Instrumentation::Manticore::VERSION + spec.authors = ['OpenTelemetry Authors'] + spec.email = ['cncf-opentelemetry-contributors@lists.cncf.io'] + + spec.summary = 'Manticore Client instrumentation for the OpenTelemetry framework' + spec.description = 'Manticore Client instrumentation for the OpenTelemetry framework' + spec.homepage = 'https://github.com/open-telemetry/opentelemetry-ruby' + spec.license = 'Apache-2.0' + + spec.files = ::Dir.glob('lib/**/*.rb') + + ::Dir.glob('*.md') + + ['LICENSE', '.yardopts'] + spec.require_paths = ['lib'] + spec.required_ruby_version = '>= 2.5.0' + + spec.add_dependency 'opentelemetry-api', '~> 0.17.0' + spec.add_dependency 'opentelemetry-common', '~> 0.17.0' + spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.17.0' + + spec.add_development_dependency 'appraisal', '~> 2.2.0' + spec.add_development_dependency 'bundler', '>= 1.17' + spec.add_development_dependency 'minitest', '~> 5.0' + spec.add_development_dependency 'opentelemetry-sdk', '~> 0.0' + spec.add_development_dependency 'manticore', '~> 0.7.0' + spec.add_development_dependency 'rubocop', '~> 0.73.0' + spec.add_development_dependency 'simplecov', '~> 0.17.1' + spec.add_development_dependency 'webmock', '~> 3.7.6' + spec.add_development_dependency 'yard', '~> 0.9' + spec.add_development_dependency 'yard-doctest', '~> 0.1.6' + + # if spec.respond_to?(:metadata) + # spec.metadata['changelog_uri'] = "https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-manticore/v#{OpenTelemetry::Instrumentation::Manticore::VERSION}/file.CHANGELOG.html" + # spec.metadata['source_code_uri'] = 'https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/manticore' + # spec.metadata['bug_tracker_uri'] = 'https://github.com/open-telemetry/opentelemetry-ruby/issues' + # spec.metadata['documentation_uri'] = "https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-manticore/v#{OpenTelemetry::Instrumentation::Manticore::VERSION}" + # end +end diff --git a/instrumentation/manticore/test/.rubocop.yml b/instrumentation/manticore/test/.rubocop.yml new file mode 100644 index 0000000000..dd94258585 --- /dev/null +++ b/instrumentation/manticore/test/.rubocop.yml @@ -0,0 +1,4 @@ +inherit_from: ../.rubocop.yml + +Metrics/BlockLength: + Enabled: false diff --git a/instrumentation/manticore/test/opentelemetry/instrumentation/manticore/instrumentation_test.rb b/instrumentation/manticore/test/opentelemetry/instrumentation/manticore/instrumentation_test.rb new file mode 100644 index 0000000000..e1ed3f48ee --- /dev/null +++ b/instrumentation/manticore/test/opentelemetry/instrumentation/manticore/instrumentation_test.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'test_helper' + +require_relative '../../../../lib/opentelemetry/instrumentation/manticore' +require_relative '../../../../lib/opentelemetry/instrumentation/manticore/patches/response' + +describe OpenTelemetry::Instrumentation::Manticore::Instrumentation do + let(:instrumentation) { OpenTelemetry::Instrumentation::Manticore::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) + + # this is currently a noop but this will future proof the test + @orig_propagation = OpenTelemetry.propagation + propagator = OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator + OpenTelemetry.propagation = propagator + end + + after do + # Force re-install of instrumentation + instrumentation.instance_variable_set(:@installed, false) + + OpenTelemetry.propagation = @orig_propagation + end + + 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 + ::Manticore.get('http://username:password@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.url']).must_equal 'http://example.com/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 + expect do + ::Manticore.get('http://username:password@example.com/failure') + end.must_raise Manticore::InternalServerError + + _(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.url']).must_equal 'http://example.com/failure' + assert_requested( + :get, + 'http://example.com/failure', + 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 + ::Manticore.get('http://username:password@example.com/success') + end + + _(span.attributes['http.method']).must_equal 'OVERRIDE' + _(span.attributes['test.attribute']).must_equal 'test.value' + _(span.attributes['http.url']).must_equal 'http://example.com/success' + end + + it 'accepts peer service name from config' do + instrumentation.instance_variable_set(:@installed, false) + instrumentation.install(peer_service: 'example:faraday') + + ::Manticore.get('http://example.com/success') + _(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') + + client_context_attrs = { 'peer.service' => 'example:custom' } + OpenTelemetry::Common::HTTP::ClientContext.with_attributes(client_context_attrs) do + ::Manticore.get('http://example.com/success') + end + _(span.attributes['peer.service']).must_equal 'example:custom' + end + end +end diff --git a/instrumentation/manticore/test/test_helper.rb b/instrumentation/manticore/test/test_helper.rb new file mode 100644 index 0000000000..14691caf24 --- /dev/null +++ b/instrumentation/manticore/test/test_helper.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'manticore' + +require 'opentelemetry/sdk' + +require 'minitest/autorun' +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.add_span_processor span_processor +end diff --git a/instrumentation/sidekiq/Appraisals b/instrumentation/sidekiq/Appraisals index 6cb0f10e7a..008b9c89e5 100644 --- a/instrumentation/sidekiq/Appraisals +++ b/instrumentation/sidekiq/Appraisals @@ -1,5 +1,9 @@ # frozen_string_literal: true +appraise 'sidekiq-6.3' do + gem 'sidekiq', '~> 6.3' +end + appraise 'sidekiq-6.1' do gem 'sidekiq', '~> 6.1' end diff --git a/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/patches/poller_test.rb b/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/patches/poller_test.rb index e6124389d3..31357dbda9 100644 --- a/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/patches/poller_test.rb +++ b/instrumentation/sidekiq/test/opentelemetry/instrumentation/sidekiq/patches/poller_test.rb @@ -46,7 +46,8 @@ poller.enqueue span_names = spans.map(&:name) _(span_names).must_include('Sidekiq::Scheduled::Poller#enqueue') - _(span_names).must_include('ZRANGEBYSCORE') + # Inline Lua uses a different redis client method in 6.3+ https://github.com/mperham/sidekiq/pull/5044 + _(span_names).must_include('ZRANGEBYSCORE') if Gem.loaded_specs['sidekiq'].version < Gem::Version.new('6.3') end describe 'when peer_service config is set' do diff --git a/website_docs/getting_started.md b/website_docs/getting_started.md index d6a7be22b4..6c74cb98a0 100644 --- a/website_docs/getting_started.md +++ b/website_docs/getting_started.md @@ -85,7 +85,7 @@ Adding tracing to a single service is a great first step and although auto-instr [repository]: https://github.com/open-telemetry/opentelemetry-ruby [auto-instrumentation]: https://github.com/open-telemetry/opentelemetry-ruby#instrumentation-libraries -[sdk-env]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options +[sdk-env]: {{< relref "/docs/reference/specification/protocol/exporter#configuration-options" >}} [context-propagation]: ../context_propagation [events]: ../events [manual-instrumentation]: ../manual_instrumentation diff --git a/website_docs/manual_instrumentation.md b/website_docs/manual_instrumentation.md index 735b4c495c..caa1980ff9 100644 --- a/website_docs/manual_instrumentation.md +++ b/website_docs/manual_instrumentation.md @@ -76,9 +76,10 @@ end #### Semantic Attributes -Semantic Attributes are attributes that are defined by the OpenTelemetry Specification in order to provide a shared set of attribute keys across multiple languages, frameworks, and runtimes for common concepts like HTTP methods, status codes, user agents, and more. These attributes are available in the [Semantic Conventions gem][semconv-gem]. +Semantic Attributes are attributes that are defined by the [OpenTelemetry Specification][] in order to provide a shared set of attribute keys across multiple languages, frameworks, and runtimes for common concepts like HTTP methods, status codes, user agents, and more. These attributes are available in the [Semantic Conventions gem][semconv-gem]. -Tracing semantic conventions can be found in [this document][semconv-spec] +For details, see [Trace semantic conventions][semconv-spec]. +[OpenTelemetry Specification]: {{< relref "/docs/reference/specification" >}} [semconv-gem]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/semantic_conventions -[semconv-spec]: https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions +[semconv-spec]: {{< relref "/docs/reference/specification/trace/semantic_conventions" >}}