diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c74566bd0..83a3512d30f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed +- `go.opentelemetry.io/contrib/instrumentation/runtime` now produces the new metrics by default. Set `OTEL_GO_X_DEPRECATED_RUNTIME_METRICS=true` environment variable to additionally produce the deprecated metrics. (#7418) - The semantic conventions have been upgraded from `v1.30.0` to `v1.32.0` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#7361) - The semantic conventions have been upgraded from `v1.26.0` to `v1.32.0` in `go.opentelemetry.io/contrib/detectors/aws/ec2`. (#7373) - The semantic conventions have been upgraded from `v1.26.0` to `v1.32.0` in `go.opentelemetry.io/contrib/detectors/aws/eks`. (#7375) diff --git a/instrumentation/runtime/doc.go b/instrumentation/runtime/doc.go index 2b5e78686d4..fabf952c46d 100644 --- a/instrumentation/runtime/doc.go +++ b/instrumentation/runtime/doc.go @@ -5,6 +5,18 @@ // // The metric events produced are: // +// go.memory.used By Memory used by the Go runtime. +// go.memory.limit By Go runtime memory limit configured by the user, if a limit exists. +// go.memory.allocated By Memory allocated to the heap by the application. +// go.memory.allocations {allocation} Count of allocations to the heap by the application. +// go.memory.gc.goal By Heap size target for the end of the GC cycle. +// go.goroutine.count {goroutine} Count of live goroutines. +// go.processor.limit {thread} The number of OS threads that can execute user-level Go code simultaneously. +// go.config.gogc % Heap size target percentage configured by the user, otherwise 100. +// +// When the OTEL_GO_X_DEPRECATED_RUNTIME_METRICS environment variable is set to +// true, the following deprecated metrics are produced: +// // runtime.go.cgo.calls - Number of cgo calls made by the current process // runtime.go.gc.count - Number of completed garbage collection cycles // runtime.go.gc.pause_ns (ns) Amount of nanoseconds in GC stop-the-world pauses @@ -19,16 +31,4 @@ // runtime.go.mem.heap_sys (bytes) Bytes of heap memory obtained from the OS // runtime.go.mem.live_objects - Number of live objects is the number of cumulative Mallocs - Frees // runtime.uptime (ms) Milliseconds since application was initialized -// -// When the OTEL_GO_X_DEPRECATED_RUNTIME_METRICS environment variable is set to -// false, the metrics produced are: -// -// go.memory.used By Memory used by the Go runtime. -// go.memory.limit By Go runtime memory limit configured by the user, if a limit exists. -// go.memory.allocated By Memory allocated to the heap by the application. -// go.memory.allocations {allocation} Count of allocations to the heap by the application. -// go.memory.gc.goal By Heap size target for the end of the GC cycle. -// go.goroutine.count {goroutine} Count of live goroutines. -// go.processor.limit {thread} The number of OS threads that can execute user-level Go code simultaneously. -// go.config.gogc % Heap size target percentage configured by the user, otherwise 100. package runtime // import "go.opentelemetry.io/contrib/instrumentation/runtime" diff --git a/instrumentation/runtime/internal/x/README.md b/instrumentation/runtime/internal/x/README.md index a2367651a09..00170e1a687 100644 --- a/instrumentation/runtime/internal/x/README.md +++ b/instrumentation/runtime/internal/x/README.md @@ -13,22 +13,13 @@ change in backwards incompatible ways as feedback is applied. ### Include Deprecated Metrics -Once new experimental runtime metrics are added, they will be produced -**in addition to** the existing runtime metrics. Users that migrate right away -can disable the old runtime metrics: - -```console -export OTEL_GO_X_DEPRECATED_RUNTIME_METRICS=false -``` - -In a later release, the deprecated runtime metrics will stop being produced by -default. To temporarily re-enable the deprecated metrics: +To temporarily re-enable the deprecated metrics: ```console export OTEL_GO_X_DEPRECATED_RUNTIME_METRICS=true ``` -After two additional releases, the deprecated runtime metrics will be removed, +Eventually, the deprecated runtime metrics will be removed, and setting the environment variable will no longer have any effect. The value set must be the case-insensitive string of `"true"` to enable the diff --git a/instrumentation/runtime/internal/x/x.go b/instrumentation/runtime/internal/x/x.go index 7ffb473adc3..95a05d5993e 100644 --- a/instrumentation/runtime/internal/x/x.go +++ b/instrumentation/runtime/internal/x/x.go @@ -9,17 +9,17 @@ package x // import "go.opentelemetry.io/contrib/instrumentation/runtime/interna import ( "os" - "strings" + "strconv" ) // DeprecatedRuntimeMetrics is an experimental feature flag that defines if the deprecated // runtime metrics should be produced. During development of the new // conventions, it is enabled by default. // -// To disable this feature set the OTEL_GO_X_DEPRECATED_RUNTIME_METRICS environment variable -// to the case-insensitive string value of "false" (i.e. "False" and "FALSE" +// To enable this feature set the OTEL_GO_X_DEPRECATED_RUNTIME_METRICS environment variable +// to the case-insensitive string value of "true" (i.e. "True" and "TRUE" // will also enable this). -var DeprecatedRuntimeMetrics = newFeature("DEPRECATED_RUNTIME_METRICS", true) +var DeprecatedRuntimeMetrics = newFeature("DEPRECATED_RUNTIME_METRICS", false) // BoolFeature is an experimental feature control flag. It provides a uniform way // to interact with these feature flags and parse their values. @@ -43,11 +43,11 @@ func (f BoolFeature) Key() string { return f.key } // Enabled returns if the feature is enabled. func (f BoolFeature) Enabled() bool { v := os.Getenv(f.key) - if strings.ToLower(v) == "false" { - return false - } - if strings.ToLower(v) == "true" { - return true + + val, err := strconv.ParseBool(v) + if err != nil { + return f.defaultVal } - return f.defaultVal + + return val } diff --git a/instrumentation/runtime/internal/x/x_test.go b/instrumentation/runtime/internal/x/x_test.go index fac942514ff..0667a775c81 100644 --- a/instrumentation/runtime/internal/x/x_test.go +++ b/instrumentation/runtime/internal/x/x_test.go @@ -21,7 +21,7 @@ func TestDeprecatedRuntimeMetrics(t *testing.T) { t.Run("False", run(setenv(key, "False"), assertEnabled(DeprecatedRuntimeMetrics, false))) t.Run("FALSE", run(setenv(key, "FALSE"), assertEnabled(DeprecatedRuntimeMetrics, false))) t.Run("1", run(setenv(key, "1"), assertEnabled(DeprecatedRuntimeMetrics, true))) - t.Run("empty", run(assertEnabled(DeprecatedRuntimeMetrics, true))) + t.Run("empty", run(assertEnabled(DeprecatedRuntimeMetrics, false))) } func run(steps ...func(*testing.T)) func(*testing.T) { diff --git a/instrumentation/runtime/runtime.go b/instrumentation/runtime/runtime.go index e1e25be4b75..fec833b573e 100644 --- a/instrumentation/runtime/runtime.go +++ b/instrumentation/runtime/runtime.go @@ -44,7 +44,9 @@ func Start(opts ...Option) error { metric.WithInstrumentationVersion(Version()), ) if x.DeprecatedRuntimeMetrics.Enabled() { - return deprecatedruntime.Start(meter, c.MinimumReadMemStatsInterval) + if err := deprecatedruntime.Start(meter, c.MinimumReadMemStatsInterval); err != nil { + return err + } } memoryUsed, err := goconv.NewMemoryUsed(meter) if err != nil { diff --git a/instrumentation/runtime/runtime_test.go b/instrumentation/runtime/runtime_test.go index 131a54118ce..64c653162e8 100644 --- a/instrumentation/runtime/runtime_test.go +++ b/instrumentation/runtime/runtime_test.go @@ -63,7 +63,6 @@ func TestRuntimeWithLimit(t *testing.T) { // buffer for allocating memory var buffer [][]byte _ = allocateMemory(buffer) - t.Setenv("OTEL_GO_X_DEPRECATED_RUNTIME_METRICS", "false") debug.SetMemoryLimit(1234567890) // reset to default defer debug.SetMemoryLimit(math.MaxInt64)