Documentation ¶
Index ¶
- Variables
- func EndpointTracingMiddleware(next endpoint.Endpoint) endpoint.Endpoint
- func FromGRPCRequest(tracer stdopentracing.Tracer, operationName string, logger log.Logger) grpctransport.RequestFunc
- func FromHTTPRequest(tracer stdopentracing.Tracer, operationName string, logger log.Logger) httptransport.RequestFunc
- func GRPCFinish() grpctransport.ResponseFunc
- func ToGRPCRequest(tracer stdopentracing.Tracer, logger log.Logger) grpctransport.RequestFunc
- func ToHTTPResponse(tracer stdopentracing.Tracer, logger log.Logger) httptransport.ServerResponseFunc
- func TraceAPIErrorAndFinish(ctx context.Context, header http.Header, err APIError)
- func TraceError(ctx context.Context, err error)
- func TraceStatusAndFinish(ctx context.Context, header http.Header, status int)
- func TransportErrorEncoder(ctx context.Context, err error, w http.ResponseWriter)
- func WithErrBodyDecoding(err error) error
- func WithErrQueryParam(err error, key string) error
- type APIError
Constants ¶
This section is empty.
Variables ¶
var ( // APIInternal indicates an unexpected internal error. APIInternal = APIError{ Status: 500, Description: "An internal error occured. Please retry later.", ErrorCode: "INTERNAL_ERROR", Params: make(map[string]interface{}), } // the domain execution (from go-kit). Probably caused by an overload. APIUnavailable = APIError{ Status: 503, Description: "The service is currently unavailable. Please retry later.", ErrorCode: "SERVICE_UNAVAILABLE", Params: make(map[string]interface{}), } // APIBodyDecoding indicates that the request body could not be decoded (bad syntax). APIBodyDecoding = APIError{ Status: 400, Description: "Could not decode the JSON request.", ErrorCode: "BODY_DECODING_ERROR", Params: make(map[string]interface{}), } // APIQueryParam indicates that an expected query parameter is missing. APIQueryParam = APIError{ Status: 400, Description: "Missing query parameter.", ErrorCode: "QUERY_PARAM_ERROR", Params: make(map[string]interface{}), } // APIValidation indicates that some received parameters are invalid. APIValidation = APIError{ Status: 400, Description: "The parameters validation failed.", ErrorCode: "VALIDATION_ERROR", Params: make(map[string]interface{}), } APIUnauthorized = APIError{ Status: 401, Description: "Authorization Required.", ErrorCode: "AUTHORIZATION_REQUIRED", Params: make(map[string]interface{}), } // APIForbidden indicates that the user has a valid session but he is missing some permissions. APIForbidden = APIError{ Status: 403, Description: "The specified resource was not found or you don't have sufficient permissions.", ErrorCode: "FORBIDDEN", Params: make(map[string]interface{}), } )
Functions ¶
func EndpointTracingMiddleware ¶
EndpointTracingMiddleware traces unexpected errors at the endpoint level.
func FromGRPCRequest ¶
func FromGRPCRequest(tracer stdopentracing.Tracer, operationName string, logger log.Logger) grpctransport.RequestFunc
FromGRPCRequest returns a grpc RequestFunc that tries to join with an OpenTracing trace found in `req` and starts a new Span called `operationName` accordingly. If no trace could be found in `req`, the Span will be a trace root. The Span is incorporated in the returned Context and can be retrieved with opentracing.SpanFromContext(ctx).
func FromHTTPRequest ¶
func FromHTTPRequest(tracer stdopentracing.Tracer, operationName string, logger log.Logger) httptransport.RequestFunc
FromHTTPRequest returns an http RequestFunc that tries to join with an OpenTracing trace found in `req` and starts a new Span called `operationName` accordingly. If no trace could be found in `req`, the Span will be a trace root. The Span is incorporated in the returned Context and can be retrieved with opentracing.SpanFromContext(ctx).
func GRPCFinish ¶
func GRPCFinish() grpctransport.ResponseFunc
GRPCFinish finishes a span if a trace could be found.
func ToGRPCRequest ¶
func ToGRPCRequest(tracer stdopentracing.Tracer, logger log.Logger) grpctransport.RequestFunc
ToGRPCRequest returns a grpc RequestFunc that injects an OpenTracing Span found in `ctx` into the grpc Metadata. If no such Span can be found, the RequestFunc is a noop.
func ToHTTPResponse ¶
func ToHTTPResponse(tracer stdopentracing.Tracer, logger log.Logger) httptransport.ServerResponseFunc
ToHTTPResponse returns a http ServerResponseFunc that injects an OpenTracing Span found in `ctx` in the response HTTP header. Typicaly useful for tracing using subrequests. eg. Nginx auth subrequests.
func TraceAPIErrorAndFinish ¶
TraceAPIErrorAndFinish traces an APIError response and finishes the span if a trace could be found.
func TraceError ¶
TraceError traces an error into an 'error' tag that appears red on Zipkin. It is typically used to show that something unexpected happened. It also tags the stacktrace if it could be found.
func TraceStatusAndFinish ¶
TraceStatusAndFinish traces a HTTP response and finishes the span if a trace could be found.
func TransportErrorEncoder ¶
func TransportErrorEncoder(ctx context.Context, err error, w http.ResponseWriter)
TransportErrorEncoder offers a standardized way of handling transport errors. It responds with the appropriate APIError and traces it.
func WithErrBodyDecoding ¶
WithErrBodyDecoding adds a errBodyDecodingBehavior to the given error.
func WithErrQueryParam ¶
WithErrQueryParam adds a errQueryParamBehavior to the given error.
Types ¶
type APIError ¶
type APIError struct { // The status code. Status int `json:"status"` // The description of the API error. Description string `json:"description"` // The token uniquely identifying the API error. ErrorCode string `json:"errorCode"` // Additional infos. Params map[string]interface{} `json:"params,omitempty"` }
APIError defines a standard format for API errors.