cmotel

package module
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 17 Imported by: 1

README

cm-otel-go

Documentation

Index

Constants

View Source
const (
	// SpanAttrParentName span atrribute to mark the parent name
	SpanAttrParentName = "coordimap.span_attr.parent_name"

	// SpanAttrComponent span attribute to mark the component
	SpanAttrComponent = "coordimap.span_attr.component"

	// SpanAttrRelationship span attribute to mark a relationship
	SpanAttrRelationship = "coordimap.span_attr.relationship"

	// SpanAttrTargetService span attribute to mark a call or connection to another service. This means an outgoing relationship.
	SpanAttrTargetService = "coordimap.span_attr.target_service"
)
View Source
const (
	// EnvNodeNameType the environment variable that contains the node name
	EnvNodeNameType = "NODE_NAME"

	// EnvPodNameType the environment variable that contains the pod name
	EnvPodNameType = "POD_NAME"

	// PodNameCompleteType this is the name of the attribute that will hold the full internal name of the pod, <K8S_CLUSTER_NAME>.<NAMESPACE_NAME>.<POD_NAME>
	PodNameCompleteType = "POD_NAME"

	// EnvK8SNamespaceName the environment variable that contains the namespace name
	EnvK8SNamespaceName = "NAMESPACE_NAME"

	// EnvNodeIPType the environment variable that contains the node's primary IP
	EnvNodeIPType = "NODE_IP"

	// EnvServiceAccountType the environment variable that contains the node's service accout
	EnvServiceAccountType = "SERVICE_ACCOUNT"

	// EnvK8SClusterName the environment variable that contains the k8s cluster's name
	EnvK8SClusterName = "K8S_CLUSTER_NAME"

	// EnvServiceName environment variable that contains the name of the service
	EnvServiceName = "SERVICE_NAME"

	// EnvTracerName contains the name of the tracer to initialize the Coordimap Otel library
	EnvTracerName = "TRACER_NAME"

	// EnvCmPrefix contains the prefix of the related env variables
	EnvCmPrefix = "CM_PREFIX"

	// EnvTraceParentsMapHeaderName contains the header name where the spans will be stored
	EnvTraceParentsMapHeaderName = "x-COORDIMAP-SPANS"

	// EnvServiceNamePrefix preferrably to be used in order to uniquely identify the services
	EnvServiceNamePrefix = "SERVICE_NAME_PREFIX"
)
View Source
const (
	// CmOtelComponentIDKey the key that will store the ID of the component
	CmOtelComponentIDKey = attribute.Key("cmotel.component.id")

	// CmOtelComponentInternalIDKey the key that will store the internal id of the component
	CmOtelComponentInternalIDKey = attribute.Key("cmotel.component.internal_id")
)
View Source
const (
	// TypeSpan marks the component as an otel span
	TypeSpan = "coordimap.otel.span"

	// ComponentType marks the component as a coordimap component
	ComponentType = "coordimap.cmotel.component_type"

	// CmotelComponentTypeKey Attribute key for the coordimap component type
	CmotelComponentTypeKey = attribute.Key("coordimap.cmotel.component_type")

	// ComponentTypeKey marks the component as a coordimap component
	ComponentTypeKey = attribute.Key(ComponentType)

	// ComponentRelationshipSkipInsert represents a relationship between two components
	ComponentRelationshipSkipInsert = "coordimap.cmotel.component_relationship_skipinsert"

	// OtelComponentRelationship represents a relationship between otel components
	OtelComponentRelationship = "coordimap.cmotel.component_relationship"

	// ComponentTypeGeneric The generic type for any component
	ComponentTypeGeneric = "coordimap.asset.generic"

	// ComponentTypeGenericContainer The generic container used by default
	ComponentTypeGenericContainer = "coordimap.asset.generic_container"

	// ComponentTypeHTTPRestGeneric The HTTP REST component
	ComponentTypeHTTPRestGeneric = "coordimap.asset.http_rest"
)
View Source
const ContextKey contextKey = "cmotel"

ContextKey is used to set or retrieve the cmOtel value to or from the context

Variables

View Source
var (
	// CmOtelMessagingSystemNats sets the messaging system to NATS
	CmOtelMessagingSystemNats = semconv.MessagingSystemKey.String("NATS")
)

Functions

func ExtractJSONKeys added in v0.1.16

func ExtractJSONKeys(jsonBytes []byte) ([]string, error)

ExtractJSONKeys returns a slice of all the keys found in a json byte slice. If there are nested objects they are of the format parentkey.childkey

func GetEnvWithPrefix

func GetEnvWithPrefix(prefix string, env string) string

GetEnvWithPrefix tries to fetch the environment variable value of <prefix><env>. In case it is not set then returns an empty string

func GetServiceName added in v0.1.4

func GetServiceName(name string) string

