mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-28 20:55:37 +01:00
Add instrumentation to the search services (#30350)
This commit is contained in:
parent
8394a150d7
commit
acc77c3836
6 changed files with 55 additions and 20 deletions
2
Gemfile
2
Gemfile
|
@ -103,6 +103,8 @@ gem 'rdf-normalize', '~> 0.5'
|
||||||
|
|
||||||
gem 'private_address_check', '~> 0.5'
|
gem 'private_address_check', '~> 0.5'
|
||||||
|
|
||||||
|
gem 'opentelemetry-api', '~> 1.2.5'
|
||||||
|
|
||||||
group :opentelemetry do
|
group :opentelemetry do
|
||||||
gem 'opentelemetry-exporter-otlp', '~> 0.26.3', require: false
|
gem 'opentelemetry-exporter-otlp', '~> 0.26.3', require: false
|
||||||
gem 'opentelemetry-instrumentation-active_job', '~> 0.7.1', require: false
|
gem 'opentelemetry-instrumentation-active_job', '~> 0.7.1', require: false
|
||||||
|
|
|
@ -975,6 +975,7 @@ DEPENDENCIES
|
||||||
omniauth-rails_csrf_protection (~> 1.0)
|
omniauth-rails_csrf_protection (~> 1.0)
|
||||||
omniauth-saml (~> 2.0)
|
omniauth-saml (~> 2.0)
|
||||||
omniauth_openid_connect (~> 0.6.1)
|
omniauth_openid_connect (~> 0.6.1)
|
||||||
|
opentelemetry-api (~> 1.2.5)
|
||||||
opentelemetry-exporter-otlp (~> 0.26.3)
|
opentelemetry-exporter-otlp (~> 0.26.3)
|
||||||
opentelemetry-instrumentation-active_job (~> 0.7.1)
|
opentelemetry-instrumentation-active_job (~> 0.7.1)
|
||||||
opentelemetry-instrumentation-active_model_serializers (~> 0.20.1)
|
opentelemetry-instrumentation-active_model_serializers (~> 0.20.1)
|
||||||
|
|
|
@ -151,13 +151,23 @@ class AccountSearchService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(query, account = nil, options = {})
|
def call(query, account = nil, options = {})
|
||||||
@query = query&.strip&.gsub(/\A@/, '')
|
MastodonOTELTracer.in_span('AccountSearchService#call') do |span|
|
||||||
@limit = options[:limit].to_i
|
@query = query&.strip&.gsub(/\A@/, '')
|
||||||
@offset = options[:offset].to_i
|
@limit = options[:limit].to_i
|
||||||
@options = options
|
@offset = options[:offset].to_i
|
||||||
@account = account
|
@options = options
|
||||||
|
@account = account
|
||||||
|
|
||||||
search_service_results.compact.uniq
|
span.add_attributes(
|
||||||
|
'search.offset' => @offset,
|
||||||
|
'search.limit' => @limit,
|
||||||
|
'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database'
|
||||||
|
)
|
||||||
|
|
||||||
|
search_service_results.compact.uniq.tap do |results|
|
||||||
|
span.set_attribute('search.results.count', results.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -2,14 +2,24 @@
|
||||||
|
|
||||||
class StatusesSearchService < BaseService
|
class StatusesSearchService < BaseService
|
||||||
def call(query, account = nil, options = {})
|
def call(query, account = nil, options = {})
|
||||||
@query = query&.strip
|
MastodonOTELTracer.in_span('StatusesSearchService#call') do |span|
|
||||||
@account = account
|
@query = query&.strip
|
||||||
@options = options
|
@account = account
|
||||||
@limit = options[:limit].to_i
|
@options = options
|
||||||
@offset = options[:offset].to_i
|
@limit = options[:limit].to_i
|
||||||
|
@offset = options[:offset].to_i
|
||||||
|
convert_deprecated_options!
|
||||||
|
|
||||||
convert_deprecated_options!
|
span.add_attributes(
|
||||||
status_search_results
|
'search.offset' => @offset,
|
||||||
|
'search.limit' => @limit,
|
||||||
|
'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database'
|
||||||
|
)
|
||||||
|
|
||||||
|
status_search_results.tap do |results|
|
||||||
|
span.set_attribute('search.results.count', results.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -2,15 +2,25 @@
|
||||||
|
|
||||||
class TagSearchService < BaseService
|
class TagSearchService < BaseService
|
||||||
def call(query, options = {})
|
def call(query, options = {})
|
||||||
@query = query.strip.delete_prefix('#')
|
MastodonOTELTracer.in_span('TagSearchService#call') do |span|
|
||||||
@offset = options.delete(:offset).to_i
|
@query = query.strip.delete_prefix('#')
|
||||||
@limit = options.delete(:limit).to_i
|
@offset = options.delete(:offset).to_i
|
||||||
@options = options
|
@limit = options.delete(:limit).to_i
|
||||||
|
@options = options
|
||||||
|
|
||||||
results = from_elasticsearch if Chewy.enabled?
|
span.add_attributes(
|
||||||
results ||= from_database
|
'search.offset' => @offset,
|
||||||
|
'search.limit' => @limit,
|
||||||
|
'search.backend' => Chewy.enabled? ? 'elasticsearch' : 'database'
|
||||||
|
)
|
||||||
|
|
||||||
results
|
results = from_elasticsearch if Chewy.enabled?
|
||||||
|
results ||= from_database
|
||||||
|
|
||||||
|
span.set_attribute('search.results.count', results.size)
|
||||||
|
|
||||||
|
results
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -66,3 +66,5 @@ if ENV.keys.any? { |name| name.match?(/OTEL_.*_ENDPOINT/) }
|
||||||
c.service_version = Mastodon::Version.to_s
|
c.service_version = Mastodon::Version.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
MastodonOTELTracer = OpenTelemetry.tracer_provider.tracer('mastodon')
|
||||||
|
|
Loading…
Reference in a new issue