add aws req retry count. move tagging requestId to complete handler. some aws services fill that in at that stage. tag response content length. req throttled.

This commit is contained in:
Edward Tsang 2018-11-14 10:22:59 -08:00
parent 5ff0624a2d
commit 91787fac0e

View file

@ -1,13 +1,17 @@
package utility package utility
import ( import (
"strings"
"github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/ext"
) )
// From github.com/aws/aws-xray-sdk-go/xray/aws.go
const S3ExtendedRequestIDHeaderKey string = "x-amz-id-2"
// When you initiate any resource client and pass in a AWS session, it does a few things: // When you initiate any resource client and pass in a AWS session, it does a few things:
// * session carries the configuration to make and sign the request header // * session carries the configuration to make and sign the request header
// * session embodies a set of default request handlers to be execute in order // * session embodies a set of default request handlers to be execute in order
@ -47,7 +51,6 @@ func (h *handlers) Send(req *request.Request) {
span = span.SetTag("aws.agent", h.awsAgent(req)) span = span.SetTag("aws.agent", h.awsAgent(req))
span = span.SetTag("aws.operation", req.Operation.Name) span = span.SetTag("aws.operation", req.Operation.Name)
span = span.SetTag("aws.region", req.ClientInfo.SigningRegion) span = span.SetTag("aws.region", req.ClientInfo.SigningRegion)
span = span.SetTag("aws.requestID", req.RequestID)
ext.HTTPMethod.Set(span, req.Operation.HTTPMethod) ext.HTTPMethod.Set(span, req.Operation.HTTPMethod)
ext.HTTPUrl.Set(span, req.HTTPRequest.URL.String()) ext.HTTPUrl.Set(span, req.HTTPRequest.URL.String())
@ -55,12 +58,26 @@ func (h *handlers) Send(req *request.Request) {
} }
func (h *handlers) Complete(req *request.Request) { func (h *handlers) Complete(req *request.Request) {
span := opentracing.SpanFromContext(req.Context()) ctx := req.Context()
span := opentracing.SpanFromContext(ctx)
defer span.Finish() defer span.Finish()
defer FailIfError(span, req.Error) defer FailIfError(span, req.Error)
span = span.SetTag("aws.requestID", req.RequestID)
span = span.SetTag("aws.request.retryCount", req.RetryCount)
span = span.SetTag("aws.requestID", req.RequestID)
if req.HTTPResponse != nil { if req.HTTPResponse != nil {
ext.HTTPStatusCode.Set(span, uint16(req.HTTPResponse.StatusCode)) ext.HTTPStatusCode.Set(span, uint16(req.HTTPResponse.StatusCode))
span = span.SetTag("aws.response.contentLength", req.HTTPResponse.ContentLength)
extendedRequestID := req.HTTPResponse.Header.Get(S3ExtendedRequestIDHeaderKey)
if len(strings.TrimSpace(extendedRequestID)) > 0 {
span = span.SetTag("aws.response.extendedRequestID", extendedRequestID)
} }
}
if request.IsErrorThrottle(req.Error) {
span = span.SetTag("aws.request.throttled", "true")
}
ctx = opentracing.ContextWithSpan(ctx, span)
req.SetContext(ctx)
} }
func (h *handlers) operationName(req *request.Request) string { func (h *handlers) operationName(req *request.Request) string {