Skip to content

Commit

Permalink
Merge pull request #29 from foomo/sesamy-go-0.4.1
Browse files Browse the repository at this point in the history
fix: only log on ignore
  • Loading branch information
franklinkim authored Nov 12, 2024
2 parents dae9b3e + d289d04 commit e8e7722
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ linters-settings:
disabled: true
- name: comment-spacings
disabled: true
- name: max-public-structs
disabled: true
- name: struct-tag
arguments:
- "json,inline"
Expand Down
9 changes: 7 additions & 2 deletions integration/watermill/gtag/publishermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package gtag

import (
"github.com/ThreeDotsLabs/watermill/message"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

func PublisherMiddlewareIgnoreError(next PublisherHandler) PublisherHandler {
return func(l *zap.Logger, msg *message.Message) error {
err := next(l, msg)
l.With(zap.Error(err)).Warn("ignoring error")
if err := next(l, msg); err != nil {
if spanCtx := trace.SpanContextFromContext(msg.Context()); spanCtx.IsValid() && spanCtx.IsSampled() {
l = l.With(zap.String("trace_id", spanCtx.TraceID().String()), zap.String("span_id", spanCtx.SpanID().String()))
}
l.With(zap.Error(err)).Warn("ignoring error")
}
return nil
}
}
4 changes: 4 additions & 0 deletions integration/watermill/gtag/subscribermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/foomo/sesamy-go/pkg/encoding/gtag"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

Expand All @@ -20,6 +21,9 @@ func SubscriberMiddlewareUserID(cookieName string) SubscriberMiddleware {

func SubscriberMiddlewareLogger(next SubscriberHandler) SubscriberHandler {
return func(l *zap.Logger, r *http.Request, payload *gtag.Payload) error {
if spanCtx := trace.SpanContextFromContext(r.Context()); spanCtx.IsValid() && spanCtx.IsSampled() {
l = l.With(zap.String("trace_id", spanCtx.TraceID().String()), zap.String("span_id", spanCtx.SpanID().String()))
}
l = l.With(
zap.String("event_name", gtag.GetDefault(payload.EventName, "-").String()),
zap.String("event_user_id", gtag.GetDefault(payload.UserID, "-")),
Expand Down
9 changes: 7 additions & 2 deletions integration/watermill/mpv2/publishermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import (

"github.com/ThreeDotsLabs/watermill/message"
"github.com/foomo/sesamy-go/pkg/encoding/mpv2"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

// PublisherMiddlewareIgnoreError ignores error responses from the gtm endpoint to prevent retries.
func PublisherMiddlewareIgnoreError(next PublisherHandler) PublisherHandler {
return func(l *zap.Logger, msg *message.Message) error {
err := next(l, msg)
l.With(zap.Error(err)).Warn("ignoring error")
if err := next(l, msg); err != nil {
if spanCtx := trace.SpanContextFromContext(msg.Context()); spanCtx.IsValid() && spanCtx.IsSampled() {
l = l.With(zap.String("trace_id", spanCtx.TraceID().String()), zap.String("span_id", spanCtx.SpanID().String()))
}
l.With(zap.Error(err)).Warn("ignoring error")
}
return nil
}
}
Expand Down
5 changes: 5 additions & 0 deletions integration/watermill/mpv2/subscribermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/foomo/sesamy-go/pkg/encoding/mpv2"
"github.com/foomo/sesamy-go/pkg/session"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -80,6 +81,10 @@ func SubscriberMiddlewareLogger(next SubscriberHandler) SubscriberHandler {
eventNames[i] = event.Name.String()
}

if spanCtx := trace.SpanContextFromContext(r.Context()); spanCtx.IsValid() && spanCtx.IsSampled() {
l = l.With(zap.String("trace_id", spanCtx.TraceID().String()), zap.String("span_id", spanCtx.SpanID().String()))
}

l = l.With(
zap.String("event_names", strings.Join(eventNames, ",")),
zap.String("event_user_id", payload.UserID),
Expand Down

0 comments on commit e8e7722

Please sign in to comment.