Files
tasks/chasm/lib/nexusoperation/metrics.go
sammandGitHub 84f2b103e3 Add caller-side Nexus operation metrics (#10071)
## What changed?

NOTE: Recreation of https://github.com/temporalio/temporal/pull/10026
since that PR cannot be re-opened or have its target branch updated.

New metrics:
### Counters

| Metric | Description |
|--------|-------------|
| `nexus_operation_success_count` | Successfully completed operations |
| `nexus_operation_failed_count` | Failed operations |
| `nexus_operation_cancel_count` | Cancelled operations |
| `nexus_operation_terminate_count` | Operations terminated before
completion |
| `nexus_operation_timeout_count` | Operations timed out before
completion |

### Histograms

| Metric | Description |
|--------|-------------|
| `nexus_operation_schedule_to_close_latency` | Time between schedule
and close for sync and async operations |
| `nexus_operation_schedule_to_start_latency` | Time between schedule
and start for sync and async operations |
| `nexus_operation_start_to_close_latency` | Time between start and
close for async operations only |

## Labels

All metrics use the following labels:

| Label | Notes |
|-------|-------|
| `namespace` | |
| `nexus_endpoint` | |
| `nexus_service` | Controlled by Dynamic config |
| `nexus_operation` | Controlled by Dynamic config |
| `workflowType` | |

Latency metrics also include:

| Label | Values |
|-------|--------|
| `outcome` | succeeded, failed, canceled, terminated, timedout |

Timeout Count also includes:

| Label | Values |
|-------|--------|
| `timeout_type` | StartToClose, ScheduleToStart, ScheduleToClose  |

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
Metrics emitting isn't nil safe, and enrich metrics could panic if
misconfigured.
2026-05-01 12:23:34 -07:00

64 lines
2.4 KiB
Go

package nexusoperation
import (
"go.temporal.io/server/common/metrics"
)
var OutboundRequestCounter = metrics.NewCounterDef(
"nexus_outbound_requests",
metrics.WithDescription("The number of Nexus outbound requests made by the history service."),
)
var OutboundRequestLatency = metrics.NewTimerDef(
"nexus_outbound_latency",
metrics.WithDescription("Latency of outbound Nexus requests made by the history service."),
)
var NexusOperationSuccessCount = metrics.NewCounterDef(
"nexus_operation_success",
metrics.WithDescription("Nexus Operations successfully completed."),
)
var NexusOperationFailedCount = metrics.NewCounterDef(
"nexus_operation_fail",
metrics.WithDescription("Nexus Operations failures."),
)
var NexusOperationCancelCount = metrics.NewCounterDef(
"nexus_operation_cancel",
metrics.WithDescription("Nexus Operations cancellations."),
)
var NexusOperationTerminateCount = metrics.NewCounterDef(
"nexus_operation_terminate",
metrics.WithDescription("Nexus Operations that were terminated before completion."),
)
var NexusOperationTimeoutCount = metrics.NewCounterDef(
"nexus_operation_timeout",
metrics.WithDescription("Nexus Operations that timed out before completion."),
)
var NexusOperationScheduleToCloseLatency = metrics.NewTimerDef(
"nexus_operation_schedule_to_close_latency",
metrics.WithDescription("Duration from Nexus Operation scheduled time to terminal state."),
)
var NexusOperationScheduleToStartLatency = metrics.NewTimerDef(
"nexus_operation_schedule_to_start_latency",
metrics.WithDescription("Duration from Nexus Operation scheduled time to started time."),
)
var NexusOperationStartToCloseLatency = metrics.NewTimerDef(
"nexus_operation_start_to_close_latency",
metrics.WithDescription("Duration from Nexus Operation started time to completed time. Only emitted for async operations."),
)
type NexusMetricTagConfig struct {
// Include service name as a metric tag. Used for caller and handler metrics.
IncludeServiceTag bool
// Include operation name as a metric tag. Used for caller and handler metrics.
IncludeOperationTag bool
// Configuration for mapping request headers to metric tags. Only used for handler metrics.
HeaderTagMappings []NexusHeaderTagMapping
}
type NexusHeaderTagMapping struct {
// Name of the request header to extract value from
SourceHeader string
// Name of the metric tag to set with the header value
TargetTag string
}