Skip to content
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

feat: add untraced ctx method #1634

Merged
merged 3 commits into from May 8, 2024
Merged

feat: add untraced ctx method #1634

merged 3 commits into from May 8, 2024

Conversation

robertlaurin
Copy link
Contributor

@robertlaurin robertlaurin commented May 8, 2024

Support untraced usage in a non block structure open-telemetry/opentelemetry-ruby-contrib#965 (comment)

@@ -93,6 +93,10 @@ def untraced
end
end

def untraced_context(parent_context: Context.current)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternate considered is that we can instead amend the existing interface to support block structure or not depending if a block is provided.

      # Disables tracing within the provided block.
      def untraced
        if block_given?
          Context.with_value(UNTRACED_KEY, true) do |ctx, _|
            yield ctx
          end
        else
          Context.set_value(UNTRACED_KEY, true)
        end
      end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we modify untraced to take an optional context arg and optional block? I.e.

def untraced(context = Context.current)
  context = context.set_value(UNTRACED_KEY, true)
  if block_given?
    Context.with_current(context) { |ctx| yield ctx }
  else
    context
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

@fbogsany fbogsany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, once you've appeased the cop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants