Skip to content

Commit

Permalink
Merge branch 'main' into fix_sync_gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM authored Jun 19, 2024
2 parents 84ace90 + ffe855d commit d822f09
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed

- Retry trace and span ID generation if it generated an invalid one in `go.opentelemetry.io/otel/sdk/trace`. (#5514)
- Log a warning to the OpenTelemetry internal logger when a `Record` in `go.opentelemetry.io/otel/sdk/log` drops an attribute due to a limit being reached. (#5376)
- Identify the `Tracer` returned from the global `TracerProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
- Identify the `Meter` returned from the global `MeterProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
Expand All @@ -39,6 +40,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Prevent random number generation data-race for experimental rand exemplars in `go.opentelemetry.io/otel/sdk/metric`. (#5456)
- Fix counting number of dropped attributes of `Record` in `go.opentelemetry.io/otel/sdk/log`. (#5464)
- Fix panic in baggage creation when a member contains 0x80 char in key or value. (#5494)
- Correct comments for the priority of the `WithEndpoint` and `WithEndpointURL` options and their coresponding environment variables in in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#5508)
- Fix stale timestamps reported by the lastvalue aggregation. (#5517)

## [1.27.0/0.49.0/0.3.0] 2024-05-21
Expand Down
84 changes: 84 additions & 0 deletions exporters/otlp/otlptrace/otlptracegrpc/client_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,87 @@ func TestExportContextLinksStopSignal(t *testing.T) {
return false
}, 10*time.Second, time.Microsecond)
}

func TestWithEndpointWithEnv(t *testing.T) {
testCases := []struct {
name string
options []Option
envs map[string]string
want string
}{
{
name: "WithEndpointURL last",
options: []Option{
WithEndpoint("foo"),
WithEndpointURL("http://bar:8080/path"),
},
want: "bar:8080",
},
{
name: "WithEndpoint last",
options: []Option{
WithEndpointURL("http://bar:8080/path"),
WithEndpoint("foo"),
},
want: "foo",
},
{
name: "OTEL_EXPORTER_OTLP_ENDPOINT only",
envs: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "foo2",
},
want: "foo2",
},
{
name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT only",
envs: map[string]string{
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "bar2",
},
want: "bar2",
},
{
name: "both OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
envs: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "foo2",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "bar2",
},
want: "bar2",
},
{
name: "both options and envs",
envs: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "foo2",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "bar2",
},
options: []Option{
WithEndpointURL("http://bar:8080/path"),
WithEndpoint("foo"),
},
want: "foo",
},
{
name: "both options and envs",
envs: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "foo2",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "bar2",
},
options: []Option{
WithEndpoint("foo"),
WithEndpointURL("http://bar:8080/path"),
},
want: "bar:8080",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for key, value := range tc.envs {
t.Setenv(key, value)
}

client := newClient(tc.options...)

assert.Equal(t, tc.want, client.endpoint)
})
}
}
10 changes: 6 additions & 4 deletions exporters/otlp/otlptrace/otlptracegrpc/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func WithInsecure() Option {
//
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
// environment variable is set, and this option is not passed, that variable
// value will be used. If both are set, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
// will take precedence.
// value will be used. If both environment variables are set,
// OTEL_EXPORTER_OTLP_TRACES_ENDPOINT will take precedence. If an environment
// variable is set, and this option is passed, this option will take precedence.
//
// If both this option and WithEndpointURL are used, the last used option will
// take precedence.
Expand All @@ -79,8 +80,9 @@ func WithEndpoint(endpoint string) Option {
//
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
// environment variable is set, and this option is not passed, that variable
// value will be used. If both are set, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
// will take precedence.
// value will be used. If both environment variables are set,
// OTEL_EXPORTER_OTLP_TRACES_ENDPOINT will take precedence. If an environment
// variable is set, and this option is passed, this option will take precedence.
//
// If both this option and WithEndpoint are used, the last used option will
// take precedence.
Expand Down
21 changes: 18 additions & 3 deletions sdk/trace/id_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace
gen.Lock()
defer gen.Unlock()
sid := trace.SpanID{}
_, _ = gen.randSource.Read(sid[:])
for {
_, _ = gen.randSource.Read(sid[:])
if sid.IsValid() {
break
}
}
return sid
}

Expand All @@ -51,9 +56,19 @@ func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.
gen.Lock()
defer gen.Unlock()
tid := trace.TraceID{}
_, _ = gen.randSource.Read(tid[:])
sid := trace.SpanID{}
_, _ = gen.randSource.Read(sid[:])
for {
_, _ = gen.randSource.Read(tid[:])
if tid.IsValid() {
break
}
}
for {
_, _ = gen.randSource.Read(sid[:])
if sid.IsValid() {
break
}
}
return tid, sid
}

Expand Down

0 comments on commit d822f09

Please sign in to comment.