Skip to content

Commit

Permalink
MarshalText implementation, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
m-posluszny committed Jan 18, 2024
1 parent 4fb7a19 commit 04cb3e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ test-coverage: | $(GOCOVMERGE)
done; \
$(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt

# Adding a directory will include all benchmarks in that directory if a filter is not specified.
# Adding a directory will include all benchmarks in that direcotry if a filter is not specified.
BENCHMARK_TARGETS := sdk/trace
.PHONY: benchmark
benchmark: $(BENCHMARK_TARGETS:%=benchmark/%)
Expand Down
12 changes: 8 additions & 4 deletions sdk/metric/metricdata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package metricdata // import "go.opentelemetry.io/otel/sdk/metric/metricdata"

import (
"encoding/json"
"fmt"
"time"

"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -213,12 +212,17 @@ type Extrema[N int64 | float64] struct {
valid bool
}

// MarshalJson converts the Extrema value to JSON number
func (e *Extrema[N]) MarshalJSON() ([]byte, error) {
// MarshalText converts the Extrema value to text.
func (e Extrema[N]) MarshalText() ([]byte, error) {
if !e.valid {
return []byte("0"), nil
}
return []byte(json.Number(fmt.Sprint(e.value))), nil
return json.Marshal(e.value)
}

// MarshalJSON converts the Extrema value to JSON number.
func (e *Extrema[N]) MarshalJSON() ([]byte, error) {
return e.MarshalText()
}

// NewExtrema returns an Extrema set to v.
Expand Down

0 comments on commit 04cb3e7

Please sign in to comment.