Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
### Added

- Cache offsets for `google.golang.org/grpc` `1.72.0-dev`. ([#1849](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1849))
- The `go.opentelemtry.io/auto/pipeline` package is added.
This package contains interface definitions for types that want to handle the telemetry generated by auto-instrumentation. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The `go.opentelemtry.io/auto/pipeline/otelsdk` package is added.
This package a default handler that uses the OpenTelemetry Go SDK to handle telemetry generated by auto-instrumentation. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The `WithHandler` function is added to configure `Instrumentation` in `go.opentelemtry.io/auto` with the desired handler implementation. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The auto binary (built from `auto/cli`) can now be passed the target process PID directly using the `-target-pid` CLI option. ([#1890](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1890))
- The auto binary (built from `auto/cli`) can now be passed the path of the target process executable directly using the `-target-exe` CLI option. ([#1890](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1890))
- The auto binary (built from `auto/cli`) now resolves the target PID from the environment variable `"OTEL_GO_AUTO_TARGET_PID"` if no target options are passed. ([#1890](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1890))
Expand All @@ -30,12 +35,24 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

### Changed

- The `WithEnv` function no longer parses `OTEL_GO_AUTO_GLOBAL`.
This is included by default. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The `WithEnv` function no longer parses `OTEL_SERVICE_NAME` or `OTEL_TRACES_EXPORTER`.
Use the `Handler` from `go.opentelemtry.io/auto/pipeline/otelsdk` with its own `WithEnv` to replace functionality. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- Upgrade OpenTelemetry semantic conventions to `v1.30.0`. ([#2032](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/2032))

### Removed

- Build support for Go 1.22 has been removed.
Use Go >= 1.23 to develop and build the project. ([#1841](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1841))
- The `WithGlobal` function is removed from `go.opentelemtry.io/auto`
This option is on by default. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The `WithServiceName` function is removed from `go.opentelemtry.io/auto`
Use `WithServiceName` in `go.opentelemtry.io/auto/pipeline/otelsdk` along with `WithHandler` to replace functionality. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The `WithTraceExporter` function is removed from `go.opentelemtry.io/auto`
Use `WithTraceExporter` in `go.opentelemtry.io/auto/pipeline/otelsdk` along with `WithHandler` to replace functionality. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- The `WithResourceAttributes` function is removed from `go.opentelemtry.io/auto`
Use `WithResourceAttributes` in `go.opentelemtry.io/auto/pipeline/otelsdk` along with `WithHandler` to replace functionality. ([#1859](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1859))
- Resolution of the environment variable `"OTEL_GO_AUTO_TARGET_EXE"` has been removed from `WithEnv`.
Note, the built binary (`auto/cli`) still supports resolution and use of this value.
If using the `auto` package directly, you will need to resolve this value yourself and pass the discovered process PID using `WithPID`. ([#1890](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1890))
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# directories
!/cli
!/sdk
!/internal/include
!/internal/pkg
!/pipeline
!/sdk
87 changes: 72 additions & 15 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"context"
"debug/buildinfo"
"flag"
"fmt"
"log/slog"
Expand All @@ -16,7 +17,12 @@ import (
"strconv"
"syscall"

"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.30.0"

"go.opentelemetry.io/auto"
"go.opentelemetry.io/auto/pipeline"
"go.opentelemetry.io/auto/pipeline/otelsdk"
)

const help = `Usage of %s:
Expand Down Expand Up @@ -94,17 +100,10 @@ func newLogger(lvlStr string) *slog.Logger {
}

func main() {
var globalImpl bool
var logLevel string
var targetPID int
var targetExe string

flag.BoolVar(
&globalImpl,
"global-impl",
false,
"Record telemetry from the OpenTelemetry default global implementation",
)
flag.StringVar(&logLevel, "log-level", "", `Logging level ("debug", "info", "warn", "error")`)
flag.IntVar(&targetPID, "target-pid", -1, `PID of target process`)
flag.StringVar(&targetExe, "target-exe", "", `Executable path run by the target process`)
Expand All @@ -130,23 +129,37 @@ func main() {
}
}()

instOptions := []auto.InstrumentationOption{
auto.WithEnv(),
auto.WithLogger(logger),
}
if globalImpl {
instOptions = append(instOptions, auto.WithGlobal())
}
pid, err := findPID(ctx, logger, targetPID, targetExe)
if err != nil {
logger.Error("failed to find target", "error", err)
return
}

logger.Info(
"building OpenTelemetry Go instrumentation ...",
"version", newVersion(),
)

h, err := otelsdk.NewTraceHandler(
ctx,
otelsdk.WithEnv(),
otelsdk.WithLogger(logger),
otelsdk.WithResourceAttributes(resourceAttrs(logger, pid)...),
)
if err != nil {
logger.Error("failed to create OTel SDK handler", "error", err)
return
}

instOptions := []auto.InstrumentationOption{
auto.WithEnv(),
auto.WithLogger(logger),
auto.WithHandler(&pipeline.Handler{TraceHandler: h}),
}
instOptions = append(instOptions, auto.WithPID(pid))

logger.Info(
"building OpenTelemetry Go instrumentation ...",
"globalImpl", globalImpl,
"PID", pid,
"version", newVersion(),
)
Expand All @@ -168,6 +181,16 @@ func main() {
if err = inst.Run(ctx); err != nil {
logger.Error("instrumentation crashed", "error", err)
}

logger.Info("shutting down")

ctx, cancel = signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()

err = h.Shutdown(ctx)
if err != nil {
logger.Error("failed to flush handler", "error", err)
}
}

var errNoPID = fmt.Errorf(
Expand Down Expand Up @@ -222,3 +245,37 @@ func findExe(ctx context.Context, l *slog.Logger, exe string) (int, error) {
pp := ProcessPoller{Logger: l, BinPath: exe}
return pp.Poll(ctx)
}

func resourceAttrs(logger *slog.Logger, pid int) []attribute.KeyValue {
attrs := []attribute.KeyValue{
semconv.TelemetryDistroVersionKey.String(auto.Version()),
}

// Add additional process information for the target.
path := "/proc/" + strconv.Itoa(pid) + "/exe"
bi, err := buildinfo.ReadFile(path)
if err != nil {
logger.Error("failed to get Go proc build info", "error", err)
return attrs
}

attrs = append(attrs, semconv.ProcessRuntimeVersion(bi.GoVersion))

var compiler string
for _, setting := range bi.Settings {
if setting.Key == "-compiler" {
compiler = setting.Value
break
}
}
switch compiler {
case "":
logger.Debug("failed to identify Go compiler")
case "gc":
attrs = append(attrs, semconv.ProcessRuntimeName("go"))
default:
attrs = append(attrs, semconv.ProcessRuntimeName(compiler))
}

return attrs
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ retract (
require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/cilium/ebpf v0.18.0
github.com/go-logr/stdr v1.2.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.10.0
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
go.opentelemetry.io/collector/pdata v1.29.0
go.opentelemetry.io/contrib/exporters/autoexport v0.60.0
go.opentelemetry.io/otel v1.35.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0
go.opentelemetry.io/otel/sdk v1.35.0
go.opentelemetry.io/otel/trace v1.35.0
Expand All @@ -44,6 +42,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
Expand All @@ -62,6 +61,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.11.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.57.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.11.0 // indirect
Expand Down
Loading
Loading