Skip to content

Commit

Permalink
export field to add events
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-srivastava28 committed Mar 18, 2024
1 parent a13268f commit e4ea09d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions runtime/client_http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"strings"
"time"

"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/uber/zanzibar/v2/runtime/jsonwrapper"

Expand Down Expand Up @@ -219,7 +218,7 @@ func (req *ClientHTTPRequest) Do() (*ClientHTTPResponse, error) {

req.res.setRawHTTPResponse(res)

// generate events
// generate Events
if GetToCapture(ctx) {
// ReadAll, caches bytes internally so multiple calls will return the same data
rspBytes, err := req.res.ReadAll()
Expand All @@ -239,7 +238,7 @@ func (req *ClientHTTPRequest) Do() (*ClientHTTPResponse, error) {
}

if ec := GetEventContainer(ctx); ec != nil {
ec.events = append(ec.events, event)
ec.Events = append(ec.Events, event)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,5 +656,5 @@ func TestEventContainer(t *testing.T) {
ctx = WithEventContainer(ctx, &EventContainer{})
ec := GetEventContainer(ctx)

assert.Equal(t, len(ec.events), 0)
assert.Equal(t, len(ec.Events), 0)
}
8 changes: 4 additions & 4 deletions runtime/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package zanzibar

// Context Variables
const (
// ToCapture set to true if events have to be captured
// ToCapture set to true if Events have to be captured
ToCapture = "to_capture"
)

Expand All @@ -40,9 +40,9 @@ type Event interface {
Name() string
}

// EventContainer holds generated events.
// EventContainer holds generated Events.
type EventContainer struct {
events []Event
Events []Event
}

// ThriftOutgoingEvent captures request and response data
Expand Down Expand Up @@ -118,7 +118,7 @@ type HTTPCapture struct {
RspBody []byte
}

// NoOpEventHandler ignored events
// NoOpEventHandler ignored Events
func NoOpEventHandler(events []Event) error {
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions runtime/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net/http"
"net/url"

"github.com/opentracing/opentracing-go"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"github.com/uber-go/tally"
Expand Down Expand Up @@ -177,12 +176,12 @@ func (endpoint *RouterEndpoint) HandleRequest(
endpoint.HandlerFn(ctx, req, req.res)
req.res.flush(ctx)

// retrieve the container to see if any events are generated?
// retrieve the container to see if any Events are generated?
if GetToCapture(ctx) {
ec := GetEventContainer(ctx)
var events []Event
if ec != nil {
events = append(events, ec.events...)
events = append(events, ec.Events...)
}

event := &HTTPIncomingEvent{
Expand Down
3 changes: 1 addition & 2 deletions runtime/tchannel_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/pkg/errors"
"github.com/uber-go/tally"
"github.com/uber/tchannel-go"
"github.com/uber/zanzibar/v2/runtime/ruleengine"
netContext "golang.org/x/net/context"
)
Expand Down Expand Up @@ -303,7 +302,7 @@ func (c *TChannelClient) call(
}

if ec := GetEventContainer(ctx); ec != nil {
ec.events = append(ec.events, event)
ec.Events = append(ec.Events, event)
}
}

Expand Down

0 comments on commit e4ea09d

Please sign in to comment.