Skip to content

Commit

Permalink
add telemetry logs
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 3, 2025
1 parent 153414f commit f29c5ef
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/datadog/ci/configuration/components.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "datadog/core/telemetry/ext"
require "datadog/core/telemetry/logging"

require_relative "../ext/settings"
require_relative "../git/tree_uploader"
Expand Down Expand Up @@ -62,6 +63,7 @@ def activate_ci!(settings)
"NOTE: if you didn't disable tracing intentionally, add `c.tracing.enabled = true` to " \
"your Datadog.configure block."
)
Core::Telemetry::Logger.error("Tracing is disabled => test optimization is disabled")
settings.ci.enabled = false
return
end
Expand Down Expand Up @@ -170,6 +172,7 @@ def build_test_visibility_api(settings)
"Agentless mode was enabled but DD_API_KEY is not set: CI visibility is disabled. " \
"Please make sure to set valid api key in DD_API_KEY environment variable"
end
Core::Telemetry::Logger.error("DD_API_KEY not set => test optimization is disabled")

# Tests are running without CI visibility enabled
settings.ci.enabled = false
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/ci/ext/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "datadog/core/telemetry/logging"

require_relative "git"
require_relative "environment/extractor"

Expand Down Expand Up @@ -73,6 +75,7 @@ def validate_repository_url(repo_url)
return if !repo_url.nil? && !repo_url.empty?

Datadog.logger.error("DD_GIT_REPOSITORY_URL is not set or empty; no repo URL was automatically extracted")
Core::Telemetry::Logger.error("DD_GIT_REPOSITORY_URL is not set or empty; no repo URL was automatically extracted")
end

def validate_git_sha(git_sha)
Expand All @@ -89,6 +92,7 @@ def validate_git_sha(git_sha)
end

Datadog.logger.error(message)
Core::Telemetry::Logger.error(message)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/ci/ext/environment/providers/github_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "json"

require "datadog/core/telemetry/logging"
require "datadog/core/utils/url"

require_relative "base"
Expand Down Expand Up @@ -96,6 +97,8 @@ def additional_tags
result
rescue => e
Datadog.logger.error("Failed to extract additional tags from GitHub Actions: #{e}")
Core::Telemetry::Logger.report(e, description: "Failed to extract additional tags from GitHub Actions")

{}
end

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/test_optimisation/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "pp"

require "datadog/core/telemetry/logging"
require "datadog/core/utils/forking"

require_relative "../ext/test"
Expand Down Expand Up @@ -224,6 +225,7 @@ def load_datadog_cov!
Datadog.logger.debug("Loaded Datadog code coverage collector, using coverage mode: #{code_coverage_mode}")
rescue LoadError => e
Datadog.logger.error("Failed to load coverage collector: #{e}. Code coverage will not be collected.")
Core::Telemetry::Logger.report(e, description: "Failed to load coverage collector")

@code_coverage_enabled = false
end
Expand Down
15 changes: 14 additions & 1 deletion lib/datadog/ci/test_visibility/transport.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "datadog/core/environment/identity"
require "datadog/core/telemetry/logging"
require "datadog/core/utils/only_once"

require_relative "serializers/factories/test_level"
require_relative "../ext/app_types"
Expand All @@ -15,6 +17,10 @@ module TestVisibility
class Transport < Datadog::CI::Transport::EventPlatformTransport
attr_reader :serializers_factory, :dd_env

def self.log_once
@log_once ||= Datadog::Core::Utils::OnlyOnce.new
end

def initialize(
api:,
dd_env:,
Expand Down Expand Up @@ -64,8 +70,15 @@ def encode_span(trace, span)

encoded
else
Datadog.logger.warn("Invalid event skipped: #{serializer} Errors: #{serializer.validation_errors}")
message = "Invalid event skipped: #{serializer} Errors: #{serializer.validation_errors}"
Datadog.logger.warn(message)
CI::Transport::Telemetry.endpoint_payload_dropped(1, endpoint: telemetry_endpoint_tag)

# log invalid message once as error to internal telemetry
self.class.log_once.run do
Core::Telemetry::Logger.error(message)
end

nil
end
end
Expand Down
3 changes: 3 additions & 0 deletions sig/datadog/ci/test_visibility/transport.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Datadog
attr_reader serializers_factory: singleton(Datadog::CI::TestVisibility::Serializers::Factories::TestLevel) | singleton(Datadog::CI::TestVisibility::Serializers::Factories::TestSuiteLevel)
attr_reader dd_env: String?

self.@log_once: Datadog::Core::Utils::OnlyOnce
def self.log_once: () -> Datadog::Core::Utils::OnlyOnce

@dd_env: String?
@serializers_factory: singleton(Datadog::CI::TestVisibility::Serializers::Factories::TestLevel) | singleton(Datadog::CI::TestVisibility::Serializers::Factories::TestSuiteLevel)

Expand Down

0 comments on commit f29c5ef

Please sign in to comment.