-
Notifications
You must be signed in to change notification settings - Fork 94
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
base: main
Are you sure you want to change the base?
Call NewSpanExporter without checking OTLP_TRACES_EXPORTER environment variable #1572
Conversation
The committers listed above are authorized under a signed CLA. |
// a way to just pass the environment value currently. Just use | ||
// NewSpanExporter which will re-read this value. | ||
|
||
{ |
There was a problem hiding this comment.
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.
{ |
// 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") |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
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") |
There was a problem hiding this comment.
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.
Please be sure to include a changelog entry describing the fix being applied. |
Currently if
OTEL_TRACES_EXPORTER
is not defined, then the trace exporter is always set to HTTP, regardless of the value ofOTEL_EXPORTER_OTLP_PROTOCOL
. This is because there is a check to see ifOTEL_TRACES_EXPORTER
is set before callingautoexport.NewSpanExporter
.This change removes that check and adds a test to ensure that
autoexport.NewSpanExporter
still works withoutOTEL_TRACES_EXPORTER
defined. I have left the fallback code in place here so that ifOTEL_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).