generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbe565d
commit 53136c3
Showing
6 changed files
with
57 additions
and
15 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
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,5 @@ | ||
package observability | ||
|
||
const ( | ||
fsmRefAttribute string = "ftl.fsm.ref" | ||
) |
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,38 @@ | ||
package observability | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/TBD54566975/ftl/backend/schema" | ||
"github.com/TBD54566975/ftl/internal/observability/metrics" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
const fsmMeterName = "ftl.fsm" | ||
|
||
var fsmMeter = otel.Meter("ftl.fsm") | ||
|
||
var fsmCounters = struct { | ||
instancesActive metric.Int64UpDownCounter | ||
}{} | ||
|
||
// TODO error logging and handling | ||
func InitFSMMetrics() { | ||
fsmCounters.instancesActive, _ = fsmMeter.Int64UpDownCounter( | ||
fmt.Sprintf("%s.instances.active", fsmMeterName), | ||
metric.WithDescription("counts the number of active FSM instances")) | ||
} | ||
|
||
func FSMInstanceCreated(ctx context.Context, fsm schema.RefKey) { | ||
fsmCounters.instancesActive.Add(ctx, 1, metric.WithAttributes( | ||
attribute.String(metrics.ModuleNameAttribute, fsm.Module), | ||
attribute.String(fsmRefAttribute, fsm.String()))) | ||
} | ||
|
||
func FSMInstanceCompleted(ctx context.Context, fsm schema.RefKey) { | ||
fsmCounters.instancesActive.Add(ctx, -1, metric.WithAttributes( | ||
attribute.String(metrics.ModuleNameAttribute, fsm.Module), | ||
attribute.String(fsmRefAttribute, fsm.String()))) | ||
} |
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,5 @@ | ||
package observability | ||
|
||
func Init() { | ||
InitFSMMetrics() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,5 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/TBD54566975/ftl/backend/schema" | ||
"go.opentelemetry.io/otel/attribute" | ||
const ( | ||
ModuleNameAttribute = "ftl.module.name" | ||
) | ||
|
||
// ModuleNameAttribute identifies the name of the module that the associated | ||
// metric originates from. | ||
func ModuleNameAttribute(name string) attribute.KeyValue { | ||
return attribute.String("ftl.module.name", name) | ||
} | ||
|
||
// VerbRefAttribute identifies the verb that the associated metric originates | ||
// from. The entire module qualified name is used: e.g. {module.verb} | ||
func VerbRefAttribute(ref schema.Ref) attribute.KeyValue { | ||
return attribute.String("ftl.verb.ref", ref.Name) | ||
} |