-
Notifications
You must be signed in to change notification settings - Fork 9
Propagate OpenTelemetry context to async thread pool workers #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d8d927
propagate OpenTelemetry context to async thread pool workers
KirIgor a3d6168
fix rubocop offenses
KirIgor c6a34ac
use real opentelemetry-api gem in tests instead of stubs
KirIgor 7a8005a
drop Ruby < 3.3 support, add 3.4 to CI matrix
KirIgor 8e8b2f7
bump TargetRubyVersion to 3.3, apply new style cops
KirIgor a81812e
Refactor OpenTelemetry context propagation and cleanup specs (#47)
avoleba db1fac9
add release workflow
KirIgor b55d1ee
fix release workflow
KirIgor 8f2cb87
style fix
KirIgor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Extract version | ||
| id: version | ||
| run: | | ||
| version=$(grep -oP '(?<=version = ")[^"]+' umbrellio-sequel-plugins.gemspec) | ||
| echo "tag=v$version" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Check if release already exists | ||
| id: check | ||
| run: | | ||
| if gh release view "${{ steps.version.outputs.tag }}" &>/dev/null; then | ||
| echo "exists=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "exists=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - uses: ruby/setup-ruby@v1 | ||
| if: steps.check.outputs.exists == 'false' | ||
| with: | ||
| ruby-version: "3.4" | ||
| bundler-cache: true | ||
|
|
||
| - name: Build gem | ||
| if: steps.check.outputs.exists == 'false' | ||
| run: gem build umbrellio-sequel-plugins.gemspec | ||
|
|
||
| - name: Push gem to RubyGems | ||
| if: steps.check.outputs.exists == 'false' | ||
| run: gem push *.gem | ||
| env: | ||
| GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }} | ||
|
|
||
| - uses: softprops/action-gh-release@v3 | ||
| if: steps.check.outputs.exists == 'false' | ||
| with: | ||
| tag_name: ${{ steps.version.outputs.tag }} | ||
| files: "*.gem" | ||
| generate_release_notes: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ gemspec | |
|
|
||
| gem "async" | ||
| gem "money" | ||
| gem "opentelemetry-api" | ||
| gem "pg" | ||
| gem "pry" | ||
| gem "rake" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "concurrent" | ||
|
|
||
| ASYNC_DB_URL = ENV.fetch("DB_URL", "postgres:///sequel_plugins") | ||
|
|
||
| def make_concurrent_db(**opts) | ||
| Sequel.connect(ASYNC_DB_URL, **opts).tap { |d| d.extension(:concurrent_thread_pool) } | ||
| end |
68 changes: 68 additions & 0 deletions
68
spec/extensions/concurrent_thread_pool_opentelemetry_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "opentelemetry-api" | ||
| require_relative "concurrent_thread_pool_helpers" | ||
|
|
||
| RSpec.describe "concurrent_thread_pool extension OpenTelemetry context propagation" do | ||
| let(:db) { make_concurrent_db } | ||
| let(:otel_key) { OpenTelemetry::Context.create_key("sequel-test") } | ||
|
|
||
| after { db.disconnect rescue nil } | ||
|
|
||
| it "does not propagate context when calling thread context is ROOT" do | ||
| captured = :not_set | ||
|
|
||
| db.send(:async_run) { captured = OpenTelemetry::Context.current.value(otel_key) }.__value | ||
|
|
||
| expect(captured).to be_nil | ||
| end | ||
|
|
||
| it "does not error when OpenTelemetry is defined without Context" do | ||
| db = make_concurrent_db | ||
| stub_const("OpenTelemetry", Object.new) | ||
|
|
||
| expect { db.send(:async_run) { :ok }.__value }.not_to raise_error | ||
| ensure | ||
| db.disconnect rescue nil | ||
| end | ||
|
|
||
| it "propagates calling-thread context to worker thread" do | ||
| captured = nil | ||
|
|
||
| OpenTelemetry::Context.with_value(otel_key, "sentinel") do | ||
| db.send(:async_run) { captured = OpenTelemetry::Context.current.value(otel_key) }.__value | ||
| end | ||
|
|
||
| expect(captured).to eq("sentinel") | ||
| end | ||
|
|
||
| context "with single-thread executor" do | ||
| let(:db) { make_concurrent_db(num_async_threads: 1) } | ||
|
|
||
| it "restores context in worker thread after block completes" do | ||
| OpenTelemetry::Context.with_value(otel_key, "sentinel") do | ||
| db.send(:async_run) { :done }.__value | ||
|
|
||
| value_after = Concurrent::Promises.future_on(db.async_thread_executor) do | ||
| OpenTelemetry::Context.current.value(otel_key) | ||
| end.value! | ||
|
|
||
| expect(value_after).to be_nil | ||
| end | ||
| end | ||
| end | ||
|
|
||
| it "propagates context even when block raises" do | ||
| captured = nil | ||
|
|
||
| OpenTelemetry::Context.with_value(otel_key, "sentinel") do | ||
| result = db.send(:async_run) do | ||
| captured = OpenTelemetry::Context.current.value(otel_key) | ||
| raise "boom" | ||
| end | ||
|
|
||
| expect { result.__value }.to raise_error(RuntimeError, "boom") | ||
| expect(captured).to eq("sentinel") | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.