instance method
tagged
Ruby on Rails 8.1.2
Since v8.1.2Signature
tagged(*args, **kwargs, &block)
Add tags to events to supply additional context. Tags operate in a stack-oriented manner, so all events emitted within the block inherit the same set of tags. For example:
Rails.event.tagged("graphql") do
Rails.event.notify("user.created", { id: 123 })
end
# Emits event:
# {
# name: "user.created",
# payload: { id: 123 },
# tags: { graphql: true },
# context: {},
# timestamp: 1738964843208679035,
# source_location: { filepath: "path/to/file.rb", lineno: 123, label: "UserService#create" }
# }
Tags can be provided as arguments or as keyword arguments, and can be nested:
Rails.event.tagged("graphql") do
# Other code here...
Rails.event.tagged(section: "admin") do
Rails.event.notify("user.created", { id: 123 })
end
end
# Emits event:
# {
# name: "user.created",
# payload: { id: 123 },
# tags: { section: "admin", graphql: true },
# context: {},
# timestamp: 1738964843208679035,
# source_location: { filepath: "path/to/file.rb", lineno: 123, label: "UserService#create" }
# }
The tagged API can also receive a tag object:
graphql_tag = GraphqlTag.new(operation_name: "user_created", operation_type: "mutation")
Rails.event.tagged(graphql_tag) do
Rails.event.notify("user.created", { id: 123 })
end
# Emits event:
# {
# name: "user.created",
# payload: { id: 123 },
# tags: { "GraphqlTag": #<GraphqlTag:0x111> },
# context: {},
# timestamp: 1738964843208679035,
# source_location: { filepath: "path/to/file.rb", lineno: 123, label: "UserService#create" }
# }
Parameters
-
argsrest -
kwargskeyrest -
blockblock
Source
# File activesupport/lib/active_support/event_reporter.rb, line 497
def tagged(*args, **kwargs, &block)
TagStack.with_tags(*args, **kwargs, &block)
end
Defined in activesupport/lib/active_support/event_reporter.rb line 497
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::EventReporter