Skip to content

Commit

Permalink
chore: pin instrumentation itself (#102)
Browse files Browse the repository at this point in the history
* pin instrumentation itself

* chore: fix test
  • Loading branch information
123liuziming authored Sep 28, 2024
1 parent ca5c49c commit d9cfd10
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tool/preprocess/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,13 @@ func (dp *DepProcessor) setupDeps() error {
return fmt.Errorf("failed to update otel: %w", err)
}

// Befor generating compile commands, let's run go mod tidy first
// Try to pin opentelemetry-go-auto-instrumentation itself
tpe := dp.tryPinInstVersion()
if tpe != nil {
log.Printf("failed to pin opentelemetry-go-auto-instrumentation itself")
}

// Before generating compile commands, let's run go mod tidy first
// to fetch all dependencies
err = runModTidy()
if err != nil {
Expand Down
29 changes: 27 additions & 2 deletions tool/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package preprocess

import (
"fmt"
"github.com/alibaba/opentelemetry-go-auto-instrumentation/tool/version"
"log"
"os"
"os/exec"
Expand All @@ -42,6 +43,10 @@ const (

const FixedOtelDepVersion = "v1.30.0"

const instDependency = "github.com/alibaba/opentelemetry-go-auto-instrumentation"

const OTEL_INST_VERSION = "OTEL_INST_VERSION"

var fixedOtelDeps = []string{
"go.opentelemetry.io/otel",
"go.opentelemetry.io/otel/sdk",
Expand Down Expand Up @@ -146,7 +151,7 @@ func (dp *DepProcessor) pinDepVersion() error {

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

// Users will import github.com/alibaba/opentelemetry-go-auto-instrumentation
// dependency while using otelbuild to use the inst-api and inst-semconv package.
// We need to pin the version to let the users use the fixed version
func (dp *DepProcessor) tryPinInstVersion() error {
instVersion := os.Getenv(OTEL_INST_VERSION)
if instVersion == "" {
instVersion = version.Tag
}
err := runGoGet(instDependency + "@" + instVersion)
if err != nil {
return fmt.Errorf("failed to pin %s %w", instDependency, err)
}
return nil
}

func checkModularized() error {
go11module := os.Getenv("GO111MODULE")
if go11module == "off" {
Expand Down Expand Up @@ -221,7 +241,7 @@ func Preprocess() error {
return fmt.Errorf("failed to update dependencies: %w", err)
}

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

tpe := dp.tryPinInstVersion()
if tpe != nil {
log.Printf("failed to pin opentelemetry-go-auto-instrumentation itself")
}

log.Printf("Preprocess took %v", time.Since(start))
}

Expand Down
18 changes: 18 additions & 0 deletions tool/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024 Alibaba Group Holding Ltd.
//
// 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 version

// Tag specifies the current release tag. It needs to be manually updated.
const Tag = "v0.2.0"

0 comments on commit d9cfd10

Please sign in to comment.