coinbase / temporal-ruby

Ruby SDK for Temporal
Apache License 2.0
213 stars 81 forks source link

Add statsd adapter #281

Closed Vuta closed 5 months ago

Vuta commented 5 months ago

problem

Temporal.metrics is sending tags as a plain hash

metrics_tags = { namespace: namespace, task_queue: task_queue }.freeze
Temporal.metrics.timing(
  Temporal::MetricKeys::ACTIVITY_POLLER_TIME_SINCE_LAST_POLL, 
  time_diff_ms, 
  metrics_tags
)

# timing definition
def timing(key, time, tags = {})
  adapter.timing(key, time, tags)
end

This is not compatible with statsd, which expects the tags to be nested inside tags That means applications can't just use statsd implementation, one like https://github.com/DataDog/dogstatsd-ruby. They need to implement their own adapter that builds the tags before passing to the underlying client.

approach

This PR adds an adapter that is compatible with statsd, so that applications can use that instead of writing their own.

statsd = Datadog::Statsd.new(...)
config.metrics_adapter = Temporal::MetricsAdapter::Statsd.new(statsd)