Skip to content

Commit 5d0cea9

Browse files
authored
Merge branch 'main' into explicit_bucket_advisory_sdk
2 parents 1d7d3a9 + 5ec67e8 commit 5d0cea9

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
5252
- Retry for `502 Bad Gateway` and `504 Gateway Timeout` HTTP statuses in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#4670)
5353
- Retry for `RESOURCE_EXHAUSTED` only if RetryInfo is returned in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#4669)
5454
- Retry for `RESOURCE_EXHAUSTED` only if RetryInfo is returned in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#4669)
55+
- Retry temporary HTTP request failures in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4679)
56+
- Retry temporary HTTP request failures in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#4679)
5557

5658
### Fixed
5759

exporters/otlp/otlpmetric/otlpmetrichttp/client.go

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bytes"
1919
"compress/gzip"
2020
"context"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"net"
@@ -147,6 +148,10 @@ func (c *client) UploadMetrics(ctx context.Context, protoMetrics *metricpb.Resou
147148

148149
request.reset(iCtx)
149150
resp, err := c.httpClient.Do(request.Request)
151+
var urlErr *url.Error
152+
if errors.As(err, &urlErr) && urlErr.Temporary() {
153+
return newResponseError(http.Header{})
154+
}
150155
if err != nil {
151156
return err
152157
}

exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ func TestClient(t *testing.T) {
6565
t.Run("Integration", otest.RunClientTests(factory))
6666
}
6767

68+
func TestNewWithInvalidEndpoint(t *testing.T) {
69+
ctx := context.Background()
70+
exp, err := New(ctx, WithEndpoint("host:invalid-port"))
71+
assert.Error(t, err)
72+
assert.Nil(t, exp)
73+
}
74+
6875
func TestConfig(t *testing.T) {
6976
factoryFunc := func(ePt string, rCh <-chan otest.ExportResult, o ...Option) (metric.Exporter, *otest.HTTPCollector) {
7077
coll, err := otest.NewHTTPCollector(ePt, rCh)
@@ -113,7 +120,7 @@ func TestConfig(t *testing.T) {
113120
t.Cleanup(func() { close(rCh) })
114121
t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) })
115122
err := exp.Export(ctx, &metricdata.ResourceMetrics{})
116-
assert.ErrorContains(t, err, context.DeadlineExceeded.Error())
123+
assert.ErrorAs(t, err, new(retryableError))
117124
})
118125

119126
t.Run("WithCompressionGZip", func(t *testing.T) {
@@ -174,17 +181,6 @@ func TestConfig(t *testing.T) {
174181
assert.Len(t, coll.Collect().Dump(), 1)
175182
})
176183

177-
t.Run("WithURLPath", func(t *testing.T) {
178-
path := "/prefix/v2/metrics"
179-
ePt := fmt.Sprintf("http://localhost:0%s", path)
180-
exp, coll := factoryFunc(ePt, nil, WithURLPath(path))
181-
ctx := context.Background()
182-
t.Cleanup(func() { require.NoError(t, coll.Shutdown(ctx)) })
183-
t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) })
184-
assert.NoError(t, exp.Export(ctx, &metricdata.ResourceMetrics{}))
185-
assert.Len(t, coll.Collect().Dump(), 1)
186-
})
187-
188184
t.Run("WithTLSClientConfig", func(t *testing.T) {
189185
ePt := "https://localhost:0"
190186
tlsCfg := &tls.Config{InsecureSkipVerify: true}

exporters/otlp/otlptrace/otlptracehttp/client.go

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bytes"
1919
"compress/gzip"
2020
"context"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"net"
@@ -152,6 +153,10 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
152153

153154
request.reset(ctx)
154155
resp, err := d.client.Do(request.Request)
156+
var urlErr *url.Error
157+
if errors.As(err, &urlErr) && urlErr.Temporary() {
158+
return newResponseError(http.Header{})
159+
}
155160
if err != nil {
156161
return err
157162
}

exporters/otlp/otlptrace/otlptracehttp/client_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"errors"
2020
"fmt"
2121
"net/http"
22-
"os"
2322
"strings"
2423
"testing"
2524
"time"
@@ -213,6 +212,7 @@ func TestTimeout(t *testing.T) {
213212
otlptracehttp.WithEndpoint(mc.Endpoint()),
214213
otlptracehttp.WithInsecure(),
215214
otlptracehttp.WithTimeout(time.Nanosecond),
215+
otlptracehttp.WithRetry(otlptracehttp.RetryConfig{Enabled: false}),
216216
)
217217
ctx := context.Background()
218218
exporter, err := otlptrace.New(ctx, client)
@@ -221,9 +221,7 @@ func TestTimeout(t *testing.T) {
221221
assert.NoError(t, exporter.Shutdown(ctx))
222222
}()
223223
err = exporter.ExportSpans(ctx, otlptracetest.SingleReadOnlySpan())
224-
unwrapped := errors.Unwrap(err)
225-
assert.Equalf(t, true, os.IsTimeout(unwrapped), "expected timeout error, got: %v", unwrapped)
226-
assert.True(t, strings.HasPrefix(err.Error(), "traces export: "), err)
224+
assert.ErrorContains(t, err, "retry-able request failure")
227225
}
228226

229227
func TestNoRetry(t *testing.T) {

0 commit comments

Comments
 (0)