-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(temporal): enable sdk metrics (#2200)
- Adds a new env variable to enable specific metric from Temporal SDK: - `PEERDB_TEMPORAL_OTEL_METRICS_EXPORT_LIST` can be a comma separated list of metrics to expose. If the list is empty or no metric matches the elements in the list, then they are not exported - If the value is set to `__ALL__`, then all Temporal metrics are exposed - Additionally adds an initial interface of how temporal interceptors would look like - The added metrics include `temporal_workflow_task_execution_failed` metric having an attribute of `failure_reason` whose value can tell us about nondeterminism if the value is `nondeterminismerror` (temporalio/sdk-go#1295) - Additionally, the metrics are prefixed with `temporal.` PeerDB metrics should not be affected as they use a separate exporter and meterprovider. The rationale behind exporting a subset of metrics is noise and cases where metrics ingestion cannot be ignored Full list of metrics can be viewed at https://docs.temporal.io/references/sdk-metrics
- Loading branch information
1 parent
877534a
commit b23911e
Showing
9 changed files
with
214 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"go.temporal.io/sdk/interceptor" | ||
"go.temporal.io/sdk/workflow" | ||
) | ||
|
||
type LoggedWorkflowInboundInterceptor struct { | ||
interceptor.WorkflowInboundInterceptorBase | ||
Next interceptor.WorkflowInboundInterceptor | ||
} | ||
|
||
func NewLoggedWorkflowInboundInterceptor(next interceptor.WorkflowInboundInterceptor) *LoggedWorkflowInboundInterceptor { | ||
return &LoggedWorkflowInboundInterceptor{ | ||
WorkflowInboundInterceptorBase: interceptor.WorkflowInboundInterceptorBase{Next: next}, | ||
Next: next, | ||
} | ||
} | ||
|
||
func (w *LoggedWorkflowInboundInterceptor) ExecuteWorkflow( | ||
ctx workflow.Context, | ||
in *interceptor.ExecuteWorkflowInput, | ||
) (interface{}, error) { | ||
// Workflow starts here | ||
result, err := w.Next.ExecuteWorkflow(ctx, in) | ||
// Workflow ends here | ||
return result, err | ||
} | ||
|
||
type LoggedActivityInboundInterceptor struct { | ||
interceptor.ActivityInboundInterceptorBase | ||
Next interceptor.ActivityInboundInterceptor | ||
} | ||
|
||
func NewLoggedActivityInboundInterceptor(next interceptor.ActivityInboundInterceptor) *LoggedActivityInboundInterceptor { | ||
return &LoggedActivityInboundInterceptor{ | ||
ActivityInboundInterceptorBase: interceptor.ActivityInboundInterceptorBase{Next: next}, | ||
Next: next, | ||
} | ||
} | ||
|
||
func (c *LoggedActivityInboundInterceptor) ExecuteActivity( | ||
ctx context.Context, | ||
in *interceptor.ExecuteActivityInput, | ||
) (interface{}, error) { | ||
// Activity starts here | ||
out, err := c.Next.ExecuteActivity(ctx, in) | ||
// Activity ends here | ||
return out, err | ||
} | ||
|
||
type LoggedWorkerInterceptor struct { | ||
interceptor.WorkerInterceptorBase | ||
} | ||
|
||
func (c LoggedWorkerInterceptor) InterceptActivity( | ||
ctx context.Context, | ||
next interceptor.ActivityInboundInterceptor, | ||
) interceptor.ActivityInboundInterceptor { | ||
return NewLoggedActivityInboundInterceptor(next) | ||
} | ||
|
||
func (c LoggedWorkerInterceptor) InterceptWorkflow( | ||
ctx workflow.Context, | ||
next interceptor.WorkflowInboundInterceptor, | ||
) interceptor.WorkflowInboundInterceptor { | ||
// Workflow intercepted here | ||
intercepted := NewLoggedWorkflowInboundInterceptor(next) | ||
// Workflow intercepting ends here | ||
return intercepted | ||
} | ||
|
||
func NewLoggedWorkerInterceptor() *LoggedWorkerInterceptor { | ||
return &LoggedWorkerInterceptor{ | ||
WorkerInterceptorBase: interceptor.WorkerInterceptorBase{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../otel_metrics/peerdb_gauges/attributes.go → flow/otel_metrics/attributes.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package peerdb_gauges | ||
package otel_metrics | ||
|
||
const ( | ||
PeerNameKey string = "peerName" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package otel_metrics | ||
|
||
import "github.com/PeerDB-io/peer-flow/peerdbenv" | ||
|
||
func GetPeerDBOtelMetricsNamespace() string { | ||
return peerdbenv.GetEnvString("PEERDB_OTEL_METRICS_NAMESPACE", "") | ||
} | ||
|
||
func GetPeerDBOtelMetricsExportListEnv() string { | ||
return peerdbenv.GetEnvString("PEERDB_OTEL_METRICS_EXPORT_LIST", "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters