From f29c5ef91d2abe80acfd2da38feb76e6f8fd86bc Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 3 Jan 2025 12:58:13 +0100 Subject: [PATCH 1/2] add telemetry logs --- lib/datadog/ci/configuration/components.rb | 3 +++ lib/datadog/ci/ext/environment.rb | 4 ++++ .../ext/environment/providers/github_actions.rb | 3 +++ lib/datadog/ci/test_optimisation/component.rb | 2 ++ lib/datadog/ci/test_visibility/transport.rb | 15 ++++++++++++++- sig/datadog/ci/test_visibility/transport.rbs | 3 +++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/datadog/ci/configuration/components.rb b/lib/datadog/ci/configuration/components.rb index 4f62b51d..042308f5 100644 --- a/lib/datadog/ci/configuration/components.rb +++ b/lib/datadog/ci/configuration/components.rb @@ -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" @@ -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 @@ -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 diff --git a/lib/datadog/ci/ext/environment.rb b/lib/datadog/ci/ext/environment.rb index e2d3f8cb..ad18bd91 100644 --- a/lib/datadog/ci/ext/environment.rb +++ b/lib/datadog/ci/ext/environment.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "datadog/core/telemetry/logging" + require_relative "git" require_relative "environment/extractor" @@ -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) @@ -89,6 +92,7 @@ def validate_git_sha(git_sha) end Datadog.logger.error(message) + Core::Telemetry::Logger.error(message) end end end diff --git a/lib/datadog/ci/ext/environment/providers/github_actions.rb b/lib/datadog/ci/ext/environment/providers/github_actions.rb index 4e040d37..6ad7bea6 100644 --- a/lib/datadog/ci/ext/environment/providers/github_actions.rb +++ b/lib/datadog/ci/ext/environment/providers/github_actions.rb @@ -2,6 +2,7 @@ require "json" +require "datadog/core/telemetry/logging" require "datadog/core/utils/url" require_relative "base" @@ -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 diff --git a/lib/datadog/ci/test_optimisation/component.rb b/lib/datadog/ci/test_optimisation/component.rb index e13add52..a0e3dfba 100644 --- a/lib/datadog/ci/test_optimisation/component.rb +++ b/lib/datadog/ci/test_optimisation/component.rb @@ -2,6 +2,7 @@ require "pp" +require "datadog/core/telemetry/logging" require "datadog/core/utils/forking" require_relative "../ext/test" @@ -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 diff --git a/lib/datadog/ci/test_visibility/transport.rb b/lib/datadog/ci/test_visibility/transport.rb index b9bab02c..a6b45717 100644 --- a/lib/datadog/ci/test_visibility/transport.rb +++ b/lib/datadog/ci/test_visibility/transport.rb @@ -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" @@ -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:, @@ -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 diff --git a/sig/datadog/ci/test_visibility/transport.rbs b/sig/datadog/ci/test_visibility/transport.rbs index 7d0169c6..e6b585cc 100644 --- a/sig/datadog/ci/test_visibility/transport.rbs +++ b/sig/datadog/ci/test_visibility/transport.rbs @@ -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) From e990396cbec34e01a7ae198003e70111d793325c Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 3 Jan 2025 13:07:56 +0100 Subject: [PATCH 2/2] remove telemetry logger from component initialization lifecycle --- lib/datadog/ci/configuration/components.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/datadog/ci/configuration/components.rb b/lib/datadog/ci/configuration/components.rb index 042308f5..4f62b51d 100644 --- a/lib/datadog/ci/configuration/components.rb +++ b/lib/datadog/ci/configuration/components.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "datadog/core/telemetry/ext" -require "datadog/core/telemetry/logging" require_relative "../ext/settings" require_relative "../git/tree_uploader" @@ -63,7 +62,6 @@ 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 @@ -172,7 +170,6 @@ 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