Skip to content

Commit

Permalink
Merge branch 'metrics-alternative-prototype' of github.com:kaylareope…
Browse files Browse the repository at this point in the history
…lle/opentelemetry-ruby-contrib into metrics-alternative-prototype
  • Loading branch information
kaylareopelle committed Sep 20, 2024
2 parents 92d9ef6 + 951e0af commit 8b4554f
Show file tree
Hide file tree
Showing 95 changed files with 365 additions and 155 deletions.
4 changes: 2 additions & 2 deletions .github/actions/test_gem/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ runs:
# ...but not for appraisals, sadly.
- name: Install Ruby ${{ inputs.ruby }} with dependencies
if: "${{ steps.setup.outputs.appraisals == 'false' }}"
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: "${{ inputs.ruby }}"
working-directory: "${{ steps.setup.outputs.gem_dir }}"
Expand All @@ -77,7 +77,7 @@ runs:
# If we're using appraisals, do it all manually.
- name: Install Ruby ${{ inputs.ruby }} without dependencies
if: "${{ steps.setup.outputs.appraisals == 'true' }}"
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: "${{ inputs.ruby }}"
bundler: "latest"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/installation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v4
# ATTENTION: Dependabot does not know how to update shared actions file.
# If you see it update setup-ruby here also update it as part of actions/test_gem/action.yml
- uses: ruby/setup-ruby@v1.190.0
- uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ matrix.ruby-version }}
- name: "Install Latest Gem Versions on ${{ matrix.ruby-version }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-hook-on-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-hook-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-perform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
- uses: ruby/setup-ruby@v1.190.0
- uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: "3.0"
bundler: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-request-weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-retry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.190.0
uses: ruby/setup-ruby@v1.191.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .instrumentation_generator/templates/gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.0'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.65.0'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.7.6'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
source 'https://rubygems.org'

gem 'rake', '~> 13.0'
gem 'rubocop', '~> 1.65.1'
gem 'rubocop', '~> 1.66.0'
gem 'rubocop-performance', '~> 1.21.0'
2 changes: 1 addition & 1 deletion helpers/mysql/opentelemetry-helpers-mysql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.65.0'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.21.0'
spec.add_development_dependency 'simplecov', '~> 0.22.0'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
2 changes: 1 addition & 1 deletion helpers/sql-obfuscation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

Make sure the `Instrumentation` class for your gem contains configuration options for:

- `:obfuscation_limit`: the length at which the obfuscated SQL string will be truncated.
- `:obfuscation_limit`: the length at which the SQL string will not be obfuscated
Example: `option :obfuscation_limit, default: 2000, validate: :integer`

If you want to add support for a new adapter, update the following constants to include keys for your adapter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ def generate_regex(dialect)
# This is a SQL obfuscation utility intended for use in database adapter instrumentation.
#
# @param sql [String] The SQL to obfuscate.
# @param obfuscation_limit [optional Integer] The maximum length of an obfuscated sql statement.
# @param obfuscation_limit [optional Integer] the length at which the SQL string will not be obfuscated
# @param adapter [optional Symbol] the type of database adapter calling the method. `:default`, `:mysql` and `:postgres` are supported.
# @return [String] The SQL query string where the values are replaced with "?". When the sql statement exceeds the obufscation limit
# the first matched pair from the SQL statement will be returned, with an appended truncation message. If trunaction is unsuccessful,
# a string describing the error will be returned.
#
# @api public
def obfuscate_sql(sql, obfuscation_limit: 2000, adapter: :default)
return "SQL not obfuscated, query exceeds #{obfuscation_limit} characters" if sql.size > obfuscation_limit

regex = case adapter
when :mysql
MYSQL_COMPONENTS_REGEX
Expand All @@ -115,7 +117,6 @@ def obfuscate_sql(sql, obfuscation_limit: 2000, adapter: :default)
# https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/160
# https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/345
sql = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)
return truncate_statement(sql, regex, obfuscation_limit) if sql.size > obfuscation_limit

sql = sql.gsub(regex, PLACEHOLDER)
return 'Failed to obfuscate SQL query - quote characters remained after obfuscation' if CLEANUP_REGEX[adapter].match(sql)
Expand All @@ -124,16 +125,6 @@ def obfuscate_sql(sql, obfuscation_limit: 2000, adapter: :default)
rescue StandardError => e
OpenTelemetry.handle_error(message: 'Failed to obfuscate SQL', exception: e)
end

# @api private
def truncate_statement(sql, regex, limit)
first_match_index = sql.index(regex)
truncation_message = "SQL truncated (> #{limit} characters)"
return truncation_message unless first_match_index

truncated_sql = sql[..first_match_index - 1]
"#{truncated_sql}...\n#{truncation_message}"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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.65.0'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.21.0'
spec.add_development_dependency 'yard', '~> 0.9'
spec.add_development_dependency 'yard-doctest', '~> 0.1.6'
Expand Down
14 changes: 3 additions & 11 deletions helpers/sql-obfuscation/test/helpers/sql_obfuscation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,9 @@ def test_named_arg_defaults_obfuscates
assert_equal(expected, result)
end

def test_obfuscation_limit_truncates_query_after_first_match
def test_obfuscation_returns_message_when_limit_is_reached
sql = "SELECT * from users where users.id = 1 and users.email = 'test@test.com'"
expected = "SELECT * from users where users.id = ...\nSQL truncated (> 42 characters)"
result = OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(sql, obfuscation_limit: 42)

assert_equal(expected, result)
end

def test_obfuscation_limit_truncates_when_query_not_encoded_with_utf8
sql = "SELECT * from 😄 where users.id = 1 and users.😄 = 'test@test.com'"
expected = "SELECT * from where users.id = ...\nSQL truncated (> 42 characters)"
expected = 'SQL not obfuscated, query exceeds 42 characters'
result = OpenTelemetry::Helpers::SqlObfuscation.obfuscate_sql(sql, obfuscation_limit: 42)

assert_equal(expected, result)
Expand Down Expand Up @@ -65,7 +57,7 @@ def test_statement_with_emoji_encodes_utf_8_and_obfuscates
FAILED_TO_OBFUSCATE_MESSAGE = 'Failed to obfuscate SQL query - quote characters remained after obfuscation'

def build_failure_message(statement, dialect, acceptable_outputs, actual_output)
msg = +"Failed to obfuscate #{dialect} query correctly.\n"
msg = "Failed to obfuscate #{dialect} query correctly.\n"
msg << "Input: #{statement}\n"
if acceptable_outputs.size == 1
msg << "Expected: #{acceptable_outputs.first}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
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 'rubocop', '~> 1.65.0'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.20'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rails', '>= 6.1'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.65.0'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.20'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
Expand Down
8 changes: 8 additions & 0 deletions instrumentation/action_view/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release History: opentelemetry-instrumentation-action_view

### v0.7.3 / 2024-08-23

* FIXED: ActionView Support Legacy Formats

### v0.7.2 / 2024-08-15

* (No Significant Changes)

### v0.7.1 / 2024-07-23

* DOCS: Add cspell to CI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

module OpenTelemetry
module Instrumentation
# Contains the OpenTelemetry instrumentation for the ActionView gem
# (see OpenTelemetry::Instrumentation::ActionView::Instrumentation)
module ActionView
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,42 @@
module OpenTelemetry
module Instrumentation
module ActionView
# The Instrumentation class contains logic to detect and install the ActionView instrumentation
# The {OpenTelemetry::Instrumentation::ActionView::Instrumentation} class contains logic to detect and install the ActionView instrumentation
#
# Installation and configuration of this instrumentation is done within the
# {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry/SDK#configure-instance_method OpenTelemetry::SDK#configure}
# block, calling {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use use()}
# or {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use_all use_all()}.
#
# ## Configuration keys and options
#
# ### `:disallowed_notification_payload_keys`
#
# Specifies an array of keys that should be excluded from the notification payload as span attributes.
#
# ### `:notification_payload_transform`
#
# - `proc` **default** `nil`
#
# Specifies custom proc used to extract span attributes form the notification payload.
# Use this to rename keys, extract nested values, or perform any other custom logic.
#
# ### `:legacy_span_names`
#
# - `boolean` **default** `false`
#
# Specifies whether spans names should use the legacy format where the subscription was reverse ordered and white space separated. (Ex. `action_view render_template`)
# If set to `true`, the span name will match the name of the notification itself. (Ex. `render_template.action_view`)
#
# @example An explicit default configuration
# OpenTelemetry::SDK.configure do |c|
# c.use_all({
# 'OpenTelemetry::Instrumentation::ActionView' => {
# disallowed_notification_payload_keys: [],
# legacy_span_names: true,
# },
# })
# end
class Instrumentation < OpenTelemetry::Instrumentation::Base
MINIMUM_VERSION = Gem::Version.new('6.1.0')
install do |_config|
Expand All @@ -24,6 +59,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base

option :disallowed_notification_payload_keys, default: [], validate: :array
option :notification_payload_transform, default: nil, validate: :callable
option :legacy_span_names, default: false, validate: :boolean

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ class Railtie < ::Rails::Railtie
config.after_initialize do
::OpenTelemetry::Instrumentation::ActiveSupport::Instrumentation.instance.install({})

instance = ::OpenTelemetry::Instrumentation::ActionView::Instrumentation.instance
span_name_formatter = instance.config[:legacy_span_names] ? ::OpenTelemetry::Instrumentation::ActiveSupport::LEGACY_NAME_FORMATTER : nil

SUBSCRIPTIONS.each do |subscription_name|
config = ActionView::Instrumentation.instance.config
::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
ActionView::Instrumentation.instance.tracer,
instance.tracer,
subscription_name,
config[:notification_payload_transform],
config[:disallowed_notification_payload_keys]
instance.config[:notification_payload_transform],
instance.config[:disallowed_notification_payload_keys],
span_name_formatter: span_name_formatter
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module OpenTelemetry
module Instrumentation
module ActionView
VERSION = '0.7.1'
VERSION = '0.7.3'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 3.0'

spec.add_dependency 'opentelemetry-api', '~> 1.0'
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.1'
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.6'
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1'

spec.add_development_dependency 'appraisal', '~> 2.5'
Expand All @@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rails', '>= 6.1'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.65.0'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.20'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
Expand Down
12 changes: 12 additions & 0 deletions instrumentation/active_job/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Release History: opentelemetry-instrumentation-active_job

### v0.7.7 / 2024-08-21

* FIXED: Propagate context between enqueue and perform

### v0.7.6 / 2024-08-15

* FIXED: Prefix ::ActiveSupport when installing the instrumentation

### v0.7.5 / 2024-08-15

* FIXED: Use Active Support Lazy Load Hooks to avoid prematurely initializing ActiveRecord::Base and ActiveJob::Base

### v0.7.4 / 2024-07-30

* FIXED: Honour dynamic changes in configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def start_span(name, _id, payload)
job = payload.fetch(:job)
span_name = span_name(job, EVENT_NAME)
span = tracer.start_span(span_name, kind: :producer, attributes: @mapper.call(payload))
token = OpenTelemetry::Context.attach(OpenTelemetry::Trace.context_with_span(span))
OpenTelemetry.propagation.inject(job.__otel_headers) # This must be transmitted over the wire
{ span: span, ctx_token: OpenTelemetry::Context.attach(OpenTelemetry::Trace.context_with_span(span)) }
{ span: span, ctx_token: token }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def start_span(name, _id, payload)
# TODO: Refactor into a propagation strategy
propagation_style = @config[:propagation_style]
if propagation_style == :child
span = tracer.start_span(span_name, kind: :consumer, attributes: @mapper.call(payload))
span = tracer.start_span(span_name, with_parent: parent_context, kind: :consumer, attributes: @mapper.call(payload))
else
span_context = OpenTelemetry::Trace.current_span(parent_context).context
links = [OpenTelemetry::Trace::Link.new(span_context)] if span_context.valid? && propagation_style == :link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def require_dependencies
def patch_activejob
Handlers.subscribe

ActiveSupport.on_load(:active_job) do
::ActiveSupport.on_load(:active_job) do
::ActiveJob::Base.prepend(Patches::Base) unless ::ActiveJob::Base <= Patches::Base
end
end
Expand Down
Loading

0 comments on commit 8b4554f

Please sign in to comment.