-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Proof of Concept instrumentation for Solid Process
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module OpenTelemetryTracer | ||
SolidResultTracer = ::OpenTelemetry.tracer_provider.tracer("solid-result") | ||
|
||
module ProcessListener | ||
def self.start(name, _id, payload) | ||
scope = payload[:scope] | ||
|
||
span = SolidResultTracer.start_span("#{scope[:name]}#call", attributes: { | ||
"desc" => scope[:desc].inspect | ||
}) | ||
|
||
token = OpenTelemetry::Context.attach(::OpenTelemetry::Trace.context_with_span(span)) | ||
payload.merge!(__otel: {span:, token:}) | ||
end | ||
|
||
def self.finish(_name, _id, payload) | ||
otel = payload.delete(:__otel) | ||
|
||
otel => { span:, token: } | ||
|
||
span.finish | ||
OpenTelemetry::Context.detach(token) | ||
end | ||
end | ||
|
||
module AndThenListener | ||
def self.start(name, _id, payload) | ||
payload => { scope:, and_then: } | ||
|
||
span = SolidResultTracer.start_span("#{scope[:name]}##{and_then[:method_name] || "block"}", attributes: { | ||
"type" => and_then[:type].to_s, | ||
"arg" => and_then[:arg].inspect | ||
}) | ||
|
||
token = OpenTelemetry::Context.attach(::OpenTelemetry::Trace.context_with_span(span)) | ||
payload.merge!(__otel: {span:, token:}) | ||
end | ||
|
||
def self.finish(_name, _id, payload) | ||
otel = payload.delete(:__otel) | ||
|
||
otel => { span:, token: } | ||
|
||
span.finish | ||
OpenTelemetry::Context.detach(token) | ||
end | ||
end | ||
|
||
def self.subscribe | ||
ActiveSupport::Notifications.monotonic_subscribe("start_process.solid_process", ProcessListener) | ||
ActiveSupport::Notifications.monotonic_subscribe("and_then.solid_process", AndThenListener) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Solid::Process::ActiveSupportPublisher | ||
include Solid::Result::EventLogs::Listener | ||
|
||
def self.around_event_logs? | ||
true | ||
end | ||
|
||
def self.around_and_then? | ||
true | ||
end | ||
|
||
def around_event_logs(scope:, &) | ||
ActiveSupport::Notifications.instrument("start_process.solid_process", scope:, &) | ||
end | ||
|
||
def around_and_then(scope:, and_then:, **, &) | ||
ActiveSupport::Notifications.instrument("and_then.solid_process", scope:, and_then:, &) | ||
end | ||
end |