Merge remote-tracking branch 'parent/main' into upstream-20241231

This commit is contained in:
KMY 2024-12-31 11:56:36 +09:00
commit 3c77d4e8e4
268 changed files with 4213 additions and 3029 deletions

View file

@ -76,6 +76,31 @@ if ENV.keys.any? { |name| name.match?(/OTEL_.*_ENDPOINT/) }
)
end
end
# This middleware adds the trace_id and span_id to the Rails logging tags for every requests
class TelemetryLoggingMiddleware
def initialize(app)
@app = app
end
def call(env)
span = OpenTelemetry::Trace.current_span
return @app.call(env) unless span.recording?
span_id = span.context.hex_span_id
trace_id = span.context.hex_trace_id
Rails.logger.tagged("trace_id=#{trace_id}", "span_id=#{span_id}") do
@app.call(env)
end
end
end
Rails.application.configure do
config.middleware.insert_before Rails::Rack::Logger, TelemetryLoggingMiddleware
end
end
MastodonOTELTracer = OpenTelemetry.tracer_provider.tracer('mastodon')