Skip to content

Commit

Permalink
Merge pull request #372 from ww24/refactor-otelhttp-filter
Browse files Browse the repository at this point in the history
refactor: refactor otelhttp filter
  • Loading branch information
ww24 authored Oct 23, 2022
2 parents 86de1ca + 049f638 commit 3c13667
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions infra/external/linebot/linebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/google/wire"
"github.com/line/line-bot-sdk-go/v7/linebot"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/filters"
"golang.org/x/xerrors"

"github.com/ww24/linebot/domain/model"
Expand All @@ -28,10 +29,10 @@ type LINEBot struct {
}

func NewLINEBot(conf repository.Config) (*LINEBot, error) {
transport := otelhttp.NewTransport(http.DefaultTransport, otelhttp.WithFilter(func(r *http.Request) bool {
transport := otelhttp.NewTransport(http.DefaultTransport, otelhttp.WithFilter(
// ignore health check request
return r.URL.Path != "/"
}))
filters.Not(filters.Path("/")),
))
hc := &http.Client{Transport: transport}
cli, err := linebot.New(
conf.LINEChannelSecret(),
Expand Down
7 changes: 4 additions & 3 deletions infra/external/weather/weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/google/wire"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/filters"
"golang.org/x/xerrors"
"google.golang.org/api/idtoken"
"google.golang.org/api/option"
Expand Down Expand Up @@ -49,10 +50,10 @@ func (w *Weather) newTransport(ctx context.Context) (http.RoundTripper, error) {
return nil, xerrors.Errorf("failed to create token source: %w", err)
}

transport := otelhttp.NewTransport(http.DefaultTransport, otelhttp.WithFilter(func(r *http.Request) bool {
transport := otelhttp.NewTransport(http.DefaultTransport, otelhttp.WithFilter(
// ignore health check request
return r.URL.Path != "/"
}))
filters.Not(filters.Path("/")),
))
t, err := htransport.NewTransport(ctx, transport, option.WithTokenSource(ts))
if err != nil {
return nil, xerrors.Errorf("failed to create idtoken client: %w", err)
Expand Down

0 comments on commit 3c13667

Please sign in to comment.