Skip to content

Commit

Permalink
Merge branch 'main' into pg-prepend-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle authored Jan 2, 2024
2 parents 56f90d0 + 562f649 commit 02555e8
Show file tree
Hide file tree
Showing 195 changed files with 2,456 additions and 879 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: Release Please

on:
workflow_dispatch:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release:
name: Process Release
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@cc61a07e2da466bebbc19b3a7dd01d6aecb20d1e
id: release

outputs:
paths_released: ${{ steps.release.outputs.paths_released }}

publish:
needs: release
name: Publish Gems
runs-on: ubuntu-latest
if: ${{ needs.release.outputs.paths_released != '[]'}}

strategy:
fail-fast: false
max-parallel: 1
matrix:
path: ${{ fromJson(needs.release.outputs.paths_released) }}

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Setup Ruby
uses: ruby/setup-ruby@af848b40be8bb463a751551a1180d74782ba8a72
with:
ruby-version: 3.0.0

- name: Configure RubyGems
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"

run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
- name: Release Gem
working-directory: ${{ matrix.path }}
run: |
bundle install
bundle exec rake --trace build
bundle exec rake --trace release:rubygem_push
4 changes: 2 additions & 2 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/stale@v8
- uses: actions/stale@v9
name: Clean up stale issues and PRs
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the `keep` label to hold stale off permanently, or do nothing. If you do nothing this issue will be closed eventually by the stale bot."
stale-issue-label: "stale"
exempt-issue-labels: "keep"
days-before-issue-stale: 30
days-before-issue-close: -1
days-before-issue-close: 30
stale-pr-message: "👋 This pull request has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the `keep` label to hold stale off permanently, or do nothing. If you do nothing this pull request will be closed eventually by the stale bot"
stale-pr-label: "stale"
exempt-pr-labels: "keep"
Expand Down
1 change: 1 addition & 0 deletions .instrumentation_generator/templates/gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.48.1'
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'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
49 changes: 49 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"instrumentation/gruf": "0.1.1",
"instrumentation/grape": "0.1.6",
"instrumentation/racecar": "0.3.0",
"instrumentation/rake": "0.2.1",
"instrumentation/rdkafka": "0.4.2",
"instrumentation/trilogy": "0.57.0",
"instrumentation/active_support": "0.5.1",
"instrumentation/action_view": "0.7.0",
"instrumentation/action_pack": "0.8.0",
"instrumentation/active_job": "0.7.1",
"instrumentation/resque": "0.5.0",
"instrumentation/bunny": "0.21.1",
"instrumentation/base": "0.22.3",
"instrumentation/active_record": "0.7.0",
"instrumentation/aws_sdk": "0.5.0",
"instrumentation/lmdb": "0.22.1",
"instrumentation/http": "0.23.2",
"instrumentation/graphql": "0.27.0",
"instrumentation/http_client": "0.22.3",
"instrumentation/httpx": "0.1.1",
"instrumentation/koala": "0.20.2",
"instrumentation/active_model_serializers": "0.20.1",
"instrumentation/concurrent_ruby": "0.21.2",
"instrumentation/dalli": "0.25.0",
"instrumentation/delayed_job": "0.22.1",
"instrumentation/ethon": "0.21.3",
"instrumentation/excon": "0.22.0",
"instrumentation/faraday": "0.23.4",
"instrumentation/mongo": "0.22.2",
"instrumentation/mysql2": "0.25.0",
"instrumentation/net_http": "0.22.4",
"instrumentation/pg": "0.26.1",
"instrumentation/que": "0.7.1",
"instrumentation/rack": "0.23.5",
"instrumentation/rails": "0.29.1",
"instrumentation/redis": "0.25.3",
"instrumentation/restclient": "0.22.3",
"instrumentation/rspec": "0.3.2",
"instrumentation/ruby_kafka": "0.21.0",
"instrumentation/sidekiq": "0.25.0",
"instrumentation/sinatra": "0.23.2",
"instrumentation/all": "0.54.0",
"propagator/ottrace": "0.21.2",
"propagator/xray": "0.22.1",
"resources/azure": "0.1.0",
"resources/container": "0.1.1",
"resources/google_cloud_platform": "0.1.0"
}
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require: rubocop-performance

AllCops:
TargetRubyVersion: '3.0'
NewCops: enable
Expand Down
20 changes: 10 additions & 10 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
# https://help.github.com/en/articles/about-code-owners
#

* @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle @open-telemetry/ruby-contrib-approvers
* @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

resources/container/ @scbjans @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
resources/container/ @scbjans @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/aws_sdk/ @NathanielRN @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/aws_sdk/ @NathanielRN @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/grape/ @muripic @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/grape/ @muripic @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/graphql/ @swalkinshaw @rmosolgo @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/graphql/ @swalkinshaw @rmoslogo @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/httpx/ @HoneyryderChuck @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/httpx/ @HoneyryderChuck @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/mongo/ @johnnyshields @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/mongo/ @johnnyshields @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/racecar/ @chrisholmes @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/racecar/ @chrisholmes @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/rspec/ @chrisholmes @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/rspec/ @chrisholmes @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle

instrumentation/que/ @indrekj @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd
instrumentation/que/ @indrekj @open-telemetry/ruby-contrib-maintainers @open-telemetry/ruby-contrib-approvers @fbogsany @mwear @robertlaurin @dazuma @ericmustin @arielvalentin @ahayworth @plantfansam @robbkidd @simi @kaylareopelle
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
source 'https://rubygems.org'

gem 'rake', '~> 13.0'
gem 'rubocop', '~> 1.57.1'
gem 'rubocop', '~> 1.59.0'
gem 'rubocop-performance', '~> 1.19.1'
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ The Ruby special interest group (SIG) meets regularly. See the OpenTelemetry

