Module: TempmailSdk::Telemetry

Defined in:
lib/tempmail_sdk/telemetry.rb

Overview

匿名用量遥测 默认开启,可通过配置或环境变量关闭;批量异步上报,失败静默忽略

Constant Summary collapse

DEFAULT_URL =
"https://sdk-1.openel.top/v1/event"
MAX_BATCH =
32
FLUSH_SEC =
2.0
EMAIL_RE =
/[^\s@]{1,64}@[^\s@]{1,255}/.freeze
HOST_OS =

主机信息在进程内不变,预取为常量避免每次 flush 重复读取 RbConfig

(RbConfig::CONFIG["host_os"] || "unknown").freeze
HOST_CPU =
(RbConfig::CONFIG["host_cpu"] || "unknown").freeze

Class Method Summary collapse

Class Method Details

.report(operation:, channel:, success:, attempt_count:, channels_tried:, error:) ⇒ Object

上报一条遥测事件 rubocop:disable Metrics/ParameterLists



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tempmail_sdk/telemetry.rb', line 26

def report(operation:, channel:, success:, attempt_count:, channels_tried:, error:)
  return unless telemetry_on?

  ensure_periodic

  ev = {
    "operation" => operation,
    "channel" => channel,
    "success" => success,
    "attempt_count" => attempt_count,
    "ts_ms" => (Time.now.to_f * 1000).to_i
  }
  ev["channels_tried"] = channels_tried if channels_tried.positive?
  err = sanitize(error)
  ev["error"] = err unless err.empty?

  n = 0
  @lock.synchronize do
    @queue << ev
    n = @queue.size
  end

  flush_batch if n >= MAX_BATCH
end

.sdk_versionString

Returns SDK 版本号.

Returns:

  • (String)

    SDK 版本号



53
54
55
# File 'lib/tempmail_sdk/telemetry.rb', line 53

def sdk_version
  VERSION
end