简体   繁体   中英

How can I emit custom metrics from a Cadence workflow or activity?

Cadence emits a bunch of metrics using tally. Is it possible to emit my own metrics using Cadence SDK?

Go SDK has cadence.GetMetricsScope().Counter(counterName).Inc() but it doesn't seem to work when I just call it. Am I missing some required configuration?

You can add your own metrics using both the Go and Java SDKs. The following examples show how to do it using the Go SDK, and Java SDK isn't much different than it.

In workflow code:

cadence.GetMetricsScope().Counter(counterName).Inc(1)

In activity code:

cadence.GetActivityMetricsScope().Counter(counterName).Inc(1)

However, just doing that will not be sufficient to actually emit the metrics. The reason is that tally uses tally.NoopScope by default, which does nothing as the name implies. Therefore, you'd also need to set up the MetricsScope as part of the WorkerOptions as in the following example:

workerOptions := cadence.WorkerOptions{
 MetricsScope: myTallyScope, 
}
worker := cadence.NewWorker(service, domain, taskList, workerOptions)

You can create myTallyScope by following the examples in tally documentation for Go and Java .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM