mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-08 16:54:31 +00:00
Add telemetry for status / bio formatting (#32677)
This commit is contained in:
parent
244aaf9a38
commit
9de3fd60a0
|
@ -27,8 +27,15 @@ module FormattingHelper
|
|||
module_function :extract_status_plain_text
|
||||
|
||||
def status_content_format(status)
|
||||
MastodonOTELTracer.in_span('HtmlAwareFormatter rendering') do |span|
|
||||
span.add_attributes(
|
||||
'app.formatter.content.type' => 'status',
|
||||
'app.formatter.content.origin' => status.local? ? 'local' : 'remote'
|
||||
)
|
||||
|
||||
html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
|
||||
end
|
||||
end
|
||||
|
||||
def rss_status_content_format(status)
|
||||
prerender_custom_emojis(
|
||||
|
@ -39,8 +46,15 @@ module FormattingHelper
|
|||
end
|
||||
|
||||
def account_bio_format(account)
|
||||
MastodonOTELTracer.in_span('HtmlAwareFormatter rendering') do |span|
|
||||
span.add_attributes(
|
||||
'app.formatter.content.type' => 'account_bio',
|
||||
'app.formatter.content.origin' => account.local? ? 'local' : 'remote'
|
||||
)
|
||||
|
||||
html_aware_format(account.note, account.local?)
|
||||
end
|
||||
end
|
||||
|
||||
def account_field_value_format(field, with_rel_me: true)
|
||||
if field.verified? && !field.account.local?
|
||||
|
|
|
@ -33,6 +33,8 @@ class TextFormatter
|
|||
def to_s
|
||||
return ''.html_safe if text.blank?
|
||||
|
||||
html = nil
|
||||
MastodonOTELTracer.in_span('TextFormatter#to_s extract_and_rewrite') do
|
||||
html = rewrite do |entity|
|
||||
if entity[:url]
|
||||
link_to_url(entity)
|
||||
|
@ -42,8 +44,13 @@ class TextFormatter
|
|||
link_to_mention(entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
html = simple_format(html, {}, sanitize: false).delete("\n") if multiline?
|
||||
if multiline?
|
||||
MastodonOTELTracer.in_span('TextFormatter#to_s simple_format') do
|
||||
html = simple_format(html, {}, sanitize: false).delete("\n")
|
||||
end
|
||||
end
|
||||
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
@ -93,10 +100,13 @@ class TextFormatter
|
|||
end
|
||||
|
||||
def link_to_url(entity)
|
||||
MastodonOTELTracer.in_span('TextFormatter#link_to_url') do
|
||||
TextFormatter.shortened_link(entity[:url], rel_me: with_rel_me?)
|
||||
end
|
||||
end
|
||||
|
||||
def link_to_hashtag(entity)
|
||||
MastodonOTELTracer.in_span('TextFormatter#link_to_hashtag') do
|
||||
hashtag = entity[:hashtag]
|
||||
url = tag_url(hashtag)
|
||||
|
||||
|
@ -104,8 +114,10 @@ class TextFormatter
|
|||
<a href="#{h(url)}" class="mention hashtag" rel="tag">#<span>#{h(hashtag)}</span></a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
def link_to_mention(entity)
|
||||
MastodonOTELTracer.in_span('TextFormatter#link_to_mention') do
|
||||
username, domain = entity[:screen_name].split('@')
|
||||
domain = nil if local_domain?(domain)
|
||||
account = nil
|
||||
|
@ -136,6 +148,7 @@ class TextFormatter
|
|||
<span class="h-card" translate="no"><a href="#{h(url)}" class="u-url mention">@<span>#{h(display_username)}</span></a></span>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
def entity_cache
|
||||
@entity_cache ||= EntityCache.instance
|
||||
|
|
Loading…
Reference in a new issue