GetServiceName returns the service name based on the unique service prefix.

func GetUniqueServicePrefix added in v0.1.5

func GetUniqueServicePrefix() string

GetUniqueServicePrefix returns the prefix that will be used to name the service and any other remote services that are being called. It takes into account the environment variables being set. It first checks if the SERVICE_NAME_PREFIX env variable is set. If so that it generates the name by using the value as a prefix. Otherwise if K8S_CLUSTER_NAME and NAMESPACE_NAME have been set then it uses both of them to generate the service name. It also takes into consideration the CM_PREFIX env variable when looking for the previously mentioned environment variables. If none has been set then it returns the provided name.

func InitDefaultTracerProvider added in v0.1.16

func InitDefaultTracerProvider(exporter sdktrace.SpanExporter) error

InitDefaultTracerProvider initialize the default provider

func LoadEnvVarsAsResource

func LoadEnvVarsAsResource(prefix string) *resource.Resource

LoadEnvVarsAsResource loads all the known environment variables as resource attributes

func LoadRESTEndpointAtributes added in v0.1.16

func LoadRESTEndpointAtributes(r *http.Request) []attribute.KeyValue

LoadRESTEndpointAtributes returns an array of KeyValues related to the given request object

func MarshalSpanMap

func MarshalSpanMap(spans map[string]string) (string, error)

MarshalSpanMap marshals into a string the map of spans so that they can be passed as a header

func ParseTraceParent

func ParseTraceParent(traceParent string) (context.Context, error)

ParseTraceParent parses a traceParent header and converts it to a SpanContextConfig

func UnmarshalToSpanMap

func UnmarshalToSpanMap(span string) (map[string]string, error)

UnmarshalToSpanMap unmarshal the specified string to a map

func WithAddComponentAttribute

func WithAddComponentAttribute(attribute attribute.KeyValue) addComponentOptionType

WithAddComponentAttribute extra attributes to add to the component

func WithAddComponentSpan

func WithAddComponentSpan(span trace.Span) addComponentOptionType

WithAddComponentSpan the Span where to add the coordimap component annotation to

func WithAddComponentSpanName

func WithAddComponentSpanName(spanName string) addComponentOptionType

WithAddComponentSpanName the Span name where to add the coordimap component annotation to

func WithAddComponentType

func WithAddComponentType(componentType string) addComponentOptionType

WithAddComponentType the type of the coordimap component

Types

type CMComponent

type CMComponent struct {
	Name       string            `json:"name"`
	InternalID string            `json:"internal_id"`
	Type       string            `json:"type"`
	Data       map[string]string `json:"data"`
}

CMComponent describes the main values of the component

type CMOtel

type CMOtel interface {
	NewSpan(opts ...SpanOption) (trace.Span, context.Context)
	EndSpan(name string, opts ...trace.SpanEndOption) error
	GetSpanContext(name string) (context.Context, error)
	SpanExists(name string) bool
	AddComponent(opts ...addComponentOptionType) error
	AddRemoteSpanCtx(spanCtx context.Context, spanName string) error
	GetSpanTraceparent(name string) string
	GetSpanTraceparentMaps(spanNames []string) (map[string]string, error)
	SetSpanFromTraceparent(name, traceparent string) error
}

CMOtel The interface that helps manage Coordimap spans

func CreateSingleton

func CreateSingleton(intialTracer trace.Tracer, serviceName string) CMOtel

CreateSingleton create a singleton structure

func New

func New(initialTracer trace.Tracer, serviceName string) CMOtel

New creates a new object to handle the traces

func Singleton

func Singleton() CMOtel

Singleton get the singleton object. If the object was not previously created it will create it with the default otel tracer.

type SpanOption

type SpanOption = func(c *newSpanOpts) error

SpanOption the function parameter for creating a Span

func WithParentSpanName

func WithParentSpanName(name string) SpanOption

WithParentSpanName provide the name of the parent span. The name must exist otherwise it will return an error.

func WithSpanContext

func WithSpanContext(ctx context.Context) SpanOption

WithSpanContext an existing span context to create the span from. It defaults to Background()

func WithSpanExternalRelationshipFrom added in v0.1.2

func WithSpanExternalRelationshipFrom(from string) SpanOption

WithSpanExternalRelationshipFrom the span names that are related, i.e. come after, this span.

func WithSpanInternalRelationshipFrom added in v0.1.2

func WithSpanInternalRelationshipFrom(from string) SpanOption

WithSpanInternalRelationshipFrom the span names that are related, i.e. come after, this span.

func WithSpanName

func WithSpanName(name string) SpanOption

WithSpanName the name of the span. It must be a non empty string

func WithSpanRelationshipTo

func WithSpanRelationshipTo(to string) SpanOption

WithSpanRelationshipTo currently not implemented

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL