Skip to content

Commit

Permalink
Merge branch 'main' into create-sql-instrumentation-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin authored Feb 6, 2024
2 parents 32018f7 + 859b6e0 commit 2cf3a7a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/installation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1.169.0
- uses: ruby/setup-ruby@v1.171.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.169.0
uses: ruby/setup-ruby@v1.171.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.169.0
uses: ruby/setup-ruby@v1.171.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.169.0
uses: ruby/setup-ruby@v1.171.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 @@ -47,7 +47,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.169.0
- uses: ruby/setup-ruby@v1.171.0
with:
ruby-version: "3.0"
bundler: latest
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.169.0
uses: ruby/setup-ruby@v1.171.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.169.0
uses: ruby/setup-ruby@v1.171.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def self.with_send_span(channel, tracer, exchange, routing_key, &block)
tracer.in_span("#{destination} publish", attributes: attributes, kind: :producer, &block)
end

def self.with_process_span(channel, tracer, delivery_info, properties, &block) # rubocop:disable Style/ArgumentsForwarding
def self.with_process_span(channel, tracer, delivery_info, properties, &block)
destination = destination_name(delivery_info[:exchange], delivery_info[:routing_key])
parent_context, links = extract_context(properties)

OpenTelemetry::Context.with_current(parent_context) do
tracer.in_span("#{destination} process", links: links, kind: :consumer, &block) # rubocop:disable Style/ArgumentsForwarding
tracer.in_span("#{destination} process", links: links, kind: :consumer, &block)
end
end

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 Resque gem
# (see OpenTelemetry::Instrumentation::Resque::Instrumentation)
module Resque
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,61 @@
module OpenTelemetry
module Instrumentation
module Resque
# The Instrumentation class contains logic to detect and install the Resque instrumentation
# The {OpenTelemetry::Instrumentation::Resque::Instrumentation} class contains logic to detect and install the Resque 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
#
# ### `:span_naming`
#
# Specifies how the span names are set. Can be one of:
#
# - `:queue` **(default)** - The job span name will appear as '<destination / queue name> <operation>',
# for example `default process`.
# - `:job_class` - The job span name will appear as '<job class name> <operation>',
# for example `SimpleJob process`.
#
# ### `:propagation_style`
#
# Specifies how the job's execution is traced and related to the trace where the job was enqueued.
#
# - `:link` **(default)** - The job will be represented by a separate trace from the span that enqueued the job.
# - The initial span of the job trace will be associated with the span that enqueued the job, via a
# {https://opentelemetry.io/docs/concepts/signals/traces/#span-links Span Link}.
# - `:child` - The job will be represented within the same logical trace, as a direct
# child of the span that enqueued the job.
# - `:none` - The job will be represented by a separate trace from the span that enqueued the job.
# There will be no explicit relationship between the job trace and the trace containing the span that
# enqueued the job.
#
# ### `:force_flush`
#
# Specifies whether spans are forcibly flushed (exported out of process) upon every job completion.
#
# - `:ask_the_job` **(default)** - Synchronously flush completed spans when a job completes if workers are
# forked for each job.
# - Determined by checking if {https://www.rubydoc.info/gems/resque/Resque%2FWorker:fork_per_job%3F Resque::Worker#fork_per_job?}
# is true. Spans must be flushed and exported before a worker process terminates or no telemetry will be sent.
# - `:always` - All completed spans will be synchronously flushed at the end of a job's execution.
# - `:never` - Job completion will not affect the export of spans out of worker processes.
# - Selecting this option will result in spans being lost if the worker process ends before
# the spans are flushed. You might select this option if you wish to coordinate the timing for flushing
# completed spans yourself.
#
# @example An explicit default configuration
# OpenTelemetry::SDK.configure do |c|
# c.use_all({
# 'OpenTelemetry::Instrumentation::Resque' => {
# span_naming: :queue,
# propagation_style: :link
# force_flush: :ask_the_job,
# },
# })
# end
class Instrumentation < OpenTelemetry::Instrumentation::Base
install do |_config|
require_dependencies
Expand All @@ -18,30 +72,6 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
defined?(::Resque)
end

## Supported configuration keys for the install config hash:
#
# force_flush: controls if spans are forcibly flushed upon job completion
# - :ask_the_job (default) - if `Resque::Worker#fork_per_job?` is set,
# all completed spans will be synchronously flushed at the end of a
# job's execution
# - :always - all completed spans will be synchronously flushed at the
# end of a job's execution
# - :never - the job will not intervene with the processing of spans
#
# span_naming: when `:job_class`, the span names will be set to
# '<job class name> <operation>'. When `:queue`, the span names
# will be set to '<destination / queue name> <operation>'
#
# propagation_style: controls how the job's execution is traced and related
# to the trace where the job was enqueued. Can be one of:
# - :link (default) - the job will be executed in a separate trace. The
# initial span of the execution trace will be linked to the span that
# enqueued the job, via a Span Link.
# - :child - the job will be executed in the same logical trace, as a direct
# child of the span that enqueued the job.
# - :none - the job's execution will not be explicitly linked to the span that
# enqueued the job.

option :force_flush, default: :ask_the_job, validate: %I[ask_the_job always never]
option :span_naming, default: :queue, validate: %I[job_class queue]
option :propagation_style, default: :link, validate: %i[link child none]
Expand Down

0 comments on commit 2cf3a7a

Please sign in to comment.