Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/awsxray] Feature Gate to Allow fully random Trace IDs in XRay Exporter #26041

Merged
merged 10 commits into from
Aug 25, 2023
27 changes: 27 additions & 0 deletions .chloggen/xray-exporter-allow-random-trace-id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: awsxrayexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "add `exporter.awsxray.skiptimestampvalidation` Alpha feature gate to remove xray timestamp restriction on first 32 bits of trace id"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26041]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
3 changes: 2 additions & 1 deletion exporter/awsxrayexporter/awsxray.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func extractResourceSpans(config component.Config, logger *zap.Logger, td ptrace
spans.At(k), resource,
config.(*Config).IndexedAttributes,
config.(*Config).IndexAllAttributes,
config.(*Config).LogGroupNames)
config.(*Config).LogGroupNames,
config.(*Config).skipTimestampValidation)
if localErr != nil {
logger.Debug("Error translating span.", zap.Error(localErr))
continue
Expand Down
3 changes: 3 additions & 0 deletions exporter/awsxrayexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ type Config struct {
LogGroupNames []string `mapstructure:"aws_log_groups"`
// TelemetryConfig contains the options for telemetry collection.
TelemetryConfig telemetry.Config `mapstructure:"telemetry,omitempty"`

// skipTimestampValidation if enabled, will skip timestamp validation logic on the trace ID
skipTimestampValidation bool
}
7 changes: 4 additions & 3 deletions exporter/awsxrayexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ func TestLoadConfig(t *testing.T) {
ResourceARN: "arn:aws:ec2:us-east1:123456789:instance/i-293hiuhe0u",
RoleARN: "arn:aws:iam::123456789:role/monitoring-EKS-NodeInstanceRole",
},
IndexedAttributes: []string{"indexed_attr_0", "indexed_attr_1"},
IndexAllAttributes: false,
LogGroupNames: []string{"group1", "group2"},
IndexedAttributes: []string{"indexed_attr_0", "indexed_attr_1"},
IndexAllAttributes: false,
LogGroupNames: []string{"group1", "group2"},
skipTimestampValidation: false,
},
},
}
Expand Down
10 changes: 9 additions & 1 deletion exporter/awsxrayexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/featuregate"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray/telemetry"
)

var skipTimestampValidationFeatureGate = featuregate.GlobalRegistry().MustRegister(
"exporter.awsxray.skiptimestampvalidation",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("Remove XRay's timestamp validation on first 32 bits of trace ID"),
featuregate.WithRegisterFromVersion("v0.84.0"))

// NewFactory creates a factory for AWS-Xray exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
Expand All @@ -24,7 +31,8 @@ func NewFactory() exporter.Factory {

func createDefaultConfig() component.Config {
return &Config{
AWSSessionSettings: awsutil.CreateDefaultSessionConfig(),
AWSSessionSettings: awsutil.CreateDefaultSessionConfig(),
skipTimestampValidation: skipTimestampValidationFeatureGate.IsEnabled(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/awsxrayexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
go.opentelemetry.io/collector/confmap v0.83.0
go.opentelemetry.io/collector/consumer v0.83.0
go.opentelemetry.io/collector/exporter v0.83.0
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0014
go.opentelemetry.io/collector/pdata v1.0.0-rcv0014
go.opentelemetry.io/collector/semconv v0.83.0
go.uber.org/zap v1.25.0
Expand All @@ -36,7 +37,6 @@ require (
go.opentelemetry.io/collector v0.83.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.83.0 // indirect
go.opentelemetry.io/collector/extension v0.83.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0014 // indirect
go.opentelemetry.io/collector/processor v0.83.0 // indirect
go.opentelemetry.io/collector/receiver v0.83.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
Expand Down
29 changes: 16 additions & 13 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ var (
)

// MakeSegmentDocumentString converts an OpenTelemetry Span to an X-Ray Segment and then serialzies to JSON
func MakeSegmentDocumentString(span ptrace.Span, resource pcommon.Resource, indexedAttrs []string, indexAllAttrs bool, logGroupNames []string) (string, error) {
segment, err := MakeSegment(span, resource, indexedAttrs, indexAllAttrs, logGroupNames)
func MakeSegmentDocumentString(span ptrace.Span, resource pcommon.Resource, indexedAttrs []string, indexAllAttrs bool, logGroupNames []string, skipTimestampValidation bool) (string, error) {
segment, err := MakeSegment(span, resource, indexedAttrs, indexAllAttrs, logGroupNames, skipTimestampValidation)
if err != nil {
return "", err
}
Expand All @@ -77,7 +77,7 @@ func MakeSegmentDocumentString(span ptrace.Span, resource pcommon.Resource, inde
}

// MakeSegment converts an OpenTelemetry Span to an X-Ray Segment
func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []string, indexAllAttrs bool, logGroupNames []string) (*awsxray.Segment, error) {
func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []string, indexAllAttrs bool, logGroupNames []string, skipTimestampValidation bool) (*awsxray.Segment, error) {
var segmentType string

storeResource := true
Expand All @@ -89,7 +89,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str
}

// convert trace id
traceID, err := convertToAmazonTraceID(span.TraceID())
traceID, err := convertToAmazonTraceID(span.TraceID(), skipTimestampValidation)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +107,7 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str
sqlfiltered, sql = makeSQL(span, awsfiltered)
additionalAttrs = addSpecialAttributes(sqlfiltered, indexedAttrs, attributes)
user, annotations, metadata = makeXRayAttributes(additionalAttrs, resource, storeResource, indexedAttrs, indexAllAttrs)
spanLinks, makeSpanLinkErr = makeSpanLinks(span.Links())
spanLinks, makeSpanLinkErr = makeSpanLinks(span.Links(), skipTimestampValidation)
name string
namespace string
)
Expand Down Expand Up @@ -295,7 +295,7 @@ func determineAwsOrigin(resource pcommon.Resource) string {
// - For example, 10:00AM December 2nd, 2016 PST in epoch time is 1480615200 seconds,
// or 58406520 in hexadecimal.
// - A 96-bit identifier for the trace, globally unique, in 24 hexadecimal digits.
func convertToAmazonTraceID(traceID pcommon.TraceID) (string, error) {
func convertToAmazonTraceID(traceID pcommon.TraceID, skipTimestampValidation bool) (string, error) {
const (
// maxAge of 28 days. AWS has a 30 day limit, let's be conservative rather than
// hit the limit
Expand All @@ -313,13 +313,16 @@ func convertToAmazonTraceID(traceID pcommon.TraceID) (string, error) {
b = [4]byte{}
)

// If AWS traceID originally came from AWS, no problem. However, if oc generated
// the traceID, then the epoch may be outside the accepted AWS range of within the
// past 30 days.
//
// In that case, we return invalid traceid error
if delta := epochNow - epoch; delta > maxAge || delta < -maxSkew {
return "", fmt.Errorf("invalid xray traceid: %s", traceID)
// If feature gate is enabled, skip the timestamp validation logic
if !skipTimestampValidation {
// If AWS traceID originally came from AWS, no problem. However, if oc generated
// the traceID, then the epoch may be outside the accepted AWS range of within the
// past 30 days.
//
// In that case, we return invalid traceid error
if delta := epochNow - epoch; delta > maxAge || delta < -maxSkew {
return "", fmt.Errorf("invalid xray traceid: %s", traceID)
}
}

binary.BigEndian.PutUint32(b[0:4], uint32(epoch))
Expand Down
Loading