Skip to content

Commit

Permalink
Fix up some of the open telemetry issues (dependabot#8650)
Browse files Browse the repository at this point in the history
* Start work to fix some of the otel issues

* Call shutdown on open telemetry when the run command ends.

* Rename the span for file fetcher and update files

---------
  • Loading branch information
jpinz authored Dec 19, 2023
1 parent 62b63c4 commit b05d6ed
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sorbet/rbi/shims/opentelemetry-sdk.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ module OpenTelemetry
class TracerProvider
sig { params(name: T.nilable(String), version: T.nilable(String)).returns(Tracer) }
def tracer(name = nil, version = nil); end

sig { params(timeout: T.nilable(Numeric)).void }
def shutdown(timeout: nil); end

sig { params(timeout: T.nilable(Numeric)).void }
def force_flush(timeout: nil); end
end

class Link; end
Expand Down
2 changes: 2 additions & 0 deletions updater/lib/dependabot/base_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def run
handle_exception(e)
service.mark_job_as_processed(base_commit_sha)
ensure
# Ensure that we shut down the open telemetry exporter.
::Dependabot::OpenTelemetry.shutdown
Dependabot.logger.formatter = Dependabot::Logger::BasicFormatter.new
Dependabot.logger.info(service.summary) unless service.noop?
raise Dependabot::RunFailure if Dependabot::Environment.github_actions? && service.failure?
Expand Down
5 changes: 3 additions & 2 deletions updater/lib/dependabot/file_fetcher_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class FileFetcherCommand < BaseCommand
# NotImplementedError if it is referenced
attr_reader :base_commit_sha

def perform_job # rubocop:disable Metrics/PerceivedComplexity
def perform_job # rubocop:disable Metrics/PerceivedComplexity,Metrics/AbcSize
@base_commit_sha = nil

span = ::Dependabot::OpenTelemetry.tracer&.start_span("perform_job", kind: :internal)
span = ::Dependabot::OpenTelemetry.tracer&.start_span("file_fetcher", kind: :internal)
span&.set_attribute(::Dependabot::OpenTelemetry::Attributes::JOB_ID, job_id)

begin
connectivity_check if ENV["ENABLE_CONNECTIVITY_CHECK"] == "1"
Expand Down
8 changes: 8 additions & 0 deletions updater/lib/dependabot/opentelemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def self.tracer
::OpenTelemetry.tracer_provider.tracer("dependabot", Dependabot::VERSION)
end

sig { void }
def self.shutdown
return unless should_configure?

::OpenTelemetry.tracer_provider.force_flush
::OpenTelemetry.tracer_provider.shutdown
end

sig do
params(
job_id: T.any(String, Integer),
Expand Down
4 changes: 3 additions & 1 deletion updater/lib/dependabot/update_files_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def perform_job
# encoded files and commit information in the environment, so let's retrieve
# them, decode and parse them into an object that knows the current state
# of the project's dependencies.
span = ::Dependabot::OpenTelemetry.tracer&.start_span("perform_job", kind: :internal)
span = ::Dependabot::OpenTelemetry.tracer&.start_span("update_files", kind: :internal)
span&.set_attribute(::Dependabot::OpenTelemetry::Attributes::JOB_ID, job_id)

begin
dependency_snapshot = Dependabot::DependencySnapshot.create_from_job_definition(
job: job,
Expand Down

0 comments on commit b05d6ed

Please sign in to comment.