Skip to content

Commit

Permalink
Add Version func to otel/sdk (#3949)
Browse files Browse the repository at this point in the history
* Add Version func to otel/sdk

* Update sdk/resource to use sdk version

* Remove unused UserAgent from sdk/internal

* Add changes to changelog

* Update CHANGELOG.md

Co-authored-by: Robert Pająk <pellared@hotmail.com>

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
  • Loading branch information
MrAlias and pellared committed Mar 30, 2023
1 parent f4a9d78 commit 271df1d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- The `Version` function to `go.opentelemetry.io/otel/sdk` to return the SDK version. (#3949)

### Changed

- The `Extrema` in `go.opentelemetry.io/otel/sdk/metric/metricdata` is redefined with a generic argument of `[N int64 | float64]`. (#3870)
Expand All @@ -18,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- `TracerProvider` allows calling `Tracer()` while it's shutting down.
It used to deadlock. (#3924)
- Use the SDK version for the Telemetry SDK resource detector in `go.opentelemetry.io/otel/sdk/resource`. (#3949)

## [1.15.0-rc.2/0.38.0-rc.2] 2023-03-23

Expand Down
11 changes: 1 addition & 10 deletions sdk/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@

package internal // import "go.opentelemetry.io/otel/sdk/internal"

import (
"fmt"
"time"

"go.opentelemetry.io/otel"
)

// UserAgent is the user agent to be added to the outgoing
// requests from the exporters.
var UserAgent = fmt.Sprintf("opentelemetry-go/%s", otel.Version())
import "time"

// MonotonicEndTime returns the end time at present
// but offset from start, monotonically.
Expand Down
4 changes: 2 additions & 2 deletions sdk/resource/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"os"
"path/filepath"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func (telemetrySDK) Detect(context.Context) (*Resource, error) {
semconv.SchemaURL,
semconv.TelemetrySDKName("opentelemetry"),
semconv.TelemetrySDKLanguageGo,
semconv.TelemetrySDKVersion(otel.Version()),
semconv.TelemetrySDKVersion(sdk.Version()),
), nil
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/sdk"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestDefault(t *testing.T) {
"default service.name should include executable name")

require.Contains(t, res.Attributes(), semconv.TelemetrySDKLanguageGo)
require.Contains(t, res.Attributes(), semconv.TelemetrySDKVersion(otel.Version()))
require.Contains(t, res.Attributes(), semconv.TelemetrySDKVersion(sdk.Version()))
require.Contains(t, res.Attributes(), semconv.TelemetrySDKName("opentelemetry"))
}

Expand Down Expand Up @@ -370,7 +370,7 @@ func TestNew(t *testing.T) {
resourceValues: map[string]string{
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.language": "go",
"telemetry.sdk.version": otel.Version(),
"telemetry.sdk.version": sdk.Version(),
},
schemaURL: semconv.SchemaURL,
},
Expand Down
20 changes: 20 additions & 0 deletions sdk/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sdk // import "go.opentelemetry.io/otel/sdk"

// Version is the current release version of the OpenTelemetry SDK in use.
func Version() string {
return "1.15.0-rc.2"
}
34 changes: 34 additions & 0 deletions sdk/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sdk_test

import (
"regexp"
"testing"

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel"
)

// regex taken from https://github.com/Masterminds/semver/tree/v3.1.1
var versionRegex = regexp.MustCompile(`^v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?` +
`(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` +
`(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$`)

func TestVersionSemver(t *testing.T) {
v := otel.Version()
assert.NotNil(t, versionRegex.FindStringSubmatch(v), "version is not semver: %s", v)
}

0 comments on commit 271df1d

Please sign in to comment.