From 16d3a0aa3c22dfecdf76ba8be6a5def8ab0f9b81 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 29 Apr 2024 18:04:33 +0000 Subject: [PATCH] add experimental go runtime metrics semantic conventions --- .chloggen/go-runtime-metrics.yaml | 22 ++++ docs/runtime/README.md | 1 + docs/runtime/go-metrics.md | 173 ++++++++++++++++++++++++++++++ model/metrics/go-metrics.yaml | 88 +++++++++++++++ 4 files changed, 284 insertions(+) create mode 100644 .chloggen/go-runtime-metrics.yaml create mode 100644 docs/runtime/go-metrics.md create mode 100644 model/metrics/go-metrics.yaml diff --git a/.chloggen/go-runtime-metrics.yaml b/.chloggen/go-runtime-metrics.yaml new file mode 100644 index 000000000..72e6aafe9 --- /dev/null +++ b/.chloggen/go-runtime-metrics.yaml @@ -0,0 +1,22 @@ +# Use this changelog template to create an entry for release notes. +# +# If your change doesn't affect end users you should instead start +# your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: new_component + +# The name of the area of concern in the attributes-registry, (e.g. http, cloud, db) +component: go + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add new go namespace for Go runtime metrics + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +# The values here must be integers. +issues: [535] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/docs/runtime/README.md b/docs/runtime/README.md index 6285bc2c9..9762c5ba2 100644 --- a/docs/runtime/README.md +++ b/docs/runtime/README.md @@ -48,6 +48,7 @@ Also consider the semantic conventions when instrumenting runtime environments. - [JVM](jvm-metrics.md) +- [Go](go-metrics.md) ### Attributes diff --git a/docs/runtime/go-metrics.md b/docs/runtime/go-metrics.md new file mode 100644 index 000000000..ed01d5df3 --- /dev/null +++ b/docs/runtime/go-metrics.md @@ -0,0 +1,173 @@ + + +# Semantic Conventions for Go Runtime Metrics + +**Status**: [Experimental][DocumentStatus] + +This document describes semantic conventions for Go runtime metrics in OpenTelemetry. + + + + + +- [Go Memory](#go-memory) + - [Metric: `go.memory.used`](#metric-gomemoryused) + - [Metric: `go.memory.limit`](#metric-gomemorylimit) + - [Metric: `go.memory.allocated`](#metric-gomemoryallocated) + - [Metric: `go.memory.allocations`](#metric-gomemoryallocations) +- [Go Garbage Collection](#go-garbage-collection) + - [Metric: `go.memory.gc.target`](#metric-gomemorygctarget) + - [Metric: `go.memory.gc.user_target`](#metric-gomemorygcuser_target) +- [Go Threads](#go-threads) + - [Metric: `go.thread.limit`](#metric-gothreadlimit) +- [Go Scheduler](#go-scheduler) + - [Metric: `go.schedule.duration`](#metric-goscheduleduration) + + + +## Go Memory + +**Description:** Go runtime metrics captured under the namespace `go.memory.*` + +### Metric: `go.memory.used` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package using `/memory/classes` metrics. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.memory.used` | UpDownCounter | `By` | Virtual memory mapped by the Go runtime. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + +| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability | +|---|---|---|---|---|---| +| `go.memory.type` | string | The type of memory. | `released`; `stack` | `Recommended` | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + +`go.memory.type` MUST be one of the following: + +| Value | Description | Stability | +|---|---|---| +| `released` | Memory that is completely free and has been returned to the underlying system. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | +| `stack` | Memory allocated from the heap that is reserved for stack space, whether or not it is currently in-use. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | +| `other` | All memory mapped by the Go runtime into the current process as read-write, excluding other categories of memory usage. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + +### Metric: `go.memory.limit` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package using `/gc/gomemlimit:bytes`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.memory.limit` | UpDownCounter | `By` | Go runtime memory limit configured by the user, otherwise math.MaxInt64. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + + + +### Metric: `go.memory.allocated` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package using `/gc/heap/allocs:bytes`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.memory.allocated` | Counter | `By` | Memory allocated to the heap by the application. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + + + +### Metric: `go.memory.allocations` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package using `/gc/heap/allocs:objects`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.memory.allocations` | Counter | `{allocation}` | Count of allocations to the heap by the application. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + + + +## Go Garbage Collection + +**Description:** Go metrics captured under the namespace `go.memory.gc.*` + +### Metric: `go.memory.gc.target` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package using `/gc/heap/goal:bytes`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.memory.gc.target` | UpDownCounter | `By` | Heap size target for the end of the GC cycle. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + + + +### Metric: `go.memory.gc.user_target` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package using `/gc/gogc:percent`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.memory.gc.user_target` | UpDownCounter | `1` | Heap size target ratio for the end of the GC cycle, as configured by the user. [1] | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + +**[1]:** The value range is [0.0,1.0]. + + + + + +## Go Threads + +**Description:** Go metrics captured under the namespace `go.thread.*` + +### Metric: `go.thread.limit` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package `/sched/gomaxprocs:threads`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.thread.limit` | UpDownCounter | `{thread}` | The number of OS threads that can execute user-level Go code simultaneously. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + + + +## Go Scheduler + +**Description:** Go metrics captured under the namespace `go.schedule.*` + +### Metric: `go.schedule.duration` + +This metric is [recommended][MetricRecommended]. +This metric is obtained from Go's [`runtime/metrics`][RuntimeMetrics] package `/sched/latencies:seconds`. + + +| Name | Instrument Type | Unit (UCUM) | Description | Stability | +| -------- | --------------- | ----------- | -------------- | --------- | +| `go.schedule.duration` | Histogram | `s` | The time goroutines have spent in the scheduler in a runnable state before actually running. | ![Experimental](https://img.shields.io/badge/-experimental-blue) | + + + + + +[DocumentStatus]: https://github.com/open-telemetry/opentelemetry-specification/tree/v1.31.0/specification/document-status.md +[MetricRecommended]: /docs/general/metric-requirement-level.md#recommended +[RuntimeMetrics]: https://pkg.go.dev/runtime/metrics diff --git a/model/metrics/go-metrics.yaml b/model/metrics/go-metrics.yaml new file mode 100644 index 000000000..9e3dcc076 --- /dev/null +++ b/model/metrics/go-metrics.yaml @@ -0,0 +1,88 @@ +groups: + - id: metric.go.memory.used + type: metric + metric_name: go.memory.used + brief: "Virtual memory mapped by the Go runtime." + instrument: updowncounter + prefix: go.memory + unit: "By" + attributes: + - id: type + stability: experimental + type: + allow_custom_values: false + members: + - id: released + value: 'released' + brief: 'Memory that is completely free and has been returned to the underlying system.' + stability: experimental + - id: stack + value: 'stack' + brief: 'Memory allocated from the heap that is reserved for stack space, whether or not it is currently in-use.' + stability: experimental + - id: other + value: 'other' + brief: 'All memory mapped by the Go runtime into the current process as read-write, excluding other categories of memory usage.' + stability: experimental + requirement_level: recommended + brief: The type of memory. + examples: ["released", "stack"] + stability: experimental + + - id: metric.go.memory.limit + type: metric + metric_name: go.memory.limit + brief: "Go runtime memory limit configured by the user, otherwise math.MaxInt64." + instrument: updowncounter + unit: "By" + stability: experimental + + - id: metric.go.memory.allocated + type: metric + metric_name: go.memory.allocated + brief: "Memory allocated to the heap by the application." + instrument: counter + unit: "By" + stability: experimental + + - id: metric.go.memory.allocations + type: metric + metric_name: go.memory.allocations + brief: "Count of allocations to the heap by the application." + instrument: counter + unit: "{allocation}" + stability: experimental + + - id: metric.go.memory.gc.target + type: metric + metric_name: go.memory.gc.target + brief: "Heap size target for the end of the GC cycle." + instrument: updowncounter + unit: "By" + stability: experimental + + - id: metric.go.memory.gc.user_target + type: metric + metric_name: go.memory.gc.user_target + brief: "Heap size target ratio for the end of the GC cycle, as configured by the user." + instrument: updowncounter + unit: "1" + note: > + The value range is [0.0,1.0]. + stability: experimental + + - id: metric.go.thread.limit + type: metric + metric_name: go.thread.limit + brief: "The number of OS threads that can execute user-level Go code simultaneously." + instrument: updowncounter + unit: "{thread}" + stability: experimental + + - id: metric.go.schedule.duration + type: metric + metric_name: go.schedule.duration + brief: "The time goroutines have spent in the scheduler in a runnable state before actually running." + instrument: histogram + unit: "s" + stability: experimental