Skip to content

Commit

Permalink
feat: add untraced ctx method
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlaurin committed May 8, 2024
1 parent a1f1629 commit 44cd1a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/lib/opentelemetry/common/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def untraced
end
end

def untraced_context(parent_context: Context.current)
parent_context.set_value(UNTRACED_KEY, true)
end

# Detects whether the current context has been set to disable tracing.
def untraced?(context = nil)
context ||= Context.current
Expand Down
7 changes: 7 additions & 0 deletions common/test/opentelemetry/common/utilities_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def shutdown(timeout: nil); end
common_utils.untraced {}
assert_equal(false, common_utils.untraced?)
end

it 'supports non block format' do
token = OpenTelemetry::Context.attach(common_utils.untraced_context)
assert_equal(true, common_utils.untraced?)
OpenTelemetry::Context.detach(token)
assert_equal(false, common_utils.untraced?)
end
end

describe '#utf8_encode' do
Expand Down

0 comments on commit 44cd1a4

Please sign in to comment.