ワンクリックで
add-metric
TRIGGER when user asks to add or modify a metric, counter, gauge, or histogram, or to track/measure an operation.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
TRIGGER when user asks to add or modify a metric, counter, gauge, or histogram, or to track/measure an operation.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
TRIGGER when the user asks to upgrade the project to a newer or the latest version of Microbus, or to update the framework. Each Microbus release ships this one self-contained skill; it applies that release's single-version migration, then chains to the next release's copy of this skill until the target version is reached.
TRIGGER when user asks to create, scaffold, or initialize a new microservice.
How to choose the hostname of a new Microbus microservice. Referenced by the add-microservice and add-sql-microservice scaffolding skills (and, through their delegation to add-microservice, by add-python-microservice and import-openapi-microservice). Consult it whenever a microservice's hostname is being chosen.
Performs an architectural review of a microservice-based system built on the Microbus framework. Covers only cross-cutting, cross-microservice concerns - service boundaries, the dependency graph, coupling, cross-service consistency, data ownership, workflow composition, edge security, and system operations. Anything judgeable inside a single microservice directory belongs to the review-microservice skill and is out of scope here. Produces a structured report with findings and recommendations.
Reviews the microservices touched by a set of changes - by default the whole current feature branch versus its merge-base with main, plus any uncommitted work. Runs the review-microservice skill on each changed microservice and the review-architecture skill scoped to those microservices and their graph neighbors, then consolidates one report. Use before merging a branch or before committing working-tree changes.
Performs a thorough review of a single Microbus microservice. Checks for completeness, framework compliance, code quality, security, test coverage, documentation, API design, and data access performance. Produces a structured report with findings and recommendations.
| name | add-metric |
| description | TRIGGER when user asks to add or modify a metric, counter, gauge, or histogram, or to track/measure an operation. |
CRITICAL: Do NOT explore or analyze other microservices unless explicitly instructed to do so. The instructions in this skill are self-contained to this microservice.
CRITICAL: A metric is declared as a define.Metric var in myserviceapi/definition.go; its observe callback, if any, is implemented in service.go. Add the declaration and run cmd/genservice.
CRITICAL: Keep the // MARKER: MyMetric comment on the define.Metric var.
Copy this checklist and track your progress:
Creating or modifying a metric:
- [ ] Step 1: Read local CLAUDE.md file
- [ ] Step 2: Determine the kind
- [ ] Step 3: Determine if observable just in time
- [ ] Step 4: Determine the value type and labels
- [ ] Step 5: Determine the OpenTelemetry name
- [ ] Step 6: Declare the metric in definition.go
- [ ] Step 7: Record the metric
- [ ] Step 8: Generate the boilerplate
- [ ] Step 9: Test the callback
- [ ] Step 10: Housekeeping
CLAUDE.md FileRead the local CLAUDE.md file in the microservice's directory. It contains microservice-specific instructions that should take precedence over global instructions.
Determine if the metric is a:
If a histogram, determine the boundaries that determine its buckets.
For some metrics, and in particular gauges, it is enough to observe just in time before recording. For example, there's no reason to sample available system memory constantly if only the last sampling will be reported. Determine if this metric is observable.
The value type is the type of the number being recorded: int, float64, or time.Duration.
The labels are the dimensions the metric is broken down by, named like Go arguments (e.g. status, method). They are recorded as strings. A metric may have no labels.
The OpenTelemetry name of the metric:
For example, myapplication_my_metric_units.
Do not add a _total suffix to a counter's OpenTelemetry name. _total is a Prometheus naming convention, not an OpenTelemetry one.
definition.goAppend the define.Metric var to myserviceapi/definition.go. The godoc is the metric's description.
/*
MyMetric counts X.
*/
var MyMetric = define.Metric{ // MARKER: MyMetric
Kind: define.Counter, Value: int(0), Labels: []string{"status"},
OTelName: "myapplication_my_metric_units",
}
Kind is define.Counter, define.Gauge, or define.HistogramValue is a type carrier declaring the recorded value's type: int(0), float64(0), or time.Duration(0). For time.Duration, add the "time" importLabels is the list of label argument names; omit when there are noneBuckets: []float64{0.1, 0.5, 1, 5} is required for a histogram and omitted otherwiseOTelName is the name from Step 5Observable: true for a metric observed just in time (Step 3); omit when falseThe generated recorder is IncrementMyMetric(ctx, value, labels...) for a counter and RecordMyMetric(ctx, value, labels...) for a gauge or histogram.
If the metric is observable just in time, the boilerplate generator (Step 8) creates a placeholder OnObserveMyMetric handler in service.go, tagged // MARKER: MyMetric and holding a // TODO body. Fill in that body to record the current value, for example:
v, err := svc.calculateMyMetric()
if err != nil {
return errors.Trace(err)
}
err = svc.RecordMyMetric(ctx, v, "ok")
return errors.Trace(err)
Otherwise, call the recorder from the place in service.go where the event occurs.
svc.IncrementMyMetric(ctx, 1, "ok")
From the microservice's directory, run the generator. It regenerates intermediate.go (the recorder, the Describe* registration, and the observe dispatcher), mock.go, mock_test.go, and manifest.yaml from the updated definition.go. It also scaffolds a placeholder handler in service.go and a placeholder test in service_test.go for any new feature that lacks one, each ready for you to fill in.
go run github.com/microbus-io/fabric/cmd/genservice .
Then verify the microservice compiles with go vet ./... from the project root.
Skip this step if the metric is not observable just in time, or if instructed to be "quick" or to skip tests.
When present, the boilerplate generator created a placeholder test function TestMyService_OnObserveMyMetric in service_test.go, tagged with a // MARKER: MyMetric comment and a HINT block. Add one or more test cases at the bottom of that function, following the pattern shown in its HINT comment. Do not remove the HINT comment.
Follow the housekeeping skill.