diff --git a/CHANGELOG.md b/CHANGELOG.md index 605d7dba8f6..5be45fe010e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed +- Change `Version()` function in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` to a `const Version` string. (#8142) - Improve performance by reducing allocations in the gRPC stats handler in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#8035) ### Deprecated diff --git a/instrumentation/net/http/otelhttp/common.go b/instrumentation/net/http/otelhttp/common.go index a83a026274a..3ae08243441 100644 --- a/instrumentation/net/http/otelhttp/common.go +++ b/instrumentation/net/http/otelhttp/common.go @@ -23,5 +23,5 @@ const ( type Filter func(*http.Request) bool func newTracer(tp trace.TracerProvider) trace.Tracer { - return tp.Tracer(ScopeName, trace.WithInstrumentationVersion(Version())) + return tp.Tracer(ScopeName, trace.WithInstrumentationVersion(Version)) } diff --git a/instrumentation/net/http/otelhttp/config.go b/instrumentation/net/http/otelhttp/config.go index 6107728d412..46b2054cf0a 100644 --- a/instrumentation/net/http/otelhttp/config.go +++ b/instrumentation/net/http/otelhttp/config.go @@ -66,7 +66,7 @@ func newConfig(opts ...Option) *config { c.Meter = c.MeterProvider.Meter( ScopeName, - metric.WithInstrumentationVersion(Version()), + metric.WithInstrumentationVersion(Version), ) return c diff --git a/instrumentation/net/http/otelhttp/handler_test.go b/instrumentation/net/http/otelhttp/handler_test.go index 30d1272d215..07649df8251 100644 --- a/instrumentation/net/http/otelhttp/handler_test.go +++ b/instrumentation/net/http/otelhttp/handler_test.go @@ -174,7 +174,7 @@ func TestHandlerBasics(t *testing.T) { func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, attrs attribute.Set) { assert.Equal(t, instrumentation.Scope{ Name: "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp", - Version: Version(), + Version: Version, }, sm.Scope) require.Len(t, sm.Metrics, 3) @@ -182,7 +182,7 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, attrs attribut want := metricdata.ScopeMetrics{ Scope: instrumentation.Scope{ Name: ScopeName, - Version: Version(), + Version: Version, }, Metrics: []metricdata.Metrics{ { diff --git a/instrumentation/net/http/otelhttp/transport_test.go b/instrumentation/net/http/otelhttp/transport_test.go index dd7c66f402a..d4d20b2bfa5 100644 --- a/instrumentation/net/http/otelhttp/transport_test.go +++ b/instrumentation/net/http/otelhttp/transport_test.go @@ -860,7 +860,7 @@ func TestTransportMetrics(t *testing.T) { func assertClientScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, attrs attribute.Set) { assert.Equal(t, instrumentation.Scope{ Name: "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp", - Version: Version(), + Version: Version, }, sm.Scope) require.Len(t, sm.Metrics, 2) @@ -868,7 +868,7 @@ func assertClientScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, attrs at want := metricdata.ScopeMetrics{ Scope: instrumentation.Scope{ Name: ScopeName, - Version: Version(), + Version: Version, }, Metrics: []metricdata.Metrics{ { diff --git a/instrumentation/net/http/otelhttp/version.go b/instrumentation/net/http/otelhttp/version.go index dfb53cf1f3a..c1b804a505a 100644 --- a/instrumentation/net/http/otelhttp/version.go +++ b/instrumentation/net/http/otelhttp/version.go @@ -4,7 +4,4 @@ package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" // Version is the current release version of the otelhttp instrumentation. -func Version() string { - return "0.63.0" - // This string is updated by the pre_release.sh script during release -} +const Version = "0.63.0" diff --git a/instrumentation/net/http/otelhttp/version_test.go b/instrumentation/net/http/otelhttp/version_test.go index d030fa16194..d51441178b0 100644 --- a/instrumentation/net/http/otelhttp/version_test.go +++ b/instrumentation/net/http/otelhttp/version_test.go @@ -19,6 +19,6 @@ var versionRegex = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) `(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`) func TestVersionSemver(t *testing.T) { - v := otelhttp.Version() + v := otelhttp.Version assert.NotNil(t, versionRegex.FindStringSubmatch(v), "version is not semver: %s", v) }