Skip to content

Commit

Permalink
Merge pull request #499 from kilianstallz/main
Browse files Browse the repository at this point in the history
Migrate to OTEL-Go v1.14.0
  • Loading branch information
ReneWerner87 authored Mar 12, 2023
2 parents 35787f6 + 7f1db91 commit 2968cf4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
14 changes: 9 additions & 5 deletions otelfiber/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/unit"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
oteltrace "go.opentelemetry.io/otel/trace"
Expand All @@ -27,6 +26,11 @@ const (
metricNameHttpServerRequestSize = "http.server.request.size"
metricNameHttpServerResponseSize = "http.server.response.size"
metricNameHttpServerActiveRequests = "http.server.active_requests"

// Unit constants for deprecated metric units
UnitDimensionless = "1"
UnitBytes = "By"
UnitMilliseconds = "ms"
)

// Middleware returns fiber handler which will trace incoming requests.
Expand All @@ -52,19 +56,19 @@ func Middleware(opts ...Option) fiber.Handler {
metric.WithInstrumentationVersion(otelcontrib.SemVersion()),
)

httpServerDuration, err := meter.Float64Histogram(metricNameHttpServerDuration, instrument.WithUnit(unit.Milliseconds), instrument.WithDescription("measures the duration inbound HTTP requests"))
httpServerDuration, err := meter.Float64Histogram(metricNameHttpServerDuration, instrument.WithUnit(UnitMilliseconds), instrument.WithDescription("measures the duration inbound HTTP requests"))
if err != nil {
otel.Handle(err)
}
httpServerRequestSize, err := meter.Int64Histogram(metricNameHttpServerRequestSize, instrument.WithUnit(unit.Bytes), instrument.WithDescription("measures the size of HTTP request messages"))
httpServerRequestSize, err := meter.Int64Histogram(metricNameHttpServerRequestSize, instrument.WithUnit(UnitBytes), instrument.WithDescription("measures the size of HTTP request messages"))
if err != nil {
otel.Handle(err)
}
httpServerResponseSize, err := meter.Int64Histogram(metricNameHttpServerResponseSize, instrument.WithUnit(unit.Bytes), instrument.WithDescription("measures the size of HTTP response messages"))
httpServerResponseSize, err := meter.Int64Histogram(metricNameHttpServerResponseSize, instrument.WithUnit(UnitBytes), instrument.WithDescription("measures the size of HTTP response messages"))
if err != nil {
otel.Handle(err)
}
httpServerActiveRequests, err := meter.Int64UpDownCounter(metricNameHttpServerActiveRequests, instrument.WithUnit(unit.Dimensionless), instrument.WithDescription("measures the number of concurrent HTTP requests that are currently in-flight"))
httpServerActiveRequests, err := meter.Int64UpDownCounter(metricNameHttpServerActiveRequests, instrument.WithUnit(UnitDimensionless), instrument.WithDescription("measures the number of concurrent HTTP requests that are currently in-flight"))
if err != nil {
otel.Handle(err)
}
Expand Down
10 changes: 5 additions & 5 deletions otelfiber/fiber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric/unit"
"go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/instrumentation"
Expand Down Expand Up @@ -276,7 +275,8 @@ func TestMetric(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, route, nil)
_, _ = app.Test(r)

metrics, err := reader.Collect(context.Background())
metrics := metricdata.ResourceMetrics{}
err := reader.Collect(context.Background(), &metrics)
assert.NoError(t, err)
assert.Len(t, metrics.ScopeMetrics, 1)

