github.com/TykTechnologies/tyk/internal/otel
No package summary is available.
Package
Files: 1. Third party imports: 1. Imports from organisation: 3. Tests: 0. Benchmarks: 0.
Constants
const (
NON_VERSIONED = "Non Versioned"
)
// span const
const (
SPAN_STATUS_OK = tyktrace.SPAN_STATUS_OK
SPAN_STATUS_ERROR = tyktrace.SPAN_STATUS_ERROR
SPAN_STATUS_UNSET = tyktrace.SPAN_STATUS_UNSET
)
Vars
var APIKeyAliasAttribute = semconv.TykAPIKeyAlias
var APIKeyAttribute = semconv.TykAPIKey
var OAuthClientIDAttribute = semconv.TykOauthID
var (
HTTPHandler = tyktrace.NewHTTPHandler
HTTPRoundTripper = tyktrace.NewHTTPTransport
)
Types
TracerProvider, OpenTelemetry, Sampling, SpanAttribute, Span
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
type (
TracerProvider = tyktrace.Provider
OpenTelemetry = otelconfig.OpenTelemetry
Sampling = otelconfig.Sampling
SpanAttribute = tyktrace.Attribute
Span = tyktrace.Span
)
Functions
func APIVersionAttribute
func APIVersionAttribute(version string) SpanAttribute {
if version == "" {
version = NON_VERSIONED
}
return semconv.TykAPIVersion(version)
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func AddTraceID
func AddTraceID(ctx context.Context, w http.ResponseWriter) {
span := SpanFromContext(ctx)
if span.SpanContext().HasTraceID() {
w.Header().Set("X-Tyk-Trace-Id", span.SpanContext().TraceID().String())
}
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func ApidefSpanAttributes
Span attributes related functions
func ApidefSpanAttributes(apidef *apidef.APIDefinition) []SpanAttribute {
attrs := []SpanAttribute{
semconv.TykAPIName(apidef.Name),
semconv.TykAPIOrgID(apidef.OrgID),
semconv.TykAPIID(apidef.APIID),
semconv.TykAPIListenPath(apidef.Proxy.ListenPath),
}
if !apidef.TagsDisabled {
tags := apidef.Tags
tags = append(tags, apidef.TagHeaders...)
attrs = append(attrs, semconv.TykAPITags(tags...))
}
return attrs
}
Cognitive complexity: 3, Cyclomatic complexity: 2
func ContextWithSpan
func ContextWithSpan(ctx context.Context, span tyktrace.Span) context.Context {
return tyktrace.ContextWithSpan(ctx, span)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func GatewayResourceAttributes
func GatewayResourceAttributes(gwID string, isDataplane bool, groupID string, isSegmented bool, segmentTags []string) []SpanAttribute {
attrs := []SpanAttribute{
semconv.TykGWID(gwID),
semconv.TykGWDataplane(isDataplane),
}
if isDataplane {
attrs = append(attrs, semconv.TykDataplaneGWGroupID(groupID))
}
if isSegmented {
attrs = append(attrs, semconv.TykGWSegmentTags(segmentTags...))
}
return attrs
}
Cognitive complexity: 5, Cyclomatic complexity: 3
func InitOpenTelemetry
InitOpenTelemetry initializes OpenTelemetry - it returns a TracerProvider which can be used to create a tracer. If OpenTelemetry is disabled or misconfigured, a NoopProvider is returned.
func InitOpenTelemetry(ctx context.Context, logger *logrus.Logger, gwConfig *OpenTelemetry, id string, version string,
useRPC bool, groupID string, isSegmented bool, segmentTags []string) TracerProvider {
traceLogger := logger.WithFields(logrus.Fields{
"exporter": gwConfig.Exporter,
"endpoint": gwConfig.Endpoint,
"connection_timeout": gwConfig.ConnectionTimeout,
})
provider, errOtel := tyktrace.NewProvider(
tyktrace.WithContext(ctx),
tyktrace.WithConfig(gwConfig),
tyktrace.WithLogger(traceLogger),
tyktrace.WithServiceID(id),
tyktrace.WithServiceVersion(version),
tyktrace.WithHostDetector(),
tyktrace.WithContainerDetector(),
tyktrace.WithProcessDetector(),
tyktrace.WithCustomResourceAttributes(GatewayResourceAttributes(
id,
useRPC,
groupID,
isSegmented,
segmentTags,
)...),
)
if errOtel != nil {
logger.Errorf("Initializing OpenTelemetry %s", errOtel)
}
return provider
}
Cognitive complexity: 3, Cyclomatic complexity: 2
func SpanFromContext
func SpanFromContext(ctx context.Context) tyktrace.Span {
return tyktrace.SpanFromContext(ctx)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
Tests
Files: 1. Third party imports: 3. Imports from organisation: 2. Tests: 6. Benchmarks: 0.