Documentation ¶
Overview ¶
Copyright 2021 Portworx
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 Portworx ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 Portworx ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func ContextUnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- func NewFunctionLogger(ctx context.Context) *logrus.Logger
- func NewPackageLogger(component Component) *logrus.Logger
- func RegisterComponent(component Component)
- func RegisterGlobalHook()
- func TODO() context.Context
- func WithCorrelationContext(ctx context.Context, origin Component) context.Context
- type Component
- type ContextInterceptor
- type LogHook
- type RequestContext
Constants ¶
const ( // ContextKey represents the key for storing and retrieving // the correlation context in a context.Context object. ContextKey = contextKeyType("correlation-context") // ContextIDKey represents the key for the correlation ID ContextIDKey = "correlation-context-id" // ContextOriginKey represents the key for the correlation origin ContextOriginKey = "correlation-context-origin" ComponentUnknown = Component("unknown") ComponentCSIDriver = Component("csi-driver") ComponentSDK = Component("sdk-server") ComponentAuth = Component("openstorage/pkg/auth") )
const ( // LogFieldID represents a logging field for IDs LogFieldID = "correlation-id" // LogFieldID represents a logging field for the request origin LogFieldOrigin = "origin" // LogFieldComponent represents a logging field for control plane component. // This is typically set per-package and allows you see which component // the log originated from. LogFieldComponent = "component" )
Variables ¶
This section is empty.
Functions ¶
func ContextUnaryClientInterceptor ¶
func ContextUnaryClientInterceptor( ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption, ) error
ContextUnaryClientInterceptor creates a gRPC interceptor for adding correlation ID to each request
func NewFunctionLogger ¶
NewFunctionLogger creates a logger for usage at a per-function level For example, this logger can be instantiated inside of a function with a given context object. As logs are printed, they will automatically include the correlation context info.
func NewPackageLogger ¶
NewPackageLogger creates a package-level logger for a given component
func RegisterComponent ¶
func RegisterComponent(component Component)
RegisterComponent registers the package where this function was called from as a given component name. This should be done once per package where you want explicitly name the component for this package. Otherwise, we will detect the component based on package directory.
func RegisterGlobalHook ¶
func RegisterGlobalHook()
RegisterGlobalHook will register the correlation logging hook at a global/multi-package level per-program.
Types ¶
type Component ¶
type Component string
Component represents a control plane component for correlating requests
type ContextInterceptor ¶
type ContextInterceptor struct {
Origin Component
}
ContextInterceptor represents a correlation interceptor
func (*ContextInterceptor) ContextUnaryServerInterceptor ¶
func (ci *ContextInterceptor) ContextUnaryServerInterceptor( ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (interface{}, error)
ContextUnaryServerInterceptor creates a gRPC interceptor for adding correlation ID to each request
type RequestContext ¶
type RequestContext struct { // ID is a randomly generated UUID per requst ID string // Origin is the starting point for this request. // Examples may include any of the following: // pxctl, pxc, kubernetes, CSI, SDK, etc Origin Component }
RequestContext represents the context for a given a request. A request represents a single action received from an SDK user, container orchestrator, or any other request.
func RequestContextFromContextMetadata ¶
func RequestContextFromContextMetadata(md metadata.MD) *RequestContext
RequestContextFromContextMetadata returns a new request context from a metadata object
func RequestContextFromContextValue ¶
func RequestContextFromContextValue(ctx context.Context) *RequestContext
RequestContextFromContextValue returns the request context from a context value
func (*RequestContext) AsMap ¶
func (rc *RequestContext) AsMap() map[string]string
AsMap returns the request context as a map