cw-datadog 2.23.0.5 → 2.23.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datadog/core/cloudwise/client.rb +47 -37
  3. data/lib/datadog/core/cloudwise/component.rb +40 -39
  4. data/lib/datadog/core/cloudwise/docc_heartbeat_worker.rb +0 -1
  5. data/lib/datadog/core/cloudwise/docc_operation_worker.rb +5 -10
  6. data/lib/datadog/core/cloudwise/docc_registration_worker.rb +0 -1
  7. data/lib/datadog/core/cloudwise/probe_state.rb +9 -11
  8. data/lib/datadog/core/cloudwise/time_sync_worker.rb +2 -6
  9. data/lib/datadog/core/configuration/components.rb +1 -3
  10. data/lib/datadog/core/configuration/settings.rb +25 -31
  11. data/lib/datadog/core/environment/agent_info.rb +18 -0
  12. data/lib/datadog/core/remote/negotiation.rb +14 -0
  13. data/lib/datadog/core/transport/http/adapters/net.rb +8 -6
  14. data/lib/datadog/tracing/contrib/cloudwise/propagation.rb +80 -162
  15. data/lib/datadog/tracing/contrib/grape/endpoint.rb +2 -6
  16. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +0 -26
  17. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +0 -26
  18. data/lib/datadog/tracing/contrib/kafka/instrumentation/consumer.rb +26 -114
  19. data/lib/datadog/tracing/contrib/kafka/instrumentation/producer.rb +21 -50
  20. data/lib/datadog/tracing/contrib/rack/middlewares.rb +82 -83
  21. data/lib/datadog/tracing/tracer.rb +10 -33
  22. data/lib/datadog/tracing/transport/http/api.rb +2 -4
  23. data/lib/datadog/tracing/transport/http/traces.rb +2 -2
  24. data/lib/datadog/tracing/transport/trace_formatter.rb +25 -22
  25. data/lib/datadog/tracing.rb +3 -3
  26. data/lib/datadog/version.rb +2 -2
  27. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c828f3cd16def8be8aaf2a7ad6ca5c7d895652ba61a8ab3f2e37e86a3d15c34
4
- data.tar.gz: a9a30fab81f579a6f68908e141a4ec2a3a7537bd691d0d99bc96769da2901254
3
+ metadata.gz: 357524fd08da065c567250e3808034acf9f913a3646454e08e57ba862b86630e
4
+ data.tar.gz: 1f2e9dd6587bcf9e85dd392292ae7d3383aa0049e6c47564068e3fc2be47ec98
5
5
  SHA512:
6
- metadata.gz: 8fc7e482cd0bef1fa1ccaf46a9847bca74b4a027f55b2ccf0ed61e9d8978510d36a0cd0e651336cb799834e7c3568f83fd8e8a16884f26d6fc041fda6f4f7ac2
7
- data.tar.gz: b1c9a0aba8aabac6543c2721068dc9726fa7851d4b8f8c25588657b3ba1d0b06feda729f89b2eadd3c3a29b51be0aa1c1375722eb802b3bbba0471bb4e2e8c0a
6
+ metadata.gz: e5d5e968b104db74f788b813ca07ea400169235353094b1d6376ff9b0d1d54eb45f6fe66cedca3d8e80e7edea1e51626e2e17ddd6ff173756781a7e601f74f2a
7
+ data.tar.gz: 7446cff8ed80819860f272d20a28bc5629e656ddc029951b177f391b833d1c0b717f64b8ac01baf38da84eed9ad1a9f24736f80fc914c0e1db96186f657c122b
@@ -9,10 +9,11 @@ module Datadog
9
9
  module Core
10
10
  module Cloudwise
11
11
  # HTTP client for Cloudwise API calls
12
+ # rubocop:disable CustomCops/EnvUsageCop
12
13
  class Client
13
14
  attr_reader :base_url, :server_name, :license_key, :logger, :account_id,
14
- :integrated_mode, :token, :token_account_id, :token_user_id,
15
- :agent_instance_id
15
+ :integrated_mode, :token, :token_account_id, :token_user_id,
16
+ :agent_instance_id
16
17
 
17
18
  # Response codes
18
19
  CODE_SUCCESS = 1000
@@ -99,20 +100,20 @@ module Datadog
99
100
  @account_id = register_response[:data]['account_id'].to_i
100
101
 
101
102
  # 设置到环境变量 (转为字符串存储)
103
+ # NOTE: 设置环境变量必须使用 ENV,DATADOG_ENV 只支持读取
102
104
  ENV['CLOUDWISE_ACCOUNT_ID'] = @account_id.to_s
103
105
  ENV['CLOUDWISE_HOST_ID'] = @host_id.to_s
104
106
  ENV['CLOUDWISE_AGENT_ID'] = generate_agent_id(host_ip).to_s
105
- ENV['CLOUDWISE_HOST_NAME'] = Socket.gethostname rescue 'unknown'
107
+ ENV['CLOUDWISE_HOST_NAME'] = safe_gethostname
106
108
  ENV['CLOUDWISE_INSTANCE_ID'] = generate_service_instance_id(host_ip).to_s
107
109
 
108
110
  Cloudwise.log_debug { "Cloudwise: Registered Host, account_id: #{@account_id}, host_id: #{@host_id}" }
109
- # 返回 register_host 的响应(包含 account_id)
110
- return register_response
111
111
  else
112
112
  error_msg = register_response[:error] || "code=#{register_response[:code]}"
113
113
  Cloudwise.log_error { "Cloudwise: Failed to register host: #{error_msg}" }
114
- return register_response
115
114
  end
115
+ # 返回 register_host 的响应(包含 account_id 或错误信息)
116
+ return register_response
116
117
  else
117
118
  error_msg = response[:error] || "No hostId in response"
118
119
  Cloudwise.log_error { "Cloudwise: Failed to generate host ID: #{error_msg}" }
@@ -125,11 +126,11 @@ module Datadog
125
126
  def register_host(host_ip)
126
127
  unless @host_id
127
128
  Cloudwise.log_error { 'Cloudwise: Cannot register host without host_id' }
128
- return { success: false, error: 'host_id not generated', code: nil }
129
+ return {success: false, error: 'host_id not generated', code: nil}
129
130
  end
130
131
 
131
132
  # 获取系统信息
132
- host_name = Socket.gethostname rescue 'default'
133
+ host_name = safe_gethostname
133
134
  sys_version = RUBY_VERSION
134
135
 
135
136
  post('/v2/app/registerHost', {
@@ -146,7 +147,7 @@ module Datadog
146
147
  # 心跳接口
147
148
  def heartbeat
148
149
  host_ip = get_local_ip
149
- host_name = Socket.gethostname rescue 'unknown'
150
+ host_name = safe_gethostname
150
151
 
151
152
  post('/api/v1/agent/heartbeat', {
152
153
  version: Datadog::VERSION::STRING,
@@ -191,7 +192,7 @@ module Datadog
191
192
  host_ip = get_local_ip
192
193
 
193
194
  post('/v2/licence/verification', {
194
- account_id: (@account_id).to_s,
195
+ account_id: @account_id.to_s,
195
196
  agent_id: generate_agent_id(host_ip),
196
197
  service_type: 'RUBY',
197
198
  version: Datadog::VERSION::STRING,
@@ -232,10 +233,10 @@ module Datadog
232
233
  codeType: 1012,
233
234
  app_type: 1,
234
235
  vpc: '',
235
- env_tag: 'default',
236
- service_tag: 'default',
237
- version_tag:'default',
238
- business_tag: '' ,
236
+ env_tag: 'default',
237
+ service_tag: 'default',
238
+ version_tag: 'default',
239
+ business_tag: '',
239
240
  sys: '',
240
241
  host_tag: '{}',
241
242
  tags: {},
@@ -372,14 +373,15 @@ module Datadog
372
373
  }
373
374
  else
374
375
  Cloudwise.log_warn { "Cloudwise: path: #{path} Failed to fetch server timestamp: #{response.code}" }
375
- { success: false, error: "HTTP #{response.code}" }
376
+ {success: false, error: "HTTP #{response.code}"}
376
377
  end
377
378
  rescue => e
378
379
  Cloudwise.log_error { "Cloudwise: Error fetching server timestamp: #{e.message}" }
379
- { success: false, error: e.message }
380
+ {success: false, error: e.message}
380
381
  end
381
382
 
382
383
  private
384
+
383
385
  def post(path, data)
384
386
  # 统一处理 API 路径前缀
385
387
  path = apply_api_prefix(path)
@@ -397,19 +399,23 @@ module Datadog
397
399
  # 这可以避免在 tracer 未初始化时触发 NoMethodError
398
400
  request['DD-Internal-Untraced-Request'] = '1'
399
401
  request.body = data.to_json
400
- Cloudwise.log_debug { "Cloudwise API request:#{request.method} #{uri.to_s} with data: #{data.inspect}" }
402
+ Cloudwise.log_debug { "Cloudwise API request:#{request.method} #{uri} with data: #{data.inspect}" }
401
403
 
402
404
  response = http.request(request)
403
405
  handle_response(response, path)
404
406
  rescue => e
405
407
  Cloudwise.log_error { "Cloudwise API error for #{path}: #{e.class.name} #{e.message}" }
406
- { success: false, error: e.message, code: nil }
408
+ {success: false, error: e.message, code: nil}
407
409
  end
408
410
 
409
411
  def handle_response(response, path)
410
412
  case response.code.to_i
411
413
  when 200..299
412
- body = JSON.parse(response.body) rescue {}
414
+ body = begin
415
+ JSON.parse(response.body)
416
+ rescue
417
+ {}
418
+ end
413
419
  code = body['code'] || body['status_code']
414
420
 
415
421
  Cloudwise.log_debug { "Cloudwise API response for #{path}: code=#{code}, body=#{body.inspect}" }
@@ -422,17 +428,16 @@ module Datadog
422
428
  }
423
429
  when 400..499
424
430
  Cloudwise.log_warn { "Cloudwise API client error for #{path}: #{response.code} #{response.body}" }
425
- { success: false, error: "Client error: #{response.code}", code: nil }
431
+ {success: false, error: "Client error: #{response.code}", code: nil}
426
432
  when 500..599
427
433
  Cloudwise.log_error { "Cloudwise API server error for #{path}: #{response.code} #{response.body}" }
428
- { success: false, error: "Server error: #{response.code}", code: nil }
434
+ {success: false, error: "Server error: #{response.code}", code: nil}
429
435
  else
430
436
  Cloudwise.log_warn { "Cloudwise API unexpected response for #{path}: #{response.code}" }
431
- { success: false, error: "Unexpected response: #{response.code}", code: nil }
437
+ {success: false, error: "Unexpected response: #{response.code}", code: nil}
432
438
  end
433
439
  end
434
440
 
435
-
436
441
  # 获取校正后的秒级时间戳
437
442
  # 如果启用了时间同步,会应用偏移量校正
438
443
  # @return [Integer] 校正后的秒级时间戳
@@ -510,7 +515,6 @@ module Datadog
510
515
  rescue => e
511
516
  Cloudwise.log_debug { "Cloudwise: Failed to get IP via interfaces: #{e.message}" }
512
517
  end
513
-
514
518
  end
515
519
 
516
520
  # 获取 Agent 路径
@@ -606,16 +610,17 @@ module Datadog
606
610
 
607
611
  # 1. 尝试从 Datadog 配置读取(0.0-1.0 的浮点数)
608
612
  if defined?(Datadog.configuration) &&
609
- Datadog.configuration.respond_to?(:tracing) &&
610
- Datadog.configuration.tracing.respond_to?(:sampling) &&
611
- Datadog.configuration.tracing.sampling.respond_to?(:default_rate)
613
+ Datadog.configuration.respond_to?(:tracing) &&
614
+ Datadog.configuration.tracing.respond_to?(:sampling) &&
615
+ Datadog.configuration.tracing.sampling.respond_to?(:default_rate)
612
616
  configured_rate = Datadog.configuration.tracing.sampling.default_rate
613
617
  rate = configured_rate if configured_rate && configured_rate >= 0.0 && configured_rate <= 1.0
614
618
  end
615
619
 
616
620
  # 2. 尝试从环境变量读取(DD_TRACE_SAMPLE_RATE,0.0-1.0 的浮点数)
617
- if rate.nil? && ENV['DD_TRACE_SAMPLE_RATE']
618
- env_rate = ENV['DD_TRACE_SAMPLE_RATE'].to_f
621
+ env_rate_str = DATADOG_ENV['DD_TRACE_SAMPLE_RATE']
622
+ if rate.nil? && env_rate_str
623
+ env_rate = env_rate_str.to_f
619
624
  rate = env_rate if env_rate >= 0.0 && env_rate <= 1.0
620
625
  end
621
626
 
@@ -768,7 +773,7 @@ module Datadog
768
773
  @account_id = @token_account_id
769
774
  Cloudwise.log_debug { "Cloudwise: Token parsed - account_id: #{@token_account_id}, user_id: #{@token_user_id}" }
770
775
 
771
- #account_id
776
+ # account_id
772
777
  ENV['CLOUDWISE_ACCOUNT_ID'] = @token_account_id.to_s
773
778
  else
774
779
  Cloudwise.log_warn { 'Cloudwise: Invalid token format (expected base64 of account_id@user_id)' }
@@ -782,15 +787,14 @@ module Datadog
782
787
  end
783
788
  end
784
789
 
785
-
786
790
  # 获取 Cloudwise sys 配置值
787
791
  # 优先级: Datadog.configuration.cloudwise.sys > CW_SYS 环境变量 > 默认值 'default'
788
792
  # @return [String] sys 值
789
793
  def get_cloudwise_sys
790
794
  # 优先从配置读取
791
795
  if defined?(Datadog.configuration) &&
792
- Datadog.configuration.respond_to?(:cloudwise) &&
793
- Datadog.configuration.cloudwise.respond_to?(:sys)
796
+ Datadog.configuration.respond_to?(:cloudwise) &&
797
+ Datadog.configuration.cloudwise.respond_to?(:sys)
794
798
  sys = Datadog.configuration.cloudwise.sys
795
799
  return sys if sys && !sys.empty? && sys != 'default'
796
800
  end
@@ -817,7 +821,6 @@ module Datadog
817
821
  ''
818
822
  end
819
823
 
820
-
821
824
  # Get system UUID
822
825
  # Try multiple methods to get a unique system identifier
823
826
  def get_system_uuid
@@ -834,7 +837,7 @@ module Datadog
834
837
  end
835
838
 
836
839
  # Method 3: Try macOS system_profiler
837
- if RUBY_PLATFORM =~ /darwin/
840
+ if RUBY_PLATFORM.match?(/darwin/)
838
841
  uuid = `system_profiler SPHardwareDataType 2>/dev/null | awk '/UUID/ { print $3; }'`.strip
839
842
  return uuid unless uuid.empty?
840
843
  end
@@ -870,6 +873,13 @@ module Datadog
870
873
  'unknown'
871
874
  end
872
875
 
876
+ # Safe gethostname with rescue
877
+ def safe_gethostname
878
+ Socket.gethostname
879
+ rescue
880
+ 'unknown'
881
+ end
882
+
873
883
  # Get MAC address
874
884
  def get_mac_address
875
885
  # Try to get MAC address from network interfaces
@@ -963,10 +973,10 @@ module Datadog
963
973
  handle_response(response, path)
964
974
  rescue => e
965
975
  Cloudwise.log_error { "Cloudwise DOCC API error for #{path}: #{e.class.name} #{e.message}" }
966
- { success: false, error: e.message, code: nil }
976
+ {success: false, error: e.message, code: nil}
967
977
  end
968
-
969
978
  end
979
+ # rubocop:enable CustomCops/EnvUsageCop
970
980
  end
971
981
  end
972
982
  end
@@ -11,6 +11,8 @@ require_relative 'docc_heartbeat_worker'
11
11
  require_relative 'docc_operation_worker'
12
12
  require_relative 'time_sync_worker'
13
13
 
14
+ require_relative '../../core/environment/variable_helpers'
15
+
14
16
  module Datadog
15
17
  module Core
16
18
  module Cloudwise
@@ -19,7 +21,7 @@ module Datadog
19
21
  class << self
20
22
  # Check if debug logging is enabled
21
23
  def debug_enabled?
22
- @debug_enabled ||= ENV.fetch('DD_TRACE_DEBUG', 'false').downcase == 'true'
24
+ @debug_enabled ||= (DATADOG_ENV['DD_TRACE_DEBUG'] || 'false').downcase == 'true'
23
25
  end
24
26
 
25
27
  # Log debug message (only when DD_TRACE_DEBUG=true)
@@ -46,9 +48,9 @@ module Datadog
46
48
  # Main component that manages Cloudwise workers with proper initialization order
47
49
  class Component
48
50
  attr_reader :client, :probe_state, :host_id_worker, :heartbeat_worker,
49
- :license_worker, :app_registration_worker, :logger,
50
- :docc_registration_worker, :docc_heartbeat_worker, :docc_operation_worker,
51
- :time_sync_worker
51
+ :license_worker, :app_registration_worker, :logger,
52
+ :docc_registration_worker, :docc_heartbeat_worker, :docc_operation_worker,
53
+ :time_sync_worker
52
54
 
53
55
  # 类级别的单例锁,确保全局只初始化一次
54
56
  @initialization_mutex = Mutex.new
@@ -103,46 +105,43 @@ module Datadog
103
105
  if self.class.initialization_started
104
106
  cloudwise_already_started = true
105
107
  Cloudwise.log_debug { 'Cloudwise Component already initialized globally' }
106
- else
108
+ elsif self.class.singleton_instance && instance_already_started?
107
109
  # 检查是否有已存在的单例实例
108
- if self.class.singleton_instance && instance_already_started?
109
- cloudwise_already_started = true
110
- Cloudwise.log_debug { 'Initializing Datadog components for this Components instance...' }
111
- else
112
- self.class.initialization_started = true
113
- self.class.singleton_instance = self
114
- end
110
+ cloudwise_already_started = true
111
+ Cloudwise.log_debug { 'Initializing Datadog components for this Components instance...' }
112
+ else
113
+ self.class.initialization_started = true
114
+ self.class.singleton_instance = self
115
115
  end
116
116
  end
117
117
 
118
118
  # 如果 Cloudwise 已经启动,只需要为这个新的 Components 实例初始化 Datadog 组件
119
119
  if cloudwise_already_started
120
- if block
121
- block.call # 立即初始化这个实例的 Datadog 组件
122
- end
120
+ block&.call # 立即初始化这个实例的 Datadog 组件
123
121
  return true
124
122
  end
125
123
 
126
- # 立即初始化 Datadog 组件(不等待 Cloudwise 验证)
127
- if block
128
- Cloudwise.log_debug { 'Initializing Datadog components immediately...' }
129
- block.call
130
- Cloudwise.log_debug { 'Datadog components initialized (data collection pending ProbeState)' }
131
- end
124
+ # 立即初始化 Datadog 组件(不等待 Cloudwise 验证)
125
+ # NOTE: 这里不能使用 block&.call 因为需要在调用前后执行日志
126
+ if block # rubocop:disable Style/SafeNavigation
127
+ Cloudwise.log_debug { 'Initializing Datadog components immediately...' }
128
+ block.call
129
+ Cloudwise.log_debug { 'Datadog components initialized (data collection pending ProbeState)' }
130
+ end
132
131
 
133
- # 根据模式启动不同的 workers
134
- if @client.use_integrated_mode?
135
- start_docc_workers_when_ready
136
- else
137
- # Start Host ID Worker in background (will retry until success)
138
- Cloudwise.log_debug { 'Starting Host ID generation worker (async, infinite retry)...' }
139
- @host_id_worker.perform
132
+ # 根据模式启动不同的 workers
133
+ if @client.use_integrated_mode?
134
+ start_docc_workers_when_ready
135
+ else
136
+ # Start Host ID Worker in background (will retry until success)
137
+ Cloudwise.log_debug { 'Starting Host ID generation worker (async, infinite retry)...' }
138
+ @host_id_worker.perform
140
139
 
141
- # Start other Cloudwise workers in background
142
- start_cloudwise_workers_when_ready
143
- end
140
+ # Start other Cloudwise workers in background
141
+ start_cloudwise_workers_when_ready
142
+ end
144
143
 
145
- Cloudwise.log_debug { 'Cloudwise Component initialization started (async)' }
144
+ Cloudwise.log_debug { 'Cloudwise Component initialization started (async)' }
146
145
 
147
146
  true
148
147
  end
@@ -218,15 +217,15 @@ module Datadog
218
217
 
219
218
  # Get component status
220
219
  def status
221
- return { enabled: false } unless @enabled
220
+ return {enabled: false} unless @enabled
222
221
 
223
222
  probe_status = probe_state.status
224
223
  # 获取时间同步状态
225
224
  time_sync_status = if defined?(Datadog::Core::Cloudwise::TimeSyncWorker)
226
- Datadog::Core::Cloudwise::TimeSyncWorker.status
227
- else
228
- { enabled: false }
229
- end
225
+ Datadog::Core::Cloudwise::TimeSyncWorker.status
226
+ else
227
+ {enabled: false}
228
+ end
230
229
 
231
230
  base_status = {
232
231
  enabled: true,
@@ -504,7 +503,10 @@ module Datadog
504
503
  probe_state.mark_host_id_ready!
505
504
 
506
505
  # Set environment variable
507
- ENV['CLOUDWISE_ACCOUNT_ID'] = client.account_id
506
+ # NOTE: 设置环境变量必须使用 ENV,DATADOG_ENV 只支持读取
507
+ # rubocop:disable CustomCops/EnvUsageCop
508
+ ENV['CLOUDWISE_ACCOUNT_ID'] = client.account_id.to_s
509
+ # rubocop:enable CustomCops/EnvUsageCop
508
510
 
509
511
  Cloudwise.log_debug { "Cloudwise: Host ID generated successfully on attempt #{retry_count}" }
510
512
  Cloudwise.log_debug { "Cloudwise: account_id = #{client.account_id}" }
@@ -518,7 +520,6 @@ module Datadog
518
520
  Cloudwise.log_warn { "Cloudwise: Retrying in #{retry_interval} seconds..." }
519
521
 
520
522
  probe_state.mark_host_id_failed!
521
-
522
523
  rescue => e
523
524
  # Exception occurred - log and retry
524
525
  Cloudwise.log_error { "Cloudwise: Host ID generation error (attempt #{retry_count}): #{e.class.name} #{e.message}" }
@@ -102,4 +102,3 @@ module Datadog
102
102
  end
103
103
  end
104
104
  end
105
-
@@ -79,13 +79,9 @@ module Datadog
79
79
 
80
80
  # 获取任务数据(data 是一个数组)
81
81
  tasks = result[:data]
82
- return unless tasks && tasks.is_a?(Array)
82
+ return unless tasks.is_a?(Array) && !tasks.empty?
83
83
 
84
- # 如果没有任务,直接返回
85
- if tasks.empty?
86
- Cloudwise.log_debug { "Cloudwise DOCC: No operations to execute" }
87
- return
88
- end
84
+ Cloudwise.log_debug { "Cloudwise DOCC: Processing #{tasks.size} operation(s)" }
89
85
 
90
86
  # 收集所有任务的执行结果
91
87
  results = []
@@ -105,19 +101,19 @@ module Datadog
105
101
 
106
102
  task_id = task_data['taskId']
107
103
  operation = task_data['operate']
108
- agent_instance_id = task_data['agentInstanceId']
104
+ # agent_instance_id = task_data['agentInstanceId']
109
105
 
110
106
  Cloudwise.log_debug { "Cloudwise DOCC: Received operation - taskId: #{task_id}, operation: #{operation}" }
111
107
 
112
108
  # 执行操作并返回结果
113
- execute_operation(task_id, operation, agent_instance_id)
109
+ execute_operation(task_id, operation)
114
110
  rescue => e
115
111
  Cloudwise.log_error { "Cloudwise DOCC: Error processing task #{task_id}: #{e.class.name} #{e.message}" }
116
112
  # 返回失败结果
117
113
  create_operation_result(task_id, 'failed', "Error processing task: #{e.message}")
118
114
  end
119
115
 
120
- def execute_operation(task_id, operation, agent_instance_id)
116
+ def execute_operation(task_id, operation)
121
117
  case operation
122
118
  when OPERATION_AGENT_START
123
119
  handle_agent_start(task_id)
@@ -198,4 +194,3 @@ module Datadog
198
194
  end
199
195
  end
200
196
  end
201
-
@@ -86,4 +86,3 @@ module Datadog
86
86
  end
87
87
  end
88
88
  end
89
-
@@ -260,20 +260,18 @@ module Datadog
260
260
  reasons << 'License invalid' unless @license_valid
261
261
  reasons << 'Agent stopped by operation' unless @docc_operation_active
262
262
 
263
- Cloudwise.log_debug { "Cloudwise DOCC: Probe SUSPENDED - data collection disabled (#{reasons.join(', ')})" }
263
+ Cloudwise.log_debug { "Cloudwise DOCC: Probe SUSPENDED - data collection disabled (#{reasons.join(", ")})" }
264
264
  end
265
- else
265
+ elsif @host_id_ready && @heartbeat_active && @license_valid
266
266
  # 传统模式状态日志
267
- if @host_id_ready && @heartbeat_active && @license_valid
268
- Cloudwise.log_debug { 'Cloudwise: Probe ACTIVE - data collection enabled' }
269
- else
270
- reasons = []
271
- reasons << 'Host ID not ready' unless @host_id_ready
272
- reasons << 'Heartbeat inactive' unless @heartbeat_active
273
- reasons << 'License invalid' unless @license_valid
267
+ Cloudwise.log_debug { 'Cloudwise: Probe ACTIVE - data collection enabled' }
268
+ else
269
+ reasons = []
270
+ reasons << 'Host ID not ready' unless @host_id_ready
271
+ reasons << 'Heartbeat inactive' unless @heartbeat_active
272
+ reasons << 'License invalid' unless @license_valid
274
273
 
275
- Cloudwise.log_debug { "Cloudwise: Probe SUSPENDED - data collection disabled (#{reasons.join(', ')})" }
276
- end
274
+ Cloudwise.log_debug { "Cloudwise: Probe SUSPENDED - data collection disabled (#{reasons.join(", ")})" }
277
275
  end
278
276
  end
279
277
  end
@@ -66,14 +66,10 @@ module Datadog
66
66
 
67
67
  # 上次同步时间
68
68
  # @return [Integer, nil] 毫秒时间戳
69
- def last_sync_time
70
- @last_sync_time
71
- end
69
+ attr_reader :last_sync_time
72
70
 
73
71
  # 设置上次同步时间
74
- def last_sync_time=(value)
75
- @last_sync_time = value
76
- end
72
+ attr_writer :last_sync_time
77
73
 
78
74
  # 校正时间戳(纳秒)
79
75
  # 将本地时间戳转换为服务器时间戳
@@ -206,7 +206,6 @@ module Datadog
206
206
  # 1. Immediately if Cloudwise is disabled
207
207
  # 2. After Host ID is ready if Cloudwise is enabled
208
208
  def initialize_datadog_components(settings)
209
-
210
209
  # This agent_settings is intended for use within Core. If you require
211
210
  # agent_settings within a product outside of core you should extend
212
211
  # the Core resolver from within your product/component's namespace.
@@ -221,7 +220,7 @@ module Datadog
221
220
  @tracer = Datadog::Tracing::Component.build_tracer(settings, agent_settings, logger: @logger)
222
221
 
223
222
  # Set the components reference on the tracer so it can check Cloudwise state
224
- @tracer.instance_variable_set(:@components, self) if @tracer
223
+ @tracer&.instance_variable_set(:@components, self)
225
224
 
226
225
  @crashtracker = self.class.build_crashtracker(settings, agent_settings, logger: @logger)
227
226
 
@@ -272,7 +271,6 @@ module Datadog
272
271
 
273
272
  # Starts up components
274
273
  def startup!(settings, old_state: nil)
275
-
276
274
  telemetry.start(old_state&.telemetry_enabled?, components: self)
277
275
 
278
276
  if settings.profiling.enabled
@@ -805,15 +805,14 @@ module Datadog
805
805
  option :enabled do |o|
806
806
  o.env Core::Telemetry::Ext::ENV_ENABLED
807
807
  o.default do
808
+ # 使用 cloudwise 心跳,禁用 Datadog Telemetry
808
809
  if Datadog::Core::Environment::Execution.development?
809
810
  Datadog.logger.debug do
810
811
  'Development environment detected, disabling Telemetry. ' \
811
812
  'You can enable it with DD_INSTRUMENTATION_TELEMETRY_ENABLED=true.'
812
813
  end
813
- false
814
- else
815
- false #使用cloudwise 心跳
816
814
  end
815
+ false
817
816
  end
818
817
  o.type :bool
819
818
  end
@@ -942,22 +941,13 @@ module Datadog
942
941
  settings :remote do
943
942
  # Enable remote configuration. This allows fetching of remote configuration for live updates.
944
943
  #
945
- # @default `DD_REMOTE_CONFIGURATION_ENABLED` environment variable, otherwise `true`.
946
- # By default, remote configuration is disabled in development environments.
944
+ # @default `DD_REMOTE_CONFIGURATION_ENABLED` environment variable, otherwise `false`.
945
+ # Disabled by default for Cloudwise environment (Cloudwise uses its own configuration mechanism).
947
946
  # @return [Boolean]
948
947
  option :enabled do |o|
949
948
  o.env Core::Remote::Ext::ENV_ENABLED
950
- o.default do
951
- if Datadog::Core::Environment::Execution.development?
952
- Datadog.logger.debug do
953
- 'Development environment detected, disabling Remote Configuration. ' \
954
- 'You can enable it with DD_REMOTE_CONFIGURATION_ENABLED=true.'
955
- end
956
- false
957
- else
958
- true
959
- end
960
- end
949
+ # Cloudwise 环境下禁用 Remote Configuration,使用 Cloudwise 自己的配置机制
950
+ o.default false
961
951
  o.type :bool
962
952
  end
963
953
 
@@ -1029,11 +1019,13 @@ module Datadog
1029
1019
  # Integrated mode - whether agent handles integrated environment
1030
1020
  # @default `DD_CLOUDWISE_INTEGRATED_MODE` environment variable, otherwise `true`
1031
1021
  # @return [Boolean]
1022
+ # rubocop:disable CustomCops/EnvStringValidationCop
1032
1023
  option :integrated_mode do |o|
1033
1024
  o.type :bool
1034
1025
  o.env 'DD_CLOUDWISE_INTEGRATED_MODE'
1035
1026
  o.default true
1036
1027
  end
1028
+ # rubocop:enable CustomCops/EnvStringValidationCop
1037
1029
 
1038
1030
  # Token for integrated mode (DOCC interface authentication)
1039
1031
  # Format: base64 encoded "account_id@user_id"
@@ -1045,22 +1037,22 @@ module Datadog
1045
1037
  o.default nil
1046
1038
  end
1047
1039
 
1048
- # API 路径前缀模式(简化配置)
1049
- # 可选值: 'doop', 'apm', 'custom'
1050
- # 优先级: api_prefix_mode > api_prefix > integrated_mode > 无前缀
1051
- option :api_prefix_mode do |o|
1052
- o.type :string, nilable: true
1053
- o.env 'DD_CLOUDWISE_API_PREFIX_MODE'
1054
- o.default nil
1055
- end
1040
+ # API 路径前缀模式(简化配置)
1041
+ # 可选值: 'doop', 'apm', 'custom'
1042
+ # 优先级: api_prefix_mode > api_prefix > integrated_mode > 无前缀
1043
+ option :api_prefix_mode do |o|
1044
+ o.type :string, nilable: true
1045
+ o.env 'DD_CLOUDWISE_API_PREFIX_MODE'
1046
+ o.default nil
1047
+ end
1056
1048
 
1057
- # API 路径前缀(自定义配置)
1058
- # 优先级: api_prefix_mode > api_prefix > integrated_mode ('/apm') > 无前缀
1059
- option :api_prefix do |o|
1060
- o.type :string, nilable: true
1061
- o.env 'DD_CLOUDWISE_API_PREFIX'
1062
- o.default nil
1063
- end
1049
+ # API 路径前缀(自定义配置)
1050
+ # 优先级: api_prefix_mode > api_prefix > integrated_mode ('/apm') > 无前缀
1051
+ option :api_prefix do |o|
1052
+ o.type :string, nilable: true
1053
+ o.env 'DD_CLOUDWISE_API_PREFIX'
1054
+ o.default nil
1055
+ end
1064
1056
 
1065
1057
  # SYS
1066
1058
  option :sys do |o|
@@ -1072,6 +1064,7 @@ module Datadog
1072
1064
  # Heartbeat interval in seconds
1073
1065
  # @default `DD_CLOUDWISE_HEARTBEAT_INTERVAL` environment variable, otherwise `30`
1074
1066
  # @return [Integer]
1067
+ # rubocop:disable CustomCops/EnvStringValidationCop
1075
1068
  option :heartbeat_interval do |o|
1076
1069
  o.type :int
1077
1070
  o.env 'DD_CLOUDWISE_HEARTBEAT_INTERVAL'
@@ -1086,6 +1079,7 @@ module Datadog
1086
1079
  o.env 'DD_CLOUDWISE_LICENSE_CHECK_INTERVAL'
1087
1080
  o.default 300
1088
1081
  end
1082
+ # rubocop:enable CustomCops/EnvStringValidationCop
1089
1083
 
1090
1084
  # Application registration interval in seconds (3 minutes)
1091
1085
  # @default `DD_CLOUDWISE_APP_REGISTRATION_INTERVAL` environment variable, otherwise `180`