Expand Down Expand Up @@ -318,7 +318,7 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, route string,
want := metricdata.Metrics{
Name: metricNameHttpServerRequestSize,
Description: "measures the size of HTTP request messages",
Unit: unit.Bytes,
Unit: UnitBytes,
Data: getHistogram(0, responseAttrs),
}
metricdatatest.AssertEqual(t, want, sm.Metrics[1], metricdatatest.IgnoreTimestamp())
Expand All @@ -327,7 +327,7 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, route string,
want = metricdata.Metrics{
Name: metricNameHttpServerResponseSize,
Description: "measures the size of HTTP response messages",
Unit: unit.Bytes,
Unit: UnitBytes,
Data: getHistogram(2, responseAttrs),
}
metricdatatest.AssertEqual(t, want, sm.Metrics[2], metricdatatest.IgnoreTimestamp())
Expand All @@ -336,7 +336,7 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, route string,
want = metricdata.Metrics{
Name: metricNameHttpServerActiveRequests,
Description: "measures the number of concurrent HTTP requests that are currently in-flight",
Unit: unit.Dimensionless,
Unit: UnitDimensionless,
Data: metricdata.Sum[int64]{
DataPoints: []metricdata.DataPoint[int64]{
{Attributes: attribute.NewSet(requestAttrs...), Value: 0},
Expand Down
4 changes: 2 additions & 2 deletions otelfiber/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
go.opentelemetry.io/contrib v1.15.0
go.opentelemetry.io/contrib/propagators/b3 v1.15.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/metric v0.36.0
go.opentelemetry.io/otel/metric v0.37.0
go.opentelemetry.io/otel/oteltest v1.0.0-RC3
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/sdk/metric v0.36.0
go.opentelemetry.io/otel/sdk/metric v0.37.0
go.opentelemetry.io/otel/trace v1.14.0
)

Expand Down
8 changes: 4 additions & 4 deletions otelfiber/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ go.opentelemetry.io/contrib/propagators/b3 v1.15.0/go.mod h1:VjU0g2v6HSQ+Nwfifam
go.opentelemetry.io/otel v1.0.0-RC3/go.mod h1:Ka5j3ua8tZs4Rkq4Ex3hwgBgOchyPVq5S6P2lz//nKQ=
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
go.opentelemetry.io/otel/metric v0.36.0 h1:t0lgGI+L68QWt3QtOIlqM9gXoxqxWLhZ3R/e5oOAY0Q=
go.opentelemetry.io/otel/metric v0.36.0/go.mod h1:wKVw57sd2HdSZAzyfOM9gTqqE8v7CbqWsYL6AyrH9qk=
go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs=
go.opentelemetry.io/otel/metric v0.37.0/go.mod h1:DmdaHfGt54iV6UKxsV9slj2bBRJcKC1B1uvDLIioc1s=
go.opentelemetry.io/otel/oteltest v1.0.0-RC3 h1:MjaeegZTaX0Bv9uB9CrdVjOFM/8slRjReoWoV9xDCpY=
go.opentelemetry.io/otel/oteltest v1.0.0-RC3/go.mod h1:xpzajI9JBRr7gX63nO6kAmImmYIAtuQblZ36Z+LfCjE=
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=
go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM=
go.opentelemetry.io/otel/sdk/metric v0.36.0 h1:dEXpkkOAEcHiRiaZdvd63MouV+3bCtAB/bF3jlNKnr8=
go.opentelemetry.io/otel/sdk/metric v0.36.0/go.mod h1:Lv4HQQPSCSkhyBKzLNtE8YhTSdK4HCwNh3lh7CiR20s=
go.opentelemetry.io/otel/sdk/metric v0.37.0 h1:haYBBtZZxiI3ROwSmkZnI+d0+AVzBWeviuYQDeBWosU=
go.opentelemetry.io/otel/sdk/metric v0.37.0/go.mod h1:mO2WV1AZKKwhwHTV3AKOoIEb9LbUaENZDuGUQd+j4A0=
go.opentelemetry.io/otel/trace v1.0.0-RC3/go.mod h1:VUt2TUYd8S2/ZRX09ZDFZQwn2RqfMB5MzO17jBojGxo=
go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
Expand Down

0 comments on commit 2968cf4

Please sign in to comment.