Skip to content

Commit

Permalink
Call NewSpanExporter without checking OTLP_TRACES_EXPORTER environmen…
Browse files Browse the repository at this point in the history
…t variable (#1572)

* Call NewSpanExporter without checking OTLP_TRACES_EXPORTER environment variable

* Address comments and add changelog

---------

Co-authored-by: Tyler Yahn <[email protected]>
  • Loading branch information
ManiaKazemzadeh and MrAlias authored Jan 10, 2025
1 parent 70a9938 commit e6f3f3c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
## [Unreleased]

### Added

- Update `httpPlusdb` demo with adding `OTEL_GO_AUTO_PARSE_DB_STATEMENT` env variable ([#1523](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1523))
- Support `SELECT`, `INSERT`, `UPDATE`, and `DELETE` for database span names and `db.operation.name` attribute. ([#1253](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1253))
- Support the full tracing API with the `otelglobal` probe. ([#1405](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1405))
Expand All @@ -27,6 +28,10 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

- Preemptively drop support for the `traceglobal` probe when `Go >= 1.24` is used. ([#1573](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1573))

### Fixed

- Respect `OTEL_EXPORTER_OTLP_PROTOCOL` when `OTEL_TRACES_EXPORTER` is not set. ([#1572](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1572))

## [v0.19.0-alpha] - 2024-12-05

### Added
Expand Down Expand Up @@ -70,7 +75,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

- The deprecated `go.opentelemetry.io/auto/sdk/telemetry` package is removed. ([#1252](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1252))
- The deprecated `go.opentelemetry.io/auto/sdk/telemetry/test` module is removed. ([#1252](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1252))
- Remove the `WithLoadedIndicator` `InstrumentationOption` since the `Instrumentation.Load` will indicate whether the probes are loaded in a synchronous way. ([#1245](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1245))
- Remove the `WithLoadedIndicator` `InstrumentationOption` since the `Instrumentation.Load` will indicate whether the probes are loaded in a synchronous way. ([#1245](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1245))

## [v0.17.0-alpha] - 2024-11-05

Expand Down Expand Up @@ -118,7 +123,7 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
- Support Go `v1.22.6`. ([#988](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/988))
- Support `golang.org/x/net` `v0.28.0`. ([#988](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/988))
- Support `google.golang.org/grpc` `1.67.0-dev`. ([#1007](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1007))
- Support Go `1.23.0`. ([#1007](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1007))
- Support Go `1.23.0`. ([#1007](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1007))
- Introduce `config.Provider` as an option to set the initial configuration and update it in runtime. ([#1010](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1010))
- Support `go.opentelemetry.io/[email protected]`. ([#1032](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1032))
- Support `google.golang.org/grpc` `1.66.0`. ([#1046](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1046))
Expand Down Expand Up @@ -556,5 +561,4 @@ This is the first release of OpenTelemetry Go Automatic Instrumentation.
[v0.2.1-alpha]: https://github.com/open-telemetry/opentelemetry-go-instrumentation/releases/tag/v0.2.1-alpha
[v0.2.0-alpha]: https://github.com/open-telemetry/opentelemetry-go-instrumentation/releases/tag/v0.2.0-alpha
[v0.1.0-alpha]: https://github.com/open-telemetry/opentelemetry-go-instrumentation/releases/tag/v0.1.0-alpha

[Go 1.22]: https://go.dev/doc/go1.22
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ retract (

require (
github.com/cilium/ebpf v0.17.1
github.com/go-logr/stdr v1.2.2
github.com/hashicorp/go-version v1.7.0
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.23.0
go.opentelemetry.io/contrib/exporters/autoexport v0.58.0
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0
go.opentelemetry.io/otel/sdk v1.33.0
go.opentelemetry.io/otel/trace v1.33.0
Expand All @@ -41,7 +43,6 @@ 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.25.1 // indirect
Expand All @@ -61,7 +62,6 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.55.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.9.0 // indirect
Expand Down
20 changes: 7 additions & 13 deletions instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ const (
// envResourceAttrKey is the key for the environment variable value containing
// OpenTelemetry Resource attributes.
envResourceAttrKey = "OTEL_RESOURCE_ATTRIBUTES"
// envTracesExportersKey is the key for the environment variable value
// containing what OpenTelemetry trace exporter to use.
envTracesExportersKey = "OTEL_TRACES_EXPORTER"
// envOtelGlobalImplKey is the key for the environment variable value enabling to opt-in for the
// OpenTelemetry global implementation. It should be a boolean value.
envOtelGlobalImplKey = "OTEL_GO_AUTO_GLOBAL"
Expand Down Expand Up @@ -408,17 +405,14 @@ func WithEnv() InstrumentationOption {
if v, ok := lookupEnv(envTargetExeKey); ok {
c.target = process.TargetArgs{ExePath: v}
}
if _, ok := lookupEnv(envTracesExportersKey); ok {
// Don't track the lookup value because autoexport does not provide
// a way to just pass the environment value currently. Just use
// NewSpanExporter which will re-read this value.

var e error
// NewSpanExporter will use an OTLP (HTTP/protobuf) exporter as the
// default. This is the OTel recommended default.
c.traceExp, e = autoexport.NewSpanExporter(ctx)
err = errors.Join(err, e)
}
var e error
// NewSpanExporter will use an OTLP (HTTP/protobuf) exporter as the
// default, unless OTLP_TRACES_EXPORTER is set. This is the OTel
// recommended default.
c.traceExp, e = autoexport.NewSpanExporter(ctx)
err = errors.Join(err, e)

if name, attrs, ok := lookupResourceData(); ok {
c.serviceName = name
c.additionalResAttrs = append(c.additionalResAttrs, attrs...)
Expand Down
26 changes: 26 additions & 0 deletions instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
package auto

import (
"bytes"
"context"
"fmt"
"io"
"log"
"log/slog"
"os"
"testing"

"github.com/go-logr/stdr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"

"go.opentelemetry.io/auto/internal/pkg/instrumentation/probe/sampling"
Expand Down Expand Up @@ -95,6 +101,26 @@ func TestWithEnv(t *testing.T) {
_, err = newInstConfig(ctx, opts)
require.ErrorContains(t, err, `parse log level "invalid"`)
})

// Test that autoexport.NewSpanExporter works when OTEL_TRACES_EXPORTER is
// not set and OTEL_EXPORTER_OTLP_PROTOCOL is set to 'grpc'
t.Run("With OTEL_TRACES_EXPORTER not set", func(t *testing.T) {
os.Unsetenv("OTEL_TRACES_EXPORTER")
t.Setenv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc")
c, err := newInstConfig(context.Background(), []InstrumentationOption{WithEnv()})

require.NoError(t, err)
require.NotNil(t, c.traceExp)
require.IsType(t, &otlptrace.Exporter{}, c.traceExp)
exp := c.traceExp.(*otlptrace.Exporter)
var buf bytes.Buffer
logger := stdr.New(log.New(&buf, "", log.LstdFlags))
logger.Info("", "exporter", exp)
got, err := io.ReadAll(&buf)
require.NoError(t, err)
// "otlphttphttp" should be "otlptracegrpc". This is a bug upstream.
assert.Contains(t, string(got), "otlphttpgrpc")
})
}

func TestOptionPrecedence(t *testing.T) {
Expand Down

0 comments on commit e6f3f3c

Please sign in to comment.