diff --git a/.github/actions/test_gem/action.yml b/.github/actions/test_gem/action.yml index 473891f30..06999271c 100644 --- a/.github/actions/test_gem/action.yml +++ b/.github/actions/test_gem/action.yml @@ -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.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: "${{ inputs.ruby }}" working-directory: "${{ steps.setup.outputs.gem_dir }}" @@ -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.176.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: "${{ inputs.ruby }}" bundler: "latest" diff --git a/.github/workflows/conventional-commits.yaml b/.github/workflows/conventional-commits.yaml index 6e9344b7d..26cd79d03 100644 --- a/.github/workflows/conventional-commits.yaml +++ b/.github/workflows/conventional-commits.yaml @@ -22,7 +22,7 @@ jobs: name: Conventional Commits Validation runs-on: ubuntu-latest steps: - - uses: dev-build-deploy/commit-me@v1.4.1 + - uses: dev-build-deploy/commit-me@v1.5.0 env: FORCE_COLOR: 3 with: diff --git a/.github/workflows/installation-tests.yml b/.github/workflows/installation-tests.yml index 8ab8deb43..3fcd407da 100644 --- a/.github/workflows/installation-tests.yml +++ b/.github/workflows/installation-tests.yml @@ -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.178.0 + - uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ matrix.ruby-version }} - name: "Install Latest Gem Versions on ${{ matrix.ruby-version }}" diff --git a/.github/workflows/release-hook-on-closed.yml b/.github/workflows/release-hook-on-closed.yml index 047d64443..bf1273ceb 100644 --- a/.github/workflows/release-hook-on-closed.yml +++ b/.github/workflows/release-hook-on-closed.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ruby ${{ env.ruby_version }} - uses: ruby/setup-ruby@v1.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ env.ruby_version }} - name: Checkout repo diff --git a/.github/workflows/release-hook-on-push.yml b/.github/workflows/release-hook-on-push.yml index 8bc24cbc2..76c2870c0 100644 --- a/.github/workflows/release-hook-on-push.yml +++ b/.github/workflows/release-hook-on-push.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ruby ${{ env.ruby_version }} - uses: ruby/setup-ruby@v1.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ env.ruby_version }} - name: Checkout repo diff --git a/.github/workflows/release-perform.yml b/.github/workflows/release-perform.yml index 584445ca2..ebfef57a4 100644 --- a/.github/workflows/release-perform.yml +++ b/.github/workflows/release-perform.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ruby ${{ env.ruby_version }} - uses: ruby/setup-ruby@v1.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ env.ruby_version }} - name: Checkout repo diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml index e96a72857..fd2f79052 100644 --- a/.github/workflows/release-please.yaml +++ b/.github/workflows/release-please.yaml @@ -17,8 +17,10 @@ jobs: name: Process Release runs-on: ubuntu-latest steps: - - uses: googleapis/release-please-action@v4.1.1 + - uses: googleapis/release-please-action@v4.1.3 id: prepare + # with: + # token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} outputs: paths_released: ${{ steps.prepare.outputs.paths_released }} @@ -48,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.178.0 + - uses: ruby/setup-ruby@v1.180.1 with: ruby-version: "3.0" bundler: latest diff --git a/.github/workflows/release-request-weekly.yml b/.github/workflows/release-request-weekly.yml index 282cfda37..44831942d 100644 --- a/.github/workflows/release-request-weekly.yml +++ b/.github/workflows/release-request-weekly.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ruby ${{ env.ruby_version }} - uses: ruby/setup-ruby@v1.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ env.ruby_version }} - name: Checkout repo diff --git a/.github/workflows/release-request.yml b/.github/workflows/release-request.yml index 9a43e238c..d3f776130 100644 --- a/.github/workflows/release-request.yml +++ b/.github/workflows/release-request.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ruby ${{ env.ruby_version }} - uses: ruby/setup-ruby@v1.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ env.ruby_version }} - name: Checkout repo diff --git a/.github/workflows/release-retry.yml b/.github/workflows/release-retry.yml index bb217c6dd..a0a13e890 100644 --- a/.github/workflows/release-retry.yml +++ b/.github/workflows/release-retry.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ruby ${{ env.ruby_version }} - uses: ruby/setup-ruby@v1.178.0 + uses: ruby/setup-ruby@v1.180.1 with: ruby-version: ${{ env.ruby_version }} - name: Checkout repo diff --git a/.release-please-manifest.json b/.release-please-manifest.json index bda9206b0..b72270bee 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,51 +1,51 @@ { - "helpers/mysql": "0.0.0", - "helpers/sql_obfuscation": "0.0.0", - "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.58.0", + "helpers/mysql": "0.1.1", + "helpers/sql_obfuscation": "0.1.1", + "instrumentation/base": "0.22.4", + "instrumentation/graphql": "0.28.2", + "instrumentation/gruf": "0.2.1", + "instrumentation/racecar": "0.3.2", + "instrumentation/rake": "0.2.2", + "instrumentation/rdkafka": "0.4.6", + "instrumentation/trilogy": "0.59.3", "instrumentation/active_support": "0.5.1", "instrumentation/action_mailer": "0.1.0", "instrumentation/action_view": "0.7.0", "instrumentation/action_pack": "0.9.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/resque": "0.5.2", + "instrumentation/bunny": "0.21.3", + "instrumentation/active_record": "0.7.2", + "instrumentation/aws_sdk": "0.5.2", "instrumentation/aws_lambda": "0.1.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/lmdb": "0.22.2", + "instrumentation/http": "0.23.3", + "instrumentation/http_client": "0.22.6", + "instrumentation/httpx": "0.1.2", + "instrumentation/koala": "0.20.5", "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.24.0", - "instrumentation/rails": "0.30.0", - "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/concurrent_ruby": "0.21.3", + "instrumentation/dalli": "0.25.3", + "instrumentation/delayed_job": "0.22.2", + "instrumentation/ethon": "0.21.7", + "instrumentation/excon": "0.22.3", + "instrumentation/faraday": "0.24.4", + "instrumentation/mongo": "0.22.3", + "instrumentation/mysql2": "0.27.1", + "instrumentation/net_http": "0.22.6", + "instrumentation/pg": "0.27.3", + "instrumentation/que": "0.8.1", + "instrumentation/rack": "0.24.5", + "instrumentation/rails": "0.30.2", + "instrumentation/grape": "0.1.8", + "instrumentation/redis": "0.25.6", + "instrumentation/restclient": "0.22.6", + "instrumentation/rspec": "0.3.3", + "instrumentation/ruby_kafka": "0.21.1", + "instrumentation/sidekiq": "0.25.5", + "instrumentation/sinatra": "0.23.5", "instrumentation/all": "0.56.0", - "processor/baggage": "0.1.0", + "processor/baggage": "0.2.0", "propagator/ottrace": "0.21.2", "propagator/xray": "0.22.1", "resources/azure": "0.1.0", diff --git a/docker-compose.yml b/docker-compose.yml index 0a42dd986..af815eabe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -162,6 +162,12 @@ services: command: ./start_server.sh working_dir: /app/instrumentation/sinatra/example + processor-baggage-test: + <<: *base + working_dir: /app/processor/baggage + command: | + bash -c "bundle install && rake" + mongo: image: mongo:4.4 expose: diff --git a/helpers/mysql/CHANGELOG.md b/helpers/mysql/CHANGELOG.md index a5ef9a1a4..1dc3c9f46 100644 --- a/helpers/mysql/CHANGELOG.md +++ b/helpers/mysql/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-helpers-mysql +### v0.1.1 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.1.0 / 2024-02-08 Initial release. diff --git a/helpers/mysql/lib/opentelemetry/helpers/mysql/version.rb b/helpers/mysql/lib/opentelemetry/helpers/mysql/version.rb index f66da3eea..2d047426c 100644 --- a/helpers/mysql/lib/opentelemetry/helpers/mysql/version.rb +++ b/helpers/mysql/lib/opentelemetry/helpers/mysql/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Helpers module MySQL - VERSION = '0.1.0' + VERSION = '0.1.1' end end end diff --git a/helpers/mysql/opentelemetry-helpers-mysql.gemspec b/helpers/mysql/opentelemetry-helpers-mysql.gemspec index 0635634c8..1c18e0fe8 100644 --- a/helpers/mysql/opentelemetry-helpers-mysql.gemspec +++ b/helpers/mysql/opentelemetry-helpers-mysql.gemspec @@ -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-common', '~> 0.20' + spec.add_dependency 'opentelemetry-common', '~> 0.21' spec.add_development_dependency 'bundler', '~> 2.4' spec.add_development_dependency 'minitest', '~> 5.0' diff --git a/helpers/sql-obfuscation/CHANGELOG.md b/helpers/sql-obfuscation/CHANGELOG.md index aede3a34e..7a62283ca 100644 --- a/helpers/sql-obfuscation/CHANGELOG.md +++ b/helpers/sql-obfuscation/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-helpers-sql-obfuscation +### v0.1.1 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.1.0 / 2024-02-08 Initial release. diff --git a/helpers/sql-obfuscation/lib/opentelemetry/helpers/sql_obfuscation/version.rb b/helpers/sql-obfuscation/lib/opentelemetry/helpers/sql_obfuscation/version.rb index 9861b8920..4d0787456 100644 --- a/helpers/sql-obfuscation/lib/opentelemetry/helpers/sql_obfuscation/version.rb +++ b/helpers/sql-obfuscation/lib/opentelemetry/helpers/sql_obfuscation/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Helpers module SqlObfuscation - VERSION = '0.1.0' + VERSION = '0.1.1' end end end diff --git a/helpers/sql-obfuscation/opentelemetry-helpers-sql-obfuscation.gemspec b/helpers/sql-obfuscation/opentelemetry-helpers-sql-obfuscation.gemspec index 274324dbb..5143fc7d6 100644 --- a/helpers/sql-obfuscation/opentelemetry-helpers-sql-obfuscation.gemspec +++ b/helpers/sql-obfuscation/opentelemetry-helpers-sql-obfuscation.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.required_ruby_version = '>= 3.0' - spec.add_dependency 'opentelemetry-common', '~> 0.20' + spec.add_dependency 'opentelemetry-common', '~> 0.21' spec.add_development_dependency 'bundler', '~> 2.4' spec.add_development_dependency 'minitest', '~> 5.0' diff --git a/instrumentation/active_job/Appraisals b/instrumentation/active_job/Appraisals index 05429cd62..a25edd334 100644 --- a/instrumentation/active_job/Appraisals +++ b/instrumentation/active_job/Appraisals @@ -9,3 +9,7 @@ gem 'activejob', "~> #{version}" end end + +appraise 'activejob-latest' do + gem 'activejob' +end diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb index 9a5db43b5..692346aeb 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb @@ -41,9 +41,9 @@ def start(name, id, payload) # @return [Hash] with the span and generated context tokens def start_span(name, _id, payload) span = tracer.start_span(name, attributes: @mapper.call(payload)) - tokens = [OpenTelemetry::Context.attach(OpenTelemetry::Trace.context_with_span(span))] + token = OpenTelemetry::Context.attach(OpenTelemetry::Trace.context_with_span(span)) - { span: span, ctx_tokens: tokens } + { span: span, ctx_token: token } end # Creates a span and registers it with the current context @@ -55,20 +55,20 @@ def start_span(name, _id, payload) def finish(_name, _id, payload) otel = payload.delete(:__otel) span = otel&.fetch(:span) - tokens = otel&.fetch(:ctx_tokens) + token = otel&.fetch(:ctx_token) on_exception((payload[:error] || payload[:exception_object]), span) rescue StandardError => e OpenTelemetry.handle_error(exception: e) ensure - finish_span(span, tokens) + finish_span(span, token) end # Finishes the provided spans and also detaches the associated contexts # # @param span [OpenTelemetry::Trace::Span] - # @param tokens [Array] to unregister - def finish_span(span, tokens) + # @param token [Numeric] to unregister + def finish_span(span, token) # closes the span after all attributes have been finalized begin if span&.recording? @@ -79,8 +79,7 @@ def finish_span(span, tokens) OpenTelemetry.handle_error(exception: e) end - # pops the context stack - tokens&.reverse_each do |token| + begin OpenTelemetry::Context.detach(token) rescue StandardError => e OpenTelemetry.handle_error(exception: e) diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb index 7dace8a95..4b4c55937 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/enqueue.rb @@ -29,9 +29,8 @@ def initialize(...) def start_span(name, _id, payload) job = payload.fetch(:job) span = tracer.start_span(@span_name_formatter.call(job), kind: :producer, attributes: @mapper.call(payload)) - tokens = [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_tokens: tokens } + { span: span, ctx_token: OpenTelemetry::Context.attach(OpenTelemetry::Trace.context_with_span(span)) } end end end diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb index 6dd7e2e28..bbfd2ed27 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/perform.rb @@ -27,7 +27,6 @@ def initialize(...) # @param payload [Hash] containing job run information # @return [Hash] with the span and generated context tokens def start_span(name, _id, payload) - tokens = [] job = payload.fetch(:job) parent_context = OpenTelemetry.propagation.extract(job.__otel_headers) @@ -36,7 +35,6 @@ def start_span(name, _id, payload) # TODO: Refactor into a propagation strategy propagation_style = @config[:propagation_style] if propagation_style == :child - tokens << OpenTelemetry::Context.attach(parent_context) span = tracer.start_span(span_name, kind: :consumer, attributes: @mapper.call(payload)) else span_context = OpenTelemetry::Trace.current_span(parent_context).context @@ -44,9 +42,7 @@ def start_span(name, _id, payload) span = tracer.start_root_span(span_name, kind: :consumer, attributes: @mapper.call(payload), links: links) end - tokens.concat(attach_consumer_context(span)) - - { span: span, ctx_tokens: tokens } + { span: span, ctx_token: attach_consumer_context(span) } end # This method attaches a span to multiple contexts: @@ -54,12 +50,12 @@ def start_span(name, _id, payload) # This is used later to enrich the ingress span in children, e.g. setting span status to error when a child event like `discard` terminates due to an error # 2. Registers the ingress span as the "active" span, which is the default behavior of the SDK. # @param span [OpenTelemetry::Trace::Span] the currently active span used to record the exception and set the status - # @return [Array] Context tokens that must be detached when finished + # @return [Numeric] Context token that must be detached when finished def attach_consumer_context(span) consumer_context = OpenTelemetry::Trace.context_with_span(span) internal_context = OpenTelemetry::Instrumentation::ActiveJob.context_with_span(span, parent_context: consumer_context) - [consumer_context, internal_context].map { |context| OpenTelemetry::Context.attach(context) } + OpenTelemetry::Context.attach(internal_context) end end end diff --git a/instrumentation/active_support/CHANGELOG.md b/instrumentation/active_support/CHANGELOG.md index 47f8a176c..7dd2c8d6c 100644 --- a/instrumentation/active_support/CHANGELOG.md +++ b/instrumentation/active_support/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-active_support +### v0.5.2 / 2024-06-20 + +* ADDED: ActiveSupport user specified span kind + ### v0.5.1 / 2023-11-23 * CHANGED: Applied Rubocop Performance Recommendations [#727](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/727) diff --git a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb index 71692168a..8c9e879e8 100644 --- a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb +++ b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb @@ -19,13 +19,15 @@ def self.subscribe( tracer, pattern, notification_payload_transform = nil, - disallowed_notification_payload_keys = [] + disallowed_notification_payload_keys = [], + kind: nil ) subscriber = OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber.new( name: pattern, tracer: tracer, notification_payload_transform: notification_payload_transform, - disallowed_notification_payload_keys: disallowed_notification_payload_keys + disallowed_notification_payload_keys: disallowed_notification_payload_keys, + kind: kind ) subscriber_object = ::ActiveSupport::Notifications.subscribe(pattern, subscriber) @@ -55,15 +57,16 @@ def self.subscribe( class SpanSubscriber ALWAYS_VALID_PAYLOAD_TYPES = [TrueClass, FalseClass, String, Numeric, Symbol].freeze - def initialize(name:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: []) + def initialize(name:, tracer:, notification_payload_transform: nil, disallowed_notification_payload_keys: [], kind: nil) @span_name = name.split('.')[0..1].reverse.join(' ').freeze @tracer = tracer @notification_payload_transform = notification_payload_transform @disallowed_notification_payload_keys = disallowed_notification_payload_keys + @kind = kind || :internal end def start(name, id, payload) - span = @tracer.start_span(@span_name, kind: :internal) + span = @tracer.start_span(@span_name, kind: @kind) token = OpenTelemetry::Context.attach( OpenTelemetry::Trace.context_with_span(span) ) diff --git a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb index 60c531ca6..1b7ee02b5 100644 --- a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb +++ b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module ActiveSupport - VERSION = '0.5.1' + VERSION = '0.5.2' end end end diff --git a/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb b/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb index b88b27a1a..61afd26fa 100644 --- a/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb +++ b/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb @@ -11,10 +11,12 @@ let(:tracer) { instrumentation.tracer } let(:exporter) { EXPORTER } let(:last_span) { exporter.finished_spans.last } + let(:span_kind) { nil } let(:subscriber) do OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber.new( name: 'bar.foo', - tracer: tracer + tracer: tracer, + kind: span_kind ) end @@ -76,6 +78,7 @@ def finish(name, id, payload) ) _(last_span).wont_be_nil + _(last_span.kind).must_equal(:internal) _(last_span.attributes['string']).must_equal('keys_are_present') _(last_span.attributes['numeric_is_fine']).must_equal(1) _(last_span.attributes['boolean_okay?']).must_equal(true) @@ -182,6 +185,24 @@ def finish(name, id, payload) end end + describe 'given a span kind' do + let(:span_kind) { :client } + + it 'sets the kind on the span' do + span, token = subscriber.start('hai', 'abc', {}) + # We only use the finished attributes - could change in the future, perhaps. + subscriber.finish( + 'hai', + 'abc', + __opentelemetry_span: span, + __opentelemetry_ctx_token: token + ) + + _(last_span).wont_be_nil + _(last_span.kind).must_equal(:client) + end + end + describe 'instrument' do before do ActiveSupport::Notifications.unsubscribe('bar.foo') @@ -202,6 +223,7 @@ def finish(name, id, payload) _(last_span).wont_be_nil _(last_span.name).must_equal('foo bar') _(last_span.attributes['extra']).must_equal('context') + _(last_span.kind).must_equal(:internal) end it 'finishes spans even when block subscribers blow up' do @@ -239,5 +261,15 @@ def finish(name, id, payload) _(obj.class).must_equal(ActiveSupport::Notifications::Fanout::Subscribers::Evented) _(last_span).must_be_nil end + + it 'supports setting the span kind' do + OpenTelemetry::Instrumentation::ActiveSupport.subscribe(tracer, 'bar.foo', nil, [], kind: :client) + ActiveSupport::Notifications.instrument('bar.foo', extra: 'context') + + _(last_span).wont_be_nil + _(last_span.name).must_equal('foo bar') + _(last_span.attributes['extra']).must_equal('context') + _(last_span.kind).must_equal(:client) + end end end diff --git a/instrumentation/base/CHANGELOG.md b/instrumentation/base/CHANGELOG.md index 575d63cd8..b51a63149 100644 --- a/instrumentation/base/CHANGELOG.md +++ b/instrumentation/base/CHANGELOG.md @@ -1,5 +1,10 @@ # Release History: opentelemetry-instrumentation-base +### v0.22.4 / 2024-06-18 + +* FIXED: Relax otel common gem constraints +* DOCS: Add function doc for config_overrides_from_env + ### v0.22.3 / 2023-11-23 * CHANGED: Applied Rubocop Performance Recommendations [#727](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/727) diff --git a/instrumentation/base/lib/opentelemetry/instrumentation/base.rb b/instrumentation/base/lib/opentelemetry/instrumentation/base.rb index 4e08be3ea..8c9ac0e3f 100644 --- a/instrumentation/base/lib/opentelemetry/instrumentation/base.rb +++ b/instrumentation/base/lib/opentelemetry/instrumentation/base.rb @@ -326,6 +326,18 @@ def enabled_by_env_var? ENV[var_name] != 'false' end + # Checks to see if the user has passed any environment variables that set options + # for instrumentation. By convention, the environment variable will be the name + # of the instrumentation, uppercased, with '::' replaced by underscores, + # OPENTELEMETRY shortened to OTEL_{LANG}, and _CONFIG_OPTS appended. + # For example, the environment variable name for OpenTelemetry::Instrumentation::Faraday + # will be OTEL_RUBY_INSTRUMENTATION_FARADAY_CONFIG_OPTS. A value of 'peer_service=new_service;' + # will override the options set from ::OpenTelemetry::SDK.configure do |c| ... end for Faraday. + # + # For an array option, simply separate the values with commas (e.g., option=a,b,c,d). + # For a boolean option, set the value to true or false (e.g., option=true). + # For integer, string, enum, set the value as a string (e.g., option=string). + # Callable options are not allowed to be set through environment variables. def config_overrides_from_env var_name = name.dup.tap do |n| n.upcase! diff --git a/instrumentation/base/lib/opentelemetry/instrumentation/version.rb b/instrumentation/base/lib/opentelemetry/instrumentation/version.rb index 0f05e445e..297acbb24 100644 --- a/instrumentation/base/lib/opentelemetry/instrumentation/version.rb +++ b/instrumentation/base/lib/opentelemetry/instrumentation/version.rb @@ -6,6 +6,6 @@ module OpenTelemetry module Instrumentation - VERSION = '0.22.3' + VERSION = '0.22.4' end end diff --git a/instrumentation/base/opentelemetry-instrumentation-base.gemspec b/instrumentation/base/opentelemetry-instrumentation-base.gemspec index 62753b9ad..25e2a83c8 100644 --- a/instrumentation/base/opentelemetry-instrumentation-base.gemspec +++ b/instrumentation/base/opentelemetry-instrumentation-base.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' + spec.add_dependency 'opentelemetry-common', '~> 0.21' spec.add_dependency 'opentelemetry-registry', '~> 0.1' spec.add_development_dependency 'bundler', '~> 2.4' diff --git a/instrumentation/dalli/CHANGELOG.md b/instrumentation/dalli/CHANGELOG.md index 444e51488..92c503a09 100644 --- a/instrumentation/dalli/CHANGELOG.md +++ b/instrumentation/dalli/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-dalli +### v0.25.3 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.25.2 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb index c08c8100d..19a3ba981 100644 --- a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb +++ b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Dalli - VERSION = '0.25.2' + VERSION = '0.25.3' end end end diff --git a/instrumentation/dalli/opentelemetry-instrumentation-dalli.gemspec b/instrumentation/dalli/opentelemetry-instrumentation-dalli.gemspec index eec02d53e..19317f687 100644 --- a/instrumentation/dalli/opentelemetry-instrumentation-dalli.gemspec +++ b/instrumentation/dalli/opentelemetry-instrumentation-dalli.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/ethon/CHANGELOG.md b/instrumentation/ethon/CHANGELOG.md index 160a95104..5c6418836 100644 --- a/instrumentation/ethon/CHANGELOG.md +++ b/instrumentation/ethon/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-ethon +### v0.21.7 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.21.6 / 2024-06-12 * FIXED: Add net.peer.name to ethon diff --git a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/version.rb b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/version.rb index 1b74051bf..32be6eb25 100644 --- a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/version.rb +++ b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Ethon - VERSION = '0.21.6' + VERSION = '0.21.7' end end end diff --git a/instrumentation/ethon/opentelemetry-instrumentation-ethon.gemspec b/instrumentation/ethon/opentelemetry-instrumentation-ethon.gemspec index b1e0c911c..002bcef71 100644 --- a/instrumentation/ethon/opentelemetry-instrumentation-ethon.gemspec +++ b/instrumentation/ethon/opentelemetry-instrumentation-ethon.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/excon/CHANGELOG.md b/instrumentation/excon/CHANGELOG.md index 95ba63b54..dbef84bab 100644 --- a/instrumentation/excon/CHANGELOG.md +++ b/instrumentation/excon/CHANGELOG.md @@ -1,5 +1,10 @@ # Release History: opentelemetry-instrumentation-excon +### v0.22.3 / 2024-06-18 + +* FIXED: Relax otel common gem constraints +* FIXED: Add `http.url` to Excon instrumentation + ### v0.22.2 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb b/instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb index ca0b50d7f..592fdb793 100644 --- a/instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb +++ b/instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb @@ -27,10 +27,11 @@ def request_call(datum) http_method = HTTP_METHODS_TO_UPPERCASE[datum[:method]] attributes = { + OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host], OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => http_method, OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => datum[:scheme], OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => datum[:path], - OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host], + OpenTelemetry::SemanticConventions::Trace::HTTP_URL => OpenTelemetry::Common::Utilities.cleanse_url(::Excon::Utils.request_uri(datum)), OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => datum[:hostname], OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => datum[:port] } diff --git a/instrumentation/excon/lib/opentelemetry/instrumentation/excon/version.rb b/instrumentation/excon/lib/opentelemetry/instrumentation/excon/version.rb index c1d732bfb..486b0200a 100644 --- a/instrumentation/excon/lib/opentelemetry/instrumentation/excon/version.rb +++ b/instrumentation/excon/lib/opentelemetry/instrumentation/excon/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Excon - VERSION = '0.22.2' + VERSION = '0.22.3' end end end diff --git a/instrumentation/excon/opentelemetry-instrumentation-excon.gemspec b/instrumentation/excon/opentelemetry-instrumentation-excon.gemspec index f4ef1c778..ce3de4604 100644 --- a/instrumentation/excon/opentelemetry-instrumentation-excon.gemspec +++ b/instrumentation/excon/opentelemetry-instrumentation-excon.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/excon/test/opentelemetry/instrumentation/excon/instrumentation_test.rb b/instrumentation/excon/test/opentelemetry/instrumentation/excon/instrumentation_test.rb index 94f354c09..6f085689b 100644 --- a/instrumentation/excon/test/opentelemetry/instrumentation/excon/instrumentation_test.rb +++ b/instrumentation/excon/test/opentelemetry/instrumentation/excon/instrumentation_test.rb @@ -48,11 +48,12 @@ _(exporter.finished_spans.size).must_equal 1 _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.host']).must_equal 'example.com' _(span.attributes['http.method']).must_equal 'GET' - _(span.attributes['http.status_code']).must_equal 200 _(span.attributes['http.scheme']).must_equal 'http' - _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.status_code']).must_equal 200 _(span.attributes['http.target']).must_equal '/success' + _(span.attributes['http.url']).must_equal 'http://example.com/success' assert_requested( :get, 'http://example.com/success', @@ -71,11 +72,12 @@ _(exporter.finished_spans.size).must_equal 1 _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.host']).must_equal 'example.com' _(span.attributes['http.method']).must_equal 'GET' - _(span.attributes['http.status_code']).must_equal 500 _(span.attributes['http.scheme']).must_equal 'http' - _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.status_code']).must_equal 500 _(span.attributes['http.target']).must_equal '/failure' + _(span.attributes['http.url']).must_equal 'http://example.com/failure' assert_requested( :get, 'http://example.com/failure', @@ -90,10 +92,11 @@ _(exporter.finished_spans.size).must_equal 1 _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.host']).must_equal 'example.com' _(span.attributes['http.method']).must_equal 'GET' _(span.attributes['http.scheme']).must_equal 'http' - _(span.attributes['http.host']).must_equal 'example.com' _(span.attributes['http.target']).must_equal '/timeout' + _(span.attributes['http.url']).must_equal 'http://example.com/timeout' _(span.status.code).must_equal( OpenTelemetry::Trace::Status::ERROR ) @@ -119,11 +122,12 @@ _(exporter.finished_spans.size).must_equal 1 _(span.name).must_equal 'HTTP GET' + _(span.attributes['http.host']).must_equal 'example.com' _(span.attributes['http.method']).must_equal 'OVERRIDE' - _(span.attributes['http.status_code']).must_equal 200 _(span.attributes['http.scheme']).must_equal 'http' - _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.status_code']).must_equal 200 _(span.attributes['http.target']).must_equal '/success' + _(span.attributes['http.url']).must_equal 'http://example.com/success' _(span.attributes['test.attribute']).must_equal 'test.value' assert_requested( :get, @@ -186,8 +190,8 @@ _(exporter.finished_spans.size).must_equal 1 _(span.name).must_equal 'HTTP GET' - _(span.attributes['http.method']).must_equal 'GET' _(span.attributes['http.host']).must_equal 'example.com' + _(span.attributes['http.method']).must_equal 'GET' end it 'creates a span on connect for a non-ignored request' do @@ -215,6 +219,8 @@ end it 'emits span on connect' do + port = nil + TCPServer.open('localhost', 0) do |server| Thread.start do server.accept @@ -231,8 +237,9 @@ _(span.name).must_equal 'connect' _(span.attributes['net.peer.name']).must_equal('localhost') _(span.attributes['net.peer.port']).wont_be_nil + _(span.attributes['net.peer.port']).must_equal(port) - assert_http_spans(target: '/example', exception: 'Excon::Error::Timeout') + assert_http_spans(port: port, target: '/example', exception: 'Excon::Error::Timeout') end it 'captures errors' do @@ -248,7 +255,7 @@ # Depending on the Ruby and Excon Version this will be a SocketError, Socket::ResolutionError or Resolv::ResolvError _(span_event.attributes['exception.type']).must_match(/(Socket|Resolv)/) - assert_http_spans(host: 'invalid.com', target: '/example') + assert_http_spans(host: 'invalid.com', port: 99_999, target: '/example') end it '[BUG] fails to emit an HTTP CONNECT span when connecting through an SSL proxy for an HTTP service' do @@ -296,13 +303,14 @@ end end - def assert_http_spans(scheme: 'http', host: 'localhost', target: '/', exception: nil) + def assert_http_spans(scheme: 'http', host: 'localhost', port: nil, target: '/', exception: nil) exporter.finished_spans[1..].each do |http_span| _(http_span.name).must_equal 'HTTP GET' + _(http_span.attributes['http.host']).must_equal host _(http_span.attributes['http.method']).must_equal 'GET' _(http_span.attributes['http.scheme']).must_equal scheme - _(http_span.attributes['http.host']).must_equal host _(http_span.attributes['http.target']).must_equal target + _(http_span.attributes['http.url']).must_equal "#{scheme}://#{host}#{port&.to_s&.prepend(':')}#{target}" _(http_span.status.code).must_equal( OpenTelemetry::Trace::Status::ERROR ) diff --git a/instrumentation/faraday/CHANGELOG.md b/instrumentation/faraday/CHANGELOG.md index 25e1b92a3..a3e04733d 100644 --- a/instrumentation/faraday/CHANGELOG.md +++ b/instrumentation/faraday/CHANGELOG.md @@ -1,5 +1,13 @@ # Release History: opentelemetry-instrumentation-faraday +### v0.24.5 / 2024-06-20 + +* FIXED: Compatibility with Faraday v1 + +### v0.24.4 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.24.3 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/instrumentation.rb b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/instrumentation.rb index abed74af4..17d4826e8 100644 --- a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/instrumentation.rb +++ b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/instrumentation.rb @@ -27,6 +27,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base def require_dependencies require_relative 'middlewares/tracer_middleware' + require_relative 'patches/connection' require_relative 'patches/rack_builder' end @@ -37,7 +38,11 @@ def register_tracer_middleware end def use_middleware_by_default - ::Faraday::RackBuilder.prepend(Patches::RackBuilder) + if Gem::Version.new(::Faraday::VERSION) >= Gem::Version.new('1') + ::Faraday::Connection.prepend(Patches::Connection) + else + ::Faraday::RackBuilder.prepend(Patches::RackBuilder) + end end end end diff --git a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/patches/connection.rb b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/patches/connection.rb new file mode 100644 index 000000000..51d8ad0b5 --- /dev/null +++ b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/patches/connection.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Instrumentation + module Faraday + module Patches + # Module to be prepended to force Faraday to use the middleware by + # default so the user doesn't have to call `use` for every connection. + module Connection + # Wraps Faraday::Connection#initialize: + # https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92 + def initialize(*args) + super.tap do + use(:open_telemetry) unless builder.handlers.any? do |handler| + handler.klass == Middlewares::TracerMiddleware + end + end + end + end + end + end + end +end diff --git a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb index 370cde384..f049c317f 100644 --- a/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb +++ b/instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Faraday - VERSION = '0.24.3' + VERSION = '0.24.5' end end end diff --git a/instrumentation/faraday/opentelemetry-instrumentation-faraday.gemspec b/instrumentation/faraday/opentelemetry-instrumentation-faraday.gemspec index 57cd82629..ecea6f673 100644 --- a/instrumentation/faraday/opentelemetry-instrumentation-faraday.gemspec +++ b/instrumentation/faraday/opentelemetry-instrumentation-faraday.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb index acedc19d2..8a0def73c 100644 --- a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb +++ b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware_test.rb @@ -198,5 +198,18 @@ _(span.status.code).must_equal OpenTelemetry::Trace::Status::ERROR end end + + describe 'when explicitly adding the tracer middleware' do + let(:client) do + Faraday.new do |builder| + builder.use :open_telemetry + end + end + + it 'only adds the middleware once' do + tracers = client.builder.handlers.count(OpenTelemetry::Instrumentation::Faraday::Middlewares::TracerMiddleware) + _(tracers).must_equal 1 + end + end end end diff --git a/instrumentation/grape/Gemfile b/instrumentation/grape/Gemfile index ed1ec924e..a97f3cccf 100644 --- a/instrumentation/grape/Gemfile +++ b/instrumentation/grape/Gemfile @@ -15,4 +15,5 @@ gemspec group :test do gem 'opentelemetry-instrumentation-base', path: '../base' gem 'opentelemetry-instrumentation-rack', path: '../rack' + gem 'builder' end diff --git a/instrumentation/http_client/CHANGELOG.md b/instrumentation/http_client/CHANGELOG.md index 57272442c..419dfcfa4 100644 --- a/instrumentation/http_client/CHANGELOG.md +++ b/instrumentation/http_client/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-http_client +### v0.22.6 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.22.5 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/http_client/lib/opentelemetry/instrumentation/http_client/version.rb b/instrumentation/http_client/lib/opentelemetry/instrumentation/http_client/version.rb index 93dfe3a64..5f263a756 100644 --- a/instrumentation/http_client/lib/opentelemetry/instrumentation/http_client/version.rb +++ b/instrumentation/http_client/lib/opentelemetry/instrumentation/http_client/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module HttpClient - VERSION = '0.22.5' + VERSION = '0.22.6' end end end diff --git a/instrumentation/http_client/opentelemetry-instrumentation-http_client.gemspec b/instrumentation/http_client/opentelemetry-instrumentation-http_client.gemspec index 13d2ce572..d393f10e0 100644 --- a/instrumentation/http_client/opentelemetry-instrumentation-http_client.gemspec +++ b/instrumentation/http_client/opentelemetry-instrumentation-http_client.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/koala/CHANGELOG.md b/instrumentation/koala/CHANGELOG.md index a222a5fc1..1cd0e5d62 100644 --- a/instrumentation/koala/CHANGELOG.md +++ b/instrumentation/koala/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-koala +### v0.20.5 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.20.4 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/koala/lib/opentelemetry/instrumentation/koala/version.rb b/instrumentation/koala/lib/opentelemetry/instrumentation/koala/version.rb index eb721f1ca..7d2588e92 100644 --- a/instrumentation/koala/lib/opentelemetry/instrumentation/koala/version.rb +++ b/instrumentation/koala/lib/opentelemetry/instrumentation/koala/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Koala - VERSION = '0.20.4' + VERSION = '0.20.5' end end end diff --git a/instrumentation/koala/opentelemetry-instrumentation-koala.gemspec b/instrumentation/koala/opentelemetry-instrumentation-koala.gemspec index 9b10f5568..708f34484 100644 --- a/instrumentation/koala/opentelemetry-instrumentation-koala.gemspec +++ b/instrumentation/koala/opentelemetry-instrumentation-koala.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/net_http/CHANGELOG.md b/instrumentation/net_http/CHANGELOG.md index ab2aee20a..50cb64973 100644 --- a/instrumentation/net_http/CHANGELOG.md +++ b/instrumentation/net_http/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-net_http +### v0.22.6 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.22.5 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/net_http/lib/opentelemetry/instrumentation/net/http/version.rb b/instrumentation/net_http/lib/opentelemetry/instrumentation/net/http/version.rb index e432ec226..f8b0c8666 100644 --- a/instrumentation/net_http/lib/opentelemetry/instrumentation/net/http/version.rb +++ b/instrumentation/net_http/lib/opentelemetry/instrumentation/net/http/version.rb @@ -8,7 +8,7 @@ module OpenTelemetry module Instrumentation module Net module HTTP - VERSION = '0.22.5' + VERSION = '0.22.6' end end end diff --git a/instrumentation/net_http/opentelemetry-instrumentation-net_http.gemspec b/instrumentation/net_http/opentelemetry-instrumentation-net_http.gemspec index fec9d2393..8352bcf70 100644 --- a/instrumentation/net_http/opentelemetry-instrumentation-net_http.gemspec +++ b/instrumentation/net_http/opentelemetry-instrumentation-net_http.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'bundler', '~> 2.4' diff --git a/instrumentation/rack/CHANGELOG.md b/instrumentation/rack/CHANGELOG.md index ec2b37d58..540499280 100644 --- a/instrumentation/rack/CHANGELOG.md +++ b/instrumentation/rack/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-rack +### v0.24.5 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.24.4 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/rack/lib/opentelemetry/instrumentation/rack/version.rb b/instrumentation/rack/lib/opentelemetry/instrumentation/rack/version.rb index e2957bcbd..082779a2e 100644 --- a/instrumentation/rack/lib/opentelemetry/instrumentation/rack/version.rb +++ b/instrumentation/rack/lib/opentelemetry/instrumentation/rack/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Rack - VERSION = '0.24.4' + VERSION = '0.24.5' end end end diff --git a/instrumentation/rack/opentelemetry-instrumentation-rack.gemspec b/instrumentation/rack/opentelemetry-instrumentation-rack.gemspec index bce62dfb8..6381e7f71 100644 --- a/instrumentation/rack/opentelemetry-instrumentation-rack.gemspec +++ b/instrumentation/rack/opentelemetry-instrumentation-rack.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/rdkafka/CHANGELOG.md b/instrumentation/rdkafka/CHANGELOG.md index bcbbd9d17..3fc78ff06 100644 --- a/instrumentation/rdkafka/CHANGELOG.md +++ b/instrumentation/rdkafka/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-rdkafka +### v0.4.6 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.4.5 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/rdkafka/lib/opentelemetry/instrumentation/rdkafka/version.rb b/instrumentation/rdkafka/lib/opentelemetry/instrumentation/rdkafka/version.rb index b29aba3d5..481f05b9f 100644 --- a/instrumentation/rdkafka/lib/opentelemetry/instrumentation/rdkafka/version.rb +++ b/instrumentation/rdkafka/lib/opentelemetry/instrumentation/rdkafka/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Rdkafka - VERSION = '0.4.5' + VERSION = '0.4.6' end end end diff --git a/instrumentation/rdkafka/opentelemetry-instrumentation-rdkafka.gemspec b/instrumentation/rdkafka/opentelemetry-instrumentation-rdkafka.gemspec index 5995f3d4f..afd16cdf0 100644 --- a/instrumentation/rdkafka/opentelemetry-instrumentation-rdkafka.gemspec +++ b/instrumentation/rdkafka/opentelemetry-instrumentation-rdkafka.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/redis/CHANGELOG.md b/instrumentation/redis/CHANGELOG.md index 50976b1bf..39cf15af2 100644 --- a/instrumentation/redis/CHANGELOG.md +++ b/instrumentation/redis/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-redis +### v0.25.6 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.25.5 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/redis/lib/opentelemetry/instrumentation/redis/version.rb b/instrumentation/redis/lib/opentelemetry/instrumentation/redis/version.rb index 60eb007b2..f386662f2 100644 --- a/instrumentation/redis/lib/opentelemetry/instrumentation/redis/version.rb +++ b/instrumentation/redis/lib/opentelemetry/instrumentation/redis/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Redis - VERSION = '0.25.5' + VERSION = '0.25.6' end end end diff --git a/instrumentation/redis/opentelemetry-instrumentation-redis.gemspec b/instrumentation/redis/opentelemetry-instrumentation-redis.gemspec index e4ae49193..811f3e09f 100644 --- a/instrumentation/redis/opentelemetry-instrumentation-redis.gemspec +++ b/instrumentation/redis/opentelemetry-instrumentation-redis.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/restclient/CHANGELOG.md b/instrumentation/restclient/CHANGELOG.md index 415181a70..101fa104d 100644 --- a/instrumentation/restclient/CHANGELOG.md +++ b/instrumentation/restclient/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-restclient +### v0.22.6 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.22.5 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/restclient/lib/opentelemetry/instrumentation/restclient/version.rb b/instrumentation/restclient/lib/opentelemetry/instrumentation/restclient/version.rb index 3b51ebd04..00ddf501a 100644 --- a/instrumentation/restclient/lib/opentelemetry/instrumentation/restclient/version.rb +++ b/instrumentation/restclient/lib/opentelemetry/instrumentation/restclient/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module RestClient - VERSION = '0.22.5' + VERSION = '0.22.6' end end end diff --git a/instrumentation/restclient/opentelemetry-instrumentation-restclient.gemspec b/instrumentation/restclient/opentelemetry-instrumentation-restclient.gemspec index d192d6150..41d031184 100644 --- a/instrumentation/restclient/opentelemetry-instrumentation-restclient.gemspec +++ b/instrumentation/restclient/opentelemetry-instrumentation-restclient.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' diff --git a/instrumentation/sidekiq/CHANGELOG.md b/instrumentation/sidekiq/CHANGELOG.md index 12acfff9f..f8a047837 100644 --- a/instrumentation/sidekiq/CHANGELOG.md +++ b/instrumentation/sidekiq/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-sidekiq +### v0.25.5 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.25.4 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/version.rb b/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/version.rb index c7482c923..954028728 100644 --- a/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/version.rb +++ b/instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Sidekiq - VERSION = '0.25.4' + VERSION = '0.25.5' end end end diff --git a/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec b/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec index daf1a5cbd..7c1c4c184 100644 --- a/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec +++ b/instrumentation/sidekiq/opentelemetry-instrumentation-sidekiq.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'activejob', '>= 6.0' diff --git a/instrumentation/sinatra/CHANGELOG.md b/instrumentation/sinatra/CHANGELOG.md index f593edcbd..4c72110a3 100644 --- a/instrumentation/sinatra/CHANGELOG.md +++ b/instrumentation/sinatra/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-sinatra +### v0.23.5 / 2024-06-18 + +* FIXED: Relax otel common gem constraints + ### v0.23.4 / 2024-05-09 * FIXED: Untrace entire request diff --git a/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/version.rb b/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/version.rb index b4878fbde..e4b4b4895 100644 --- a/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/version.rb +++ b/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/version.rb @@ -7,7 +7,7 @@ module OpenTelemetry module Instrumentation module Sinatra - VERSION = '0.23.4' + VERSION = '0.23.5' end end end diff --git a/instrumentation/sinatra/opentelemetry-instrumentation-sinatra.gemspec b/instrumentation/sinatra/opentelemetry-instrumentation-sinatra.gemspec index 06dfd9b20..20da3876f 100644 --- a/instrumentation/sinatra/opentelemetry-instrumentation-sinatra.gemspec +++ b/instrumentation/sinatra/opentelemetry-instrumentation-sinatra.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.0' spec.add_dependency 'opentelemetry-api', '~> 1.0' - spec.add_dependency 'opentelemetry-common', '~> 0.21.0' spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_dependency 'opentelemetry-instrumentation-rack', '~> 0.21' diff --git a/processor/baggage/CHANGELOG.md b/processor/baggage/CHANGELOG.md index a054e650e..9b948ba54 100644 --- a/processor/baggage/CHANGELOG.md +++ b/processor/baggage/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History: opentelemetry-processor-baggage +### v0.2.0 / 2024-06-18 + +* BREAKING CHANGE: Add baggage key predicate func to baggage span processor + +* ADDED: Add baggage key predicate func to baggage span processor + ### v0.1.0 / 2024-04-18 * Initial release. diff --git a/processor/baggage/README.md b/processor/baggage/README.md index b880f1150..0c5bc8b93 100644 --- a/processor/baggage/README.md +++ b/processor/baggage/README.md @@ -2,7 +2,7 @@ This is an OpenTelemetry [span processor](https://opentelemetry.io/docs/specs/otel/trace/sdk/#span-processor) that reads key/values stored in [Baggage](https://opentelemetry.io/docs/specs/otel/baggage/api/) in the starting span's parent context and adds them as attributes to the span. -Keys and values added to Baggage will appear on all subsequent child spans for a trace within this service *and* will be propagated to external services via propagation headers. +Keys and values added to Baggage will appear on all subsequent child spans, not the current active span, for a trace within this service *and* will be propagated to external services via propagation headers. If the external services also have a Baggage span processor, the keys and values will appear in those child spans as well. ⚠️ Waning ⚠️ @@ -31,7 +31,7 @@ To install the instrumentation, add the gem to your Gemfile: gem 'opentelemetry-processor-baggage' ``` -Then add the processor to an SDK's configuration: +Then configure the span processor to copy all baggage entries: ```ruby require 'rubygems' @@ -40,8 +40,11 @@ require 'bundler/setup' Bundler.require OpenTelemetry::SDK.configure do |c| - # Add the BaggageSpanProcessor to the collection of span processors - c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new) + # Add the BaggageSpanProcessor to the collection of span processors and + # copy all baggage entries + c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + OpenTelemetry::Processor::Baggage::ALLOW_ALL_BAGGAGE_KEYS + )) # Because the span processor list is no longer empty, the SDK will not use the # values in OTEL_TRACES_EXPORTER to instantiate exporters. @@ -57,6 +60,27 @@ OpenTelemetry::SDK.configure do |c| end ``` +Alternatively, you can provide a custom baggage key predicate to select which baggage keys you want to copy. + +For example, to only copy baggage entries that start with `myapp.`: + +```ruby +OUR_BAGGAGE_KEY_PREFIX = 'myapp.'.freeze +OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + # a constant here improves performance + ->(baggage_key) { baggage_key.start_with?(OUR_BAGGAGE_KEY_PREFIX) } +) +``` + +For example, to only copy baggage entries that match `myapp.`, `myapp1.` and `myapp42.`: + +```ruby +OUR_BAGGAGE_KEY_MATCHER = /\Amyapp\d*\./ +OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + ->(baggage_key) { OUR_BAGGAGE_KEY_MATCHER.match?(baggage_key) } +) +``` + ## How can I get involved? The `opentelemetry-processor-baggage` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`. diff --git a/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb b/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb index c5e840cec..9721f8517 100644 --- a/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb +++ b/processor/baggage/lib/opentelemetry/processor/baggage/baggage_span_processor.rb @@ -10,13 +10,19 @@ module OpenTelemetry module Processor module Baggage + # A baggage key predicate that allows all keys to be added to the span as attributes. + ALLOW_ALL_BAGGAGE_KEYS = ->(_) { true } + # The BaggageSpanProcessor reads key/values stored in Baggage in the - # starting span's parent context and adds them as attributes to the span. + # starting span's parent context and adds them as attributes to the span, + # if a key matches a provided predicate lambda. + # + # Keys and values added to Baggage will appear on all subsequent child spans, + # not the current active span, for a trace within this service *and* will be + # propagated to external services via propagation headers. # - # Keys and values added to Baggage will appear on all subsequent child spans - # for a trace within this service *and* will be propagated to external services - # via propagation headers. If the external services also have a Baggage span - # processor, the keys and values will appear in those child spans as well. + # If the external services also have a Baggage span processor, the keys and + # values will appear in those child spans as well. # # ⚠️ # To repeat: a consequence of adding data to Baggage is that the keys and @@ -24,10 +30,16 @@ module Baggage # Do not put sensitive information in Baggage. # ⚠️ # - # @example + # @example Adding the BaggageSpanProcessor to the SDK, only add attributes for keys that start with 'myapp.' + # OUR_BAGGAGE_KEY_PREFIX = 'myapp.'.freeze + # # OpenTelemetry::SDK.configure do |c| # # Add the BaggageSpanProcessor to the collection of span processors - # c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new) + # c.add_span_processor( + # OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + # ->(key) { key.start_with?(OUR_BAGGAGE_KEY_PREFIX) } # a constant here improves performance + # ) + # ) # # # Because the span processor list is no longer empty, the SDK will not use the # # values in OTEL_TRACES_EXPORTER to instantiate exporters. @@ -41,7 +53,31 @@ module Baggage # ) # ) # end + # + # @example Allow all Baggage keys to be added to the span as attributes + # OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + # # This processor provides a convenience predicate that allows all keys to be added as attributes. + # OpenTelemetry::Processor::Baggage::ALLOW_ALL_BAGGAGE_KEYS + # ) class BaggageSpanProcessor < OpenTelemetry::SDK::Trace::SpanProcessor + # Create a new BaggageSpanProcessor that reads Baggage keys and values from the parent context + # and adds them as attributes to the span. + # + # @param [lambda] baggage_key_predicate A lambda that takes a baggage key [String] and returns true if + # the key should be added to the span as an attribute, false otherwise. + # + # @example Only add attributes for keys that start with a specific prefix + # OUR_BAGGAGE_KEY_PREFIX = 'myapp.'.freeze + # OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + # ->(key) { key.start_with?(OUR_BAGGAGE_KEY_PREFIX) } # a constant here improves performance + # ) + def initialize(baggage_key_predicate) + raise ArgumentError, 'baggage_key_predicate must respond to :call (lambda/Proc)' unless baggage_key_predicate.respond_to?(:call) + + @baggage_key_predicate = baggage_key_predicate + super() + end + # Called when a `Span` is started, adds Baggage keys/values to the span as attributes. # # @param [Span] span the `Span` that just started, expected to conform @@ -51,7 +87,11 @@ class BaggageSpanProcessor < OpenTelemetry::SDK::Trace::SpanProcessor def on_start(span, parent_context) return unless span.respond_to?(:add_attributes) && parent_context.is_a?(::OpenTelemetry::Context) - span.add_attributes(::OpenTelemetry::Baggage.values(context: parent_context)) + span.add_attributes( + ::OpenTelemetry::Baggage + .values(context: parent_context) + .select { |k, _v| @baggage_key_predicate.call(k) } + ) end # Called when a Span is ended, does nothing. diff --git a/processor/baggage/lib/opentelemetry/processor/baggage/version.rb b/processor/baggage/lib/opentelemetry/processor/baggage/version.rb index 1544ac3f1..f3711695e 100644 --- a/processor/baggage/lib/opentelemetry/processor/baggage/version.rb +++ b/processor/baggage/lib/opentelemetry/processor/baggage/version.rb @@ -15,7 +15,7 @@ module OpenTelemetry module Processor # Namespace for OpenTelemetry Baggage processor module Baggage - VERSION = '0.1.0' + VERSION = '0.2.0' end end end diff --git a/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb b/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb index 1f7bfc779..73687f0e4 100644 --- a/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb +++ b/processor/baggage/test/opentelemetry/processor/baggage/baggage_span_processor_test.rb @@ -11,8 +11,10 @@ TEST_EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new OpenTelemetry::SDK.configure do |c| - # the baggage processor getting wired in for testing - c.add_span_processor OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new + # the baggage processor getting wired in for integration testing + c.add_span_processor OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + OpenTelemetry::Processor::Baggage::ALLOW_ALL_BAGGAGE_KEYS + ) # use a simple processor and in-memory export for testing sent spans c.add_span_processor( @@ -24,17 +26,68 @@ end describe OpenTelemetry::Processor::Baggage::BaggageSpanProcessor do - let(:processor) { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new } + let(:processor) do + OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + OpenTelemetry::Processor::Baggage::ALLOW_ALL_BAGGAGE_KEYS + ) + end let(:span) { Minitest::Mock.new } - let(:context_with_baggage) { OpenTelemetry::Baggage.set_value('a_key', 'a_value') } + let(:context_with_baggage) do + OpenTelemetry::Baggage.build(context: OpenTelemetry::Context.empty) do |baggage| + baggage.set_value('a_key', 'a_value') + baggage.set_value('b_key', 'b_value') + end + end + + describe '#new' do + it 'requires a callable baggage_key_predicate' do + _(-> { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new }).must_raise(ArgumentError) + err = _(-> { OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(:not_a_callable) }).must_raise(ArgumentError) + _(err.message).must_match(/must respond to :call/) + end + end describe '#on_start' do - it 'adds current baggage keys/values as attributes when a span starts' do - span.expect(:add_attributes, span, [{ 'a_key' => 'a_value' }]) + describe 'with the ALLOW_ALL_BAGGAGE_KEYS predicate' do + it 'adds current baggage keys/values as attributes when a span starts' do + span.expect(:add_attributes, span, [{ 'a_key' => 'a_value', 'b_key' => 'b_value' }]) + + processor.on_start(span, context_with_baggage) + + span.verify + end + end + + describe 'with a start_with? key predicate' do + let(:start_with_processor) do + OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + ->(baggage_key) { baggage_key.start_with?('a') } + ) + end + + it 'only adds attributes that pass the keyfilter' do + span.expect(:add_attributes, span, [{ 'a_key' => 'a_value' }]) + + start_with_processor.on_start(span, context_with_baggage) + + span.verify + end + end + + describe 'with a regex key predicate' do + let(:regex_processor) do + OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new( + ->(baggage_key) { baggage_key.match?(/^b_ke.+/) } + ) + end + + it 'only adds attributes that pass the keyfilter' do + span.expect(:add_attributes, span, [{ 'b_key' => 'b_value' }]) - processor.on_start(span, context_with_baggage) + regex_processor.on_start(span, context_with_baggage) - span.verify + span.verify + end end it 'does not blow up when given nil context' do @@ -89,7 +142,7 @@ _(exporter.finished_spans.size).must_equal(1) _(exporter.finished_spans.first.name).must_equal('integration test span') - _(exporter.finished_spans.first.attributes).must_equal('a_key' => 'a_value') + _(exporter.finished_spans.first.attributes).must_equal('a_key' => 'a_value', 'b_key' => 'b_value') end end end diff --git a/release-please-config.json b/release-please-config.json index 5a871d495..056677671 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,4 +1,5 @@ { + "bootstrap-sha": "c7686e532a7348b504ad43024735b12d795756cd", "bump-minor-pre-major": true, "bump-patch-for-minor-pre-major": true, "draft": true, @@ -7,7 +8,7 @@ "include-v-in-tag": true, "prerelease": true, "release-type": "ruby", - "separate-pull-requests": true, + "separate-pull-requests": false, "sequential-calls": true, "signoff": "OpenTelemetry Bot <107717825+opentelemetrybot@users.noreply.github.com>", "skip-github-release": false,