-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,11 +54,15 @@ func transactionFromRequestContext(req *http.Request) *Transaction { | |
return txn | ||
} | ||
|
||
func transactionFromRequestContextFastHTTP(ctx *fasthttp.RequestCtx) *Transaction { | ||
func transactionFromRequestContextFastHTTP(ctx interface{}) *Transaction { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
aayush-ap
Author
|
||
var txn *Transaction | ||
if nil != ctx { | ||
txn := ctx.UserValue("transaction").(*Transaction) | ||
return txn | ||
switch context := ctx.(type) { | ||
case *fasthttp.RequestCtx: | ||
txn = context.UserValue("transaction").(*Transaction) | ||
case context.Context: | ||
txn = FromContext(context) | ||
} | ||
} | ||
|
||
if txn != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,13 +340,14 @@ func StartExternalSegment(txn *Transaction, request *http.Request) *ExternalSegm | |
return s | ||
} | ||
|
||
func StartExternalSegmentFastHTTP(txn *Transaction, ctx *fasthttp.RequestCtx) *ExternalSegment { | ||
func StartExternalSegmentFastHTTP(txn *Transaction, ctx interface{}, req *fasthttp.Request) *ExternalSegment { | ||
This comment has been minimized.
Sorry, something went wrong.
iamemilio
|
||
if nil == txn { | ||
txn = transactionFromRequestContextFastHTTP(ctx) | ||
} | ||
request := &http.Request{} | ||
|
||
fasthttpadaptor.ConvertRequest(ctx, request, true) | ||
dummy_ctx := &fasthttp.RequestCtx{Request: *req} | ||
request := &http.Request{} | ||
fasthttpadaptor.ConvertRequest(dummy_ctx, request, true) | ||
s := &ExternalSegment{ | ||
StartTime: txn.StartSegmentNow(), | ||
Request: request, | ||
|
@@ -355,15 +356,21 @@ func StartExternalSegmentFastHTTP(txn *Transaction, ctx *fasthttp.RequestCtx) *E | |
s.secureAgentEvent = secureAgent.SendEvent("OUTBOUND", request) | ||
} | ||
|
||
if request != nil && request.Header != nil { | ||
request = &http.Request{} | ||
if req != nil { | ||
for key, values := range s.outboundHeaders() { | ||
for _, value := range values { | ||
request.Header.Set(key, value) | ||
req.Header.Set(key, value) | ||
} | ||
} | ||
|
||
if IsSecurityAgentPresent() { | ||
secureAgent.DistributedTraceHeaders(request, s.secureAgentEvent) | ||
for key, values := range request.Header { | ||
for _, value := range values { | ||
req.Header.Set(key, value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
2 comments
on commit 15a72c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aayush-ap this only needs to serve Fasthttp. We have also been asked to move this code into its own extension for security reasons: https://github.com/newrelic/go-agent/pull/808/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us know if the k2 agent needs any changes from this PR
@aayush-ap why do we need this? If the Transaction is in a regular context, we can just use
newrelic.FromContext()