Skip to content

Commit e43d9c0

Browse files
Sai NadendlaAneurysm9
Sai Nadendla
andauthored
Update Default Value for Jaeger Exporter Endpoint (open-telemetry#1824)
* Update Default Value for OTEL_EXPORTER_JAEGER_ENDPOINT Env Var * update comments * fix documentation * update CHANGELOG * add missing tab * fix lint issue Co-authored-by: Anthony Mirabella <[email protected]>
1 parent 0032bd6 commit e43d9c0

File tree

6 files changed

+101
-99
lines changed

6 files changed

+101
-99
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
5252

5353
### Changed
5454

55+
- Updated Jaeger Environment Variable: `OTEL_EXPORTER_JAEGER_ENDPOINT` to have a default value of
56+
`http://localhost:14250` when not set, in compliance with OTel spec. Changed the function `WithCollectorEndpoint`
57+
in the Jaeger exporter package to no longer accept an endpoint as an argument.
58+
The endpoint can be passed in as a `CollectorEndpointOption` using the `WithEndpoint` function or
59+
specified through the `OTEL_EXPORTER_JAEGER_ENDPOINT` environment variable. (#1824)
5560
- Modify Zipkin Exporter default service name, use default resouce's serviceName instead of empty. (#1777)
5661
- Updated Jaeger Environment Variables: `JAEGER_ENDPOINT`, `JAEGER_USER`, `JAEGER_PASSWORD`
5762
to `OTEL_EXPORTER_JAEGER_ENDPOINT`, `OTEL_EXPORTER_JAEGER_USER`, `OTEL_EXPORTER_JAEGER_PASSWORD`
@@ -80,6 +85,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
8085

8186
### Removed
8287

88+
- Removed the functions `CollectorEndpointFromEnv` and `WithCollectorEndpointOptionFromEnv` from the Jaeger exporter.
89+
These functions for retrieving specific environment variable values are redundant of other internal functions and
90+
are not intended for end user use. (#1824)
8391
- Removed Jaeger Environment variables: `JAEGER_SERVICE_NAME`, `JAEGER_DISABLED`, `JAEGER_TAGS`
8492
These environment variables will no longer be used to override values of the Jaeger exporter (#1752)
8593
- No longer set the links for a `Span` in `go.opentelemetry.io/otel/sdk/trace` that is configured to be a new root.

example/jaeger/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
// about the application.
4343
func tracerProvider(url string) (*tracesdk.TracerProvider, error) {
4444
// Create the Jaeger exporter
45-
exp, err := jaeger.NewRawExporter(jaeger.WithCollectorEndpoint(url))
45+
exp, err := jaeger.NewRawExporter(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
4646
if err != nil {
4747
return nil, err
4848
}

exporters/trace/jaeger/env.go

-18
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,3 @@ func envOr(key, defaultValue string) string {
4242
}
4343
return defaultValue
4444
}
45-
46-
// CollectorEndpointFromEnv return environment variable value of OTEL_EXPORTER_JAEGER_ENDPOINT
47-
func CollectorEndpointFromEnv() string {
48-
return os.Getenv(envEndpoint)
49-
}
50-
51-
// WithCollectorEndpointOptionFromEnv uses environment variables to set the username and password
52-
// if basic auth is required.
53-
func WithCollectorEndpointOptionFromEnv() CollectorEndpointOption {
54-
return func(o *CollectorEndpointOptions) {
55-
if e := os.Getenv(envUser); e != "" {
56-
o.username = e
57-
}
58-
if e := os.Getenv(envPassword); e != "" {
59-
o.password = e
60-
}
61-
}
62-
}

exporters/trace/jaeger/env_test.go

+46-28
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ import (
2424
ottest "go.opentelemetry.io/otel/internal/internaltest"
2525
)
2626

27+
func TestNewRawExporterWithDefault(t *testing.T) {
28+
const (
29+
collectorEndpoint = "http://localhost:14250"
30+
username = ""
31+
password = ""
32+
)
33+
34+
// Create Jaeger Exporter with default values
35+
exp, err := NewRawExporter(
36+
WithCollectorEndpoint(),
37+
)
38+
39+
assert.NoError(t, err)
40+
41+
require.IsType(t, &collectorUploader{}, exp.uploader)
42+
uploader := exp.uploader.(*collectorUploader)
43+
assert.Equal(t, collectorEndpoint, uploader.endpoint)
44+
assert.Equal(t, username, uploader.username)
45+
assert.Equal(t, password, uploader.password)
46+
}
47+
2748
func TestNewRawExporterWithEnv(t *testing.T) {
2849
const (
2950
collectorEndpoint = "http://localhost"
@@ -43,7 +64,7 @@ func TestNewRawExporterWithEnv(t *testing.T) {
4364

4465
// Create Jaeger Exporter with environment variables
4566
exp, err := NewRawExporter(
46-
WithCollectorEndpoint(CollectorEndpointFromEnv(), WithCollectorEndpointOptionFromEnv()),
67+
WithCollectorEndpoint(),
4768
)
4869

4970
assert.NoError(t, err)
@@ -55,11 +76,12 @@ func TestNewRawExporterWithEnv(t *testing.T) {
5576
assert.Equal(t, password, uploader.password)
5677
}
5778

58-
func TestNewRawExporterWithEnvImplicitly(t *testing.T) {
79+
func TestNewRawExporterWithPassedOption(t *testing.T) {
5980
const (
6081
collectorEndpoint = "http://localhost"
6182
username = "user"
6283
password = "password"
84+
optionEndpoint = "should not be overwritten"
6385
)
6486

6587
envStore, err := ottest.SetEnvVariables(map[string]string{
@@ -72,16 +94,16 @@ func TestNewRawExporterWithEnvImplicitly(t *testing.T) {
7294
require.NoError(t, envStore.Restore())
7395
}()
7496

75-
// Create Jaeger Exporter with environment variables
97+
// Create Jaeger Exporter with passed endpoint option, should be used over envEndpoint
7698
exp, err := NewRawExporter(
77-
WithCollectorEndpoint("should be overwritten"),
99+
WithCollectorEndpoint(WithEndpoint(optionEndpoint)),
78100
)
79101

80102
assert.NoError(t, err)
81103

82104
require.IsType(t, &collectorUploader{}, exp.uploader)
83105
uploader := exp.uploader.(*collectorUploader)
84-
assert.Equal(t, collectorEndpoint, uploader.endpoint)
106+
assert.Equal(t, optionEndpoint, uploader.endpoint)
85107
assert.Equal(t, username, uploader.username)
86108
assert.Equal(t, password, uploader.password)
87109
}
@@ -152,73 +174,69 @@ func TestEnvOrWithAgentHostPortFromEnv(t *testing.T) {
152174
}
153175
}
154176

155-
func TestCollectorEndpointFromEnv(t *testing.T) {
156-
const (
157-
collectorEndpoint = "http://localhost"
158-
)
159-
160-
envStore, err := ottest.SetEnvVariables(map[string]string{
161-
envEndpoint: collectorEndpoint,
162-
})
163-
require.NoError(t, err)
164-
defer func() {
165-
require.NoError(t, envStore.Restore())
166-
}()
167-
168-
assert.Equal(t, collectorEndpoint, CollectorEndpointFromEnv())
169-
}
170-
171-
func TestWithCollectorEndpointOptionFromEnv(t *testing.T) {
177+
func TestEnvOrWithCollectorEndpointOptionsFromEnv(t *testing.T) {
172178
testCases := []struct {
173179
name string
180+
envEndpoint string
174181
envUsername string
175182
envPassword string
176-
collectorEndpointOptions CollectorEndpointOptions
183+
defaultCollectorEndpointOptions CollectorEndpointOptions
177184
expectedCollectorEndpointOptions CollectorEndpointOptions
178185
}{
179186
{
180187
name: "overrides value via environment variables",
188+
envEndpoint: "http://localhost:14252",
181189
envUsername: "username",
182190
envPassword: "password",
183-
collectorEndpointOptions: CollectorEndpointOptions{
191+
defaultCollectorEndpointOptions: CollectorEndpointOptions{
192+
endpoint: "endpoint not to be used",
184193
username: "foo",
185194
password: "bar",
186195
},
187196
expectedCollectorEndpointOptions: CollectorEndpointOptions{
197+
endpoint: "http://localhost:14252",
188198
username: "username",
189199
password: "password",
190200
},
191201
},
192202
{
193203
name: "environment variables is empty, will not overwrite value",
204+
envEndpoint: "",
194205
envUsername: "",
195206
envPassword: "",
196-
collectorEndpointOptions: CollectorEndpointOptions{
207+
defaultCollectorEndpointOptions: CollectorEndpointOptions{
208+
endpoint: "endpoint to be used",
197209
username: "foo",
198210
password: "bar",
199211
},
200212
expectedCollectorEndpointOptions: CollectorEndpointOptions{
213+
endpoint: "endpoint to be used",
201214
username: "foo",
202215
password: "bar",
203216
},
204217
},
205218
}
206219

207220
envStore := ottest.NewEnvStore()
221+
envStore.Record(envEndpoint)
208222
envStore.Record(envUser)
209223
envStore.Record(envPassword)
210224
defer func() {
211225
require.NoError(t, envStore.Restore())
212226
}()
213227
for _, tc := range testCases {
214228
t.Run(tc.name, func(t *testing.T) {
229+
require.NoError(t, os.Setenv(envEndpoint, tc.envEndpoint))
215230
require.NoError(t, os.Setenv(envUser, tc.envUsername))
216231
require.NoError(t, os.Setenv(envPassword, tc.envPassword))
217232

218-
f := WithCollectorEndpointOptionFromEnv()
219-
f(&tc.collectorEndpointOptions)
233+
endpoint := envOr(envEndpoint, tc.defaultCollectorEndpointOptions.endpoint)
234+
username := envOr(envUser, tc.defaultCollectorEndpointOptions.username)
235+
password := envOr(envPassword, tc.defaultCollectorEndpointOptions.password)
220236

221-
assert.Equal(t, tc.expectedCollectorEndpointOptions, tc.collectorEndpointOptions)
237+
assert.Equal(t, tc.expectedCollectorEndpointOptions.endpoint, endpoint)
238+
assert.Equal(t, tc.expectedCollectorEndpointOptions.username, username)
239+
assert.Equal(t, tc.expectedCollectorEndpointOptions.password, password)
222240
})
223241
}
224242
}

exporters/trace/jaeger/jaeger_test.go

+7-33
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
)
4848

4949
func TestInstallNewPipeline(t *testing.T) {
50-
tp, err := InstallNewPipeline(WithCollectorEndpoint(collectorEndpoint))
50+
tp, err := InstallNewPipeline(WithCollectorEndpoint(WithEndpoint(collectorEndpoint)))
5151
require.NoError(t, err)
5252
// Ensure InstallNewPipeline sets the global TracerProvider. By default
5353
// the global tracer provider will be a NoOp implementation, this checks
@@ -74,7 +74,7 @@ func TestNewExportPipelinePassthroughError(t *testing.T) {
7474
},
7575
{
7676
name: "with collector endpoint",
77-
epo: WithCollectorEndpoint(collectorEndpoint),
77+
epo: WithCollectorEndpoint(WithEndpoint(collectorEndpoint)),
7878
},
7979
} {
8080
t.Run(testcase.name, func(t *testing.T) {
@@ -98,7 +98,7 @@ func TestNewRawExporter(t *testing.T) {
9898
}{
9999
{
100100
name: "default exporter",
101-
endpoint: WithCollectorEndpoint(collectorEndpoint),
101+
endpoint: WithCollectorEndpoint(),
102102
expectedServiceName: "unknown_service",
103103
expectedBufferMaxCount: bundler.DefaultBufferedByteLimit,
104104
expectedBatchMaxCount: bundler.DefaultBundleCountThreshold,
@@ -112,7 +112,7 @@ func TestNewRawExporter(t *testing.T) {
112112
},
113113
{
114114
name: "with buffer and batch max count",
115-
endpoint: WithCollectorEndpoint(collectorEndpoint),
115+
endpoint: WithCollectorEndpoint(WithEndpoint(collectorEndpoint)),
116116
options: []Option{
117117
WithBufferMaxCount(99),
118118
WithBatchMaxCount(99),
@@ -139,32 +139,7 @@ func TestNewRawExporter(t *testing.T) {
139139
}
140140
}
141141

142-
func TestNewRawExporterShouldFail(t *testing.T) {
143-
testCases := []struct {
144-
name string
145-
endpoint EndpointOption
146-
expectedErrMsg string
147-
}{
148-
{
149-
name: "with empty collector endpoint",
150-
endpoint: WithCollectorEndpoint(""),
151-
expectedErrMsg: "collectorEndpoint must not be empty",
152-
},
153-
}
154-
155-
for _, tc := range testCases {
156-
t.Run(tc.name, func(t *testing.T) {
157-
_, err := NewRawExporter(
158-
tc.endpoint,
159-
)
160-
161-
assert.Error(t, err)
162-
assert.EqualError(t, err, tc.expectedErrMsg)
163-
})
164-
}
165-
}
166-
167-
func TestNewRawExporterShouldFailIfCollectorUnset(t *testing.T) {
142+
func TestNewRawExporterUseEnvVarIfOptionUnset(t *testing.T) {
168143
// Record and restore env
169144
envStore := ottest.NewEnvStore()
170145
envStore.Record(envEndpoint)
@@ -174,12 +149,11 @@ func TestNewRawExporterShouldFailIfCollectorUnset(t *testing.T) {
174149

175150
// If the user sets the environment variable OTEL_EXPORTER_JAEGER_ENDPOINT, endpoint will always get a value.
176151
require.NoError(t, os.Unsetenv(envEndpoint))
177-
178152
_, err := NewRawExporter(
179-
WithCollectorEndpoint(""),
153+
WithCollectorEndpoint(),
180154
)
181155

182-
assert.Error(t, err)
156+
assert.NoError(t, err)
183157
}
184158

185159
type testCollectorEndpoint struct {

0 commit comments

Comments
 (0)