Skip to content

Commit d9cfd10

Browse files
authored
chore: pin instrumentation itself (#102)
* pin instrumentation itself * chore: fix test
1 parent ca5c49c commit d9cfd10

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

tool/preprocess/dependency.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,13 @@ func (dp *DepProcessor) setupDeps() error {
660660
return fmt.Errorf("failed to update otel: %w", err)
661661
}
662662

663-
// Befor generating compile commands, let's run go mod tidy first
663+
// Try to pin opentelemetry-go-auto-instrumentation itself
664+
tpe := dp.tryPinInstVersion()
665+
if tpe != nil {
666+
log.Printf("failed to pin opentelemetry-go-auto-instrumentation itself")
667+
}
668+
669+
// Before generating compile commands, let's run go mod tidy first
664670
// to fetch all dependencies
665671
err = runModTidy()
666672
if err != nil {

tool/preprocess/preprocess.go

+27-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package preprocess
1616

1717
import (
1818
"fmt"
19+
"github.com/alibaba/opentelemetry-go-auto-instrumentation/tool/version"
1920
"log"
2021
"os"
2122
"os/exec"
@@ -42,6 +43,10 @@ const (
4243

4344
const FixedOtelDepVersion = "v1.30.0"
4445

46+
const instDependency = "github.com/alibaba/opentelemetry-go-auto-instrumentation"
47+
48+
const OTEL_INST_VERSION = "OTEL_INST_VERSION"
49+
4550
var fixedOtelDeps = []string{
4651
"go.opentelemetry.io/otel",
4752
"go.opentelemetry.io/otel/sdk",
@@ -146,7 +151,7 @@ func (dp *DepProcessor) pinDepVersion() error {
146151

147152
// We want to fetch otel dependencies in a fixed version instead of the latest
148153
// version, so we need to pin the version in go.mod. All used otel dependencies
149-
// should be listed and pinned here, because go mod tidy will fetch the latest
154+
// should be listed and pinned here, because go mod tidy will fetch the latest
150155
// version even if we have pinned some of them.
151156
func (dp *DepProcessor) pinOtelVersion() error {
152157
for _, dep := range fixedOtelDeps {
@@ -159,6 +164,21 @@ func (dp *DepProcessor) pinOtelVersion() error {
159164
return nil
160165
}
161166

167+
// Users will import github.com/alibaba/opentelemetry-go-auto-instrumentation
168+
// dependency while using otelbuild to use the inst-api and inst-semconv package.
169+
// We need to pin the version to let the users use the fixed version
170+
func (dp *DepProcessor) tryPinInstVersion() error {
171+
instVersion := os.Getenv(OTEL_INST_VERSION)
172+
if instVersion == "" {
173+
instVersion = version.Tag
174+
}
175+
err := runGoGet(instDependency + "@" + instVersion)
176+
if err != nil {
177+
return fmt.Errorf("failed to pin %s %w", instDependency, err)
178+
}
179+
return nil
180+
}
181+
162182
func checkModularized() error {
163183
go11module := os.Getenv("GO111MODULE")
164184
if go11module == "off" {
@@ -221,7 +241,7 @@ func Preprocess() error {
221241
return fmt.Errorf("failed to update dependencies: %w", err)
222242
}
223243

224-
// Pinning otel version in go.mod
244+
// Pinning otel sdk dependencies version in go.mod
225245
err = dp.pinOtelVersion()
226246
if err != nil {
227247
return fmt.Errorf("failed to update otel: %w", err)
@@ -233,6 +253,11 @@ func Preprocess() error {
233253
return fmt.Errorf("failed to run mod tidy: %w", err)
234254
}
235255

256+
tpe := dp.tryPinInstVersion()
257+
if tpe != nil {
258+
log.Printf("failed to pin opentelemetry-go-auto-instrumentation itself")
259+
}
260+
236261
log.Printf("Preprocess took %v", time.Since(start))
237262
}
238263

tool/version/version.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 Alibaba Group Holding Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package version
16+
17+
// Tag specifies the current release tag. It needs to be manually updated.
18+
const Tag = "v0.2.0"

0 commit comments

Comments
 (0)