Approvers ([@open-telemetry/ruby-contrib-approvers](https://github.com/orgs/open-telemetry/teams/ruby-contrib-approvers)):

- (Could _your_ name appear here?)
- [Josef Šimánek](https://github.com/simi)
- [Kayla Reopelle](https://github.com/kaylareopelle), New Relic

*Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver).*

Expand Down
6 changes: 6 additions & 0 deletions instrumentation/action_pack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History: opentelemetry-instrumentation-action_pack

### v0.8.0 / 2023-11-22

* BREAKING CHANGE: Drop Rails 6.0 EOL

* ADDED: Drop Rails 6.0 EOL

### v0.7.1 / 2023-10-16

* FIXED: Add Rails 7.1 compatibility
Expand Down
19 changes: 19 additions & 0 deletions instrumentation/action_pack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ OpenTelemetry::SDK.configure do |c|
end
```

## Active Support Instrumentation

Earlier versions of this instrumentation relied on patching custom `dispatch` hooks from Rails's [Action Controller](https://github.com/rails/rails/blob/main/actionpack/lib/action_controller/metal.rb#L224) to extract request information.

This instrumentation now relies on `ActiveSupport::Notifications` and registers a custom Subscriber that listens to relevant events to modify the Rack span.

See the table below for details of what [Rails Framework Hook Events](https://guides.rubyonrails.org/active_support_instrumentation.html#action-controller) are recorded by this instrumentation:

| Event Name | Subscribe? | Creates Span? | Notes |
| - | - | - | - |
| `process_action.action_controller` | :white_check_mark: | :x: | It modifies the existing Rack span |


### Error Handling for Action Controller

If an error is triggered by Action Controller (such as a 500 internal server error), Action Pack will typically employ the default `ActionDispatch::PublicExceptions.new(Rails.public_path)` as the `exceptions_app`, as detailed in the [documentation](https://guides.rubyonrails.org/configuring.html#config-exceptions-app).

The error object will be retained within `payload[:exception_object]`. Additionally, its storage in `request.env['action_dispatch.exception']` is contingent upon the configuration of `action_dispatch.show_exceptions` in Rails.

## Examples

Example usage can be seen in the `./example/trace_demonstration.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/action_pack/example/trace_demonstration.ru)
Expand Down
4 changes: 2 additions & 2 deletions instrumentation/action_pack/example/trace_demonstration.ru
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require 'action_controller/railtie'
class TraceRequestApp < Rails::Application
config.root = __dir__
config.hosts << 'example.org'
secrets.secret_key_base = 'secret_key_base'
credentials.secret_key_base = 'secret_key_base'
config.eager_load = false
config.logger = Logger.new($stdout)
Rails.logger = config.logger
Expand All @@ -39,6 +39,6 @@ Rails.application.initialize!
run Rails.application

# To run this example run the `rackup` command with this file
# Example: rackup trace_request_demonstration.ru
# Example: rackup trace_demonstration.ru
# Navigate to http://localhost:9292/
# Spans for the requests will appear in the console
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require_relative 'handlers/action_controller'

module OpenTelemetry
module Instrumentation
module ActionPack
# Module that contains custom event handlers, which are used to generate spans per event
module Handlers
module_function

def subscribe
return unless Array(@subscriptions).empty?

config = ActionPack::Instrumentation.instance.config
handlers_by_pattern = {
'process_action.action_controller' => Handlers::ActionController.new(config)
}

@subscriptions = handlers_by_pattern.map do |key, handler|
::ActiveSupport::Notifications.subscribe(key, handler)
end
end

# Removes Event Handler Subscriptions for Action Controller notifications
# @note this method is not thread-safe and should not be used in a multi-threaded context
def unsubscribe
@subscriptions&.each { |subscriber| ::ActiveSupport::Notifications.unsubscribe(subscriber) }
@subscriptions = nil
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
module Instrumentation
module ActionPack
module Handlers
# Action Controller handler to handle the notification from Active Support
class ActionController
# @param config [Hash] of instrumentation options
def initialize(config)
@config = config
end

# Invoked by ActiveSupport::Notifications at the start of the instrumentation block
#
# @param _name [String] of the event (unused)
# @param _id [String] of the event (unused)
# @param payload [Hash] the payload passed as a method argument
# @return [Hash] the payload passed as a method argument
def start(_name, _id, payload)
rack_span = OpenTelemetry::Instrumentation::Rack.current_span

request = payload[:request]

rack_span.name = "#{payload[:controller]}##{payload[:action]}" unless request.env['action_dispatch.exception']

attributes_to_append = {
OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => String(payload[:controller]),
OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => String(payload[:action])
}

attributes_to_append[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = request.filtered_path if request.filtered_path != request.fullpath

rack_span.add_attributes(attributes_to_append)
rescue StandardError => e
OpenTelemetry.handle_error(exception: e)
end

# Invoked by ActiveSupport::Notifications at the end of the instrumentation block
#
# @param _name [String] of the event (unused)
# @param _id [String] of the event (unused)
# @param payload [Hash] the payload passed as a method argument
# @return [Hash] the payload passed as a method argument
def finish(_name, _id, payload)
rack_span = OpenTelemetry::Instrumentation::Rack.current_span
rack_span.record_exception(payload[:exception_object]) if payload[:exception_object]
rescue StandardError => e
OpenTelemetry.handle_error(exception: e)
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def gem_version
end

def patch
::ActionController::Metal.prepend(Patches::ActionController::Metal)
Handlers.subscribe
end

def require_dependencies
require_relative 'patches/action_controller/metal'
require_relative 'handlers'
end

def require_railtie
Expand Down
Loading

0 comments on commit 02555e8

Please sign in to comment.