Skip to content

Commit

Permalink
changed option from WithDefaultAttribute to WithAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-filipponi committed Jul 10, 2024
1 parent 5b11233 commit 02ba617
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions instrumentation/net/http/otelhttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type config struct {
Filters []Filter
SpanNameFormatter func(string, *http.Request) string
ClientTrace func(context.Context) *httptrace.ClientTrace
DefaultAttributes []attribute.KeyValue
Attributes []attribute.KeyValue

TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
Expand Down Expand Up @@ -198,10 +198,9 @@ func WithServerName(server string) Option {
})
}

// WithDefaultAttributes returns an option that sets the default attributes to be
// included in metrics.
func WithDefaultAttributes(attributes []attribute.KeyValue) Option {
// WithAttributes returns an option that sets of attributes to be always included in metrics.
func WithAttributes(attributes []attribute.KeyValue) Option {
return optionFunc(func(c *config) {
c.DefaultAttributes = attributes
c.Attributes = attributes
})
}
2 changes: 1 addition & 1 deletion instrumentation/net/http/otelhttp/test/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func TestDefaultAttributesHandling(t *testing.T) {

transport := otelhttp.NewTransport(
http.DefaultTransport, otelhttp.WithMeterProvider(provider),
otelhttp.WithDefaultAttributes(defaultAttributes))
otelhttp.WithAttributes(defaultAttributes))
client := http.Client{Transport: transport}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
Expand Down
6 changes: 3 additions & 3 deletions instrumentation/net/http/otelhttp/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Transport struct {
filters []Filter
spanNameFormatter func(string, *http.Request) string
clientTrace func(context.Context) *httptrace.ClientTrace
defaultAttributes []attribute.KeyValue
attributes []attribute.KeyValue

requestBytesCounter metric.Int64Counter
responseBytesCounter metric.Int64Counter
Expand Down Expand Up @@ -77,7 +77,7 @@ func (t *Transport) applyConfig(c *config) {
t.filters = c.Filters
t.spanNameFormatter = c.SpanNameFormatter
t.clientTrace = c.ClientTrace
t.defaultAttributes = c.DefaultAttributes
t.attributes = c.Attributes
}

func (t *Transport) createMeasures() {
Expand Down Expand Up @@ -169,7 +169,7 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
}

// metrics
metricAttrs := append(append(labeler.Get(), semconvutil.HTTPClientRequestMetrics(r)...), t.defaultAttributes...)
metricAttrs := append(append(labeler.Get(), semconvutil.HTTPClientRequestMetrics(r)...), t.attributes...)
if res.StatusCode > 0 {
metricAttrs = append(metricAttrs, semconv.HTTPStatusCode(res.StatusCode))
}
Expand Down

0 comments on commit 02ba617

Please sign in to comment.