Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call NewSpanExporter without checking OTLP_TRACES_EXPORTER environment variable #1572

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ManiaKazemzadeh
Copy link

Currently if OTEL_TRACES_EXPORTER is not defined, then the trace exporter is always set to HTTP, regardless of the value of OTEL_EXPORTER_OTLP_PROTOCOL. This is because there is a check to see if OTEL_TRACES_EXPORTER is set before calling autoexport.NewSpanExporter.

This change removes that check and adds a test to ensure that autoexport.NewSpanExporter still works without OTEL_TRACES_EXPORTER defined. I have left the fallback code in place here so that if OTEL_EXPORTER_OTLP_PROTOCOL has an invalid value (or NewSpanExporter returns nil for any other reason) the http exporter will be selected (which is the current behaviour).

Copy link

linux-foundation-easycla bot commented Jan 9, 2025

CLA Signed

  • ✅login: ManiaKazemzadeh / (f1cee98)

The committers listed above are authorized under a signed CLA.

@ManiaKazemzadeh ManiaKazemzadeh marked this pull request as ready for review January 9, 2025 19:43
@ManiaKazemzadeh ManiaKazemzadeh requested a review from a team as a code owner January 9, 2025 19:43
// a way to just pass the environment value currently. Just use
// NewSpanExporter which will re-read this value.

{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sub-scope is not needed here and only adds additional indentation.

Suggested change
{

// Test that autoexport.NewSpanExporter works when OTEL_TRACES_EXPORTER is
// not set
t.Run("With OTEL_TRACES_EXPORTER not set", func(t *testing.T) {
os.Unsetenv("OTEL_TRACES_EXPORTER")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to test when this is unset but OTEL_EXPORTER_OTLP_PROTOCOL is set.

Suggested change
os.Unsetenv("OTEL_TRACES_EXPORTER")
os.Unsetenv("OTEL_TRACES_EXPORTER")
t.Setenv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc")

c, err := newInstConfig(context.Background(), []InstrumentationOption{WithEnv()})

require.NoError(t, err)
assert.NotNil(t, c.traceExp)
Copy link
Contributor

@MrAlias MrAlias Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should validate the instance type to be and exporter from otlptracegrpc. Given the structure of those exporters, calling MarshalLog is likely your best option.

Suggested change
assert.NotNil(t, c.traceExp)
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")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be impacted by open-telemetry/opentelemetry-go#6143. We can follow up with that update later though.

@MrAlias
Copy link
Contributor

MrAlias commented Jan 9, 2025

Please be sure to include a changelog entry describing the fix being applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants