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

[chore] Don't use deprecated [Span|Trace]ID.HexString method #16301

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
)

const (
Expand Down Expand Up @@ -176,12 +178,12 @@ func mapLogRecordToLogService(lr plog.LogRecord,

contentsBuffer = append(contentsBuffer, sls.LogContent{
Key: proto.String(traceIDField),
Value: proto.String(lr.TraceID().HexString()),
Value: proto.String(traceutil.TraceIDToHexOrEmptyString(lr.TraceID())),
})

contentsBuffer = append(contentsBuffer, sls.LogContent{
Key: proto.String(spanIDField),
Value: proto.String(lr.SpanID().HexString()),
Value: proto.String(traceutil.SpanIDToHexOrEmptyString(lr.SpanID())),
})

for i := range contentsBuffer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/tracetranslator"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
)

const (
Expand Down Expand Up @@ -90,16 +91,16 @@ func spanToLogServiceData(span ptrace.Span, resourceContents, instrumentationLib

contentsBuffer = append(contentsBuffer, sls.LogContent{
Key: proto.String(traceIDField),
Value: proto.String(span.TraceID().HexString()),
Value: proto.String(traceutil.TraceIDToHexOrEmptyString(span.TraceID())),
})
contentsBuffer = append(contentsBuffer, sls.LogContent{
Key: proto.String(spanIDField),
Value: proto.String(span.SpanID().HexString()),
Value: proto.String(traceutil.SpanIDToHexOrEmptyString(span.SpanID())),
})
// if ParentSpanID is not valid, the return "", it is compatible for log service
contentsBuffer = append(contentsBuffer, sls.LogContent{
Key: proto.String(parentSpanIDField),
Value: proto.String(span.ParentSpanID().HexString()),
Value: proto.String(traceutil.SpanIDToHexOrEmptyString(span.ParentSpanID())),
})

contentsBuffer = append(contentsBuffer, sls.LogContent{
Expand Down Expand Up @@ -206,8 +207,8 @@ func spanLinksToString(spanLinkSlice ptrace.SpanLinkSlice) string {
for i := 0; i < spanLinkSlice.Len(); i++ {
spanLink := spanLinkSlice.At(i)
link := map[string]interface{}{}
link[spanIDField] = spanLink.SpanID().HexString()
link[traceIDField] = spanLink.TraceID().HexString()
link[spanIDField] = traceutil.SpanIDToHexOrEmptyString(spanLink.SpanID())
link[traceIDField] = traceutil.TraceIDToHexOrEmptyString(spanLink.TraceID())
link[attributeField] = spanLink.Attributes().AsRaw()
linkArray = append(linkArray, link)
}
Expand Down
7 changes: 4 additions & 3 deletions exporter/awsxrayexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/aws/aws-sdk-go v1.44.133
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.64.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray v0.64.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/collector v0.64.2-0.20221110222631-20e3aac00413
go.opentelemetry.io/collector/pdata v0.64.2-0.20221110222631-20e3aac00413
Expand All @@ -16,7 +17,6 @@ require (
require (
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -28,7 +28,6 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
Expand All @@ -39,7 +38,7 @@ require (
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -48,3 +47,5 @@ require (
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray => ./../../internal/aws/xray

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil => ./../../internal/aws/awsutil

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal
18 changes: 2 additions & 16 deletions exporter/awsxrayexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector-

import (
"bufio"
"encoding/hex"
"net/textproto"
"regexp"
"strconv"
Expand Down Expand Up @@ -108,15 +109,13 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
}

if message != "" {
id := newSegmentID()
hexID := id.HexString()

segmentID := newSegmentID()
cause = &awsxray.CauseData{
Type: awsxray.CauseTypeObject,
CauseObject: awsxray.CauseObject{
Exceptions: []awsxray.Exception{
{
ID: aws.String(hexID),
ID: aws.String(hex.EncodeToString(segmentID[:])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we know it's not empty here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newSegmentID always generates a not empty span ID

Type: aws.String(errorKind),
Message: aws.String(message),
},
Expand Down Expand Up @@ -158,8 +157,9 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p

func parseException(exceptionType string, message string, stacktrace string, language string) []awsxray.Exception {
exceptions := make([]awsxray.Exception, 0, 1)
segmentID := newSegmentID()
exceptions = append(exceptions, awsxray.Exception{
ID: aws.String(newSegmentID().HexString()),
ID: aws.String(hex.EncodeToString(segmentID[:])),
Type: aws.String(exceptionType),
Message: aws.String(message),
})
Expand Down Expand Up @@ -256,8 +256,9 @@ func fillJavaStacktrace(stacktrace string, exceptions []awsxray.Exception) []aws
causeMessage += line
}
}
segmentID := newSegmentID()
exceptions = append(exceptions, awsxray.Exception{
ID: aws.String(newSegmentID().HexString()),
ID: aws.String(hex.EncodeToString(segmentID[:])),
Type: aws.String(causeType),
Message: aws.String(causeMessage),
Stack: nil,
Expand Down Expand Up @@ -351,8 +352,9 @@ func fillPythonStacktrace(stacktrace string, exceptions []awsxray.Exception) []a

causeType := message[0:colonIdx]
causeMessage := message[colonIdx+2:]
segmentID := newSegmentID()
exceptions = append(exceptions, awsxray.Exception{
ID: aws.String(newSegmentID().HexString()),
ID: aws.String(hex.EncodeToString(segmentID[:])),
Type: aws.String(causeType),
Message: aws.String(causeMessage),
})
Expand Down
5 changes: 3 additions & 2 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
conventions "go.opentelemetry.io/collector/semconv/v1.8.0"

awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
)

// AWS X-Ray acceptable values for origin field.
Expand Down Expand Up @@ -189,12 +190,12 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str
}

return &awsxray.Segment{
ID: awsxray.String(span.SpanID().HexString()),
ID: awsxray.String(traceutil.SpanIDToHexOrEmptyString(span.SpanID())),
TraceID: awsxray.String(traceID),
Name: awsxray.String(name),
StartTime: awsP.Float64(startTime),
EndTime: awsP.Float64(endTime),
ParentID: awsxray.String(span.ParentSpanID().HexString()),
ParentID: awsxray.String(traceutil.SpanIDToHexOrEmptyString(span.ParentSpanID())),
Fault: awsP.Bool(isFault),
Error: awsP.Bool(isError),
Throttle: awsP.Bool(isThrottle),
Expand Down
6 changes: 4 additions & 2 deletions exporter/azuredataexplorerexporter/logsdata_to_adx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
)

type AdxLog struct {
Expand All @@ -43,8 +45,8 @@ func mapToAdxLog(resource pcommon.Resource, scope pcommon.InstrumentationScope,
adxLog := &AdxLog{
Timestamp: logData.Timestamp().AsTime().Format(time.RFC3339),
ObservedTimestamp: logData.ObservedTimestamp().AsTime().Format(time.RFC3339),
TraceID: logData.TraceID().HexString(),
SpanID: logData.SpanID().HexString(),
TraceID: traceutil.TraceIDToHexOrEmptyString(logData.TraceID()),
SpanID: traceutil.SpanIDToHexOrEmptyString(logData.SpanID()),
SeverityText: logData.SeverityText(),
SeverityNumber: int32(logData.SeverityNumber()),
Body: logData.Body().AsString(),
Expand Down
10 changes: 5 additions & 5 deletions exporter/azuredataexplorerexporter/tracesdata_to_adx.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func mapToAdxTrace(resource pcommon.Resource, scope pcommon.InstrumentationScope
copyMap(clonedTraceAttrib, getScopeMap(scope))

return &AdxTrace{
TraceID: spanData.TraceID().HexString(),
SpanID: spanData.SpanID().HexString(),
ParentID: spanData.ParentSpanID().HexString(),
TraceID: traceutil.TraceIDToHexOrEmptyString(spanData.TraceID()),
SpanID: traceutil.SpanIDToHexOrEmptyString(spanData.SpanID()),
ParentID: traceutil.SpanIDToHexOrEmptyString(spanData.ParentSpanID()),
SpanName: spanData.Name(),
SpanStatus: traceutil.StatusCodeStr(spanData.Status().Code()),
SpanKind: traceutil.SpanKindStr(spanData.Kind()),
Expand Down Expand Up @@ -91,8 +91,8 @@ func getLinksData(sd ptrace.Span) []*Link {
links := make([]*Link, sd.Links().Len())
for i := 0; i < sd.Links().Len(); i++ {
link := &Link{
TraceID: sd.Links().At(i).TraceID().HexString(),
SpanID: sd.Links().At(i).SpanID().HexString(),
TraceID: traceutil.TraceIDToHexOrEmptyString(sd.Links().At(i).TraceID()),
SpanID: traceutil.SpanIDToHexOrEmptyString(sd.Links().At(i).SpanID()),
TraceState: sd.Links().At(i).TraceState().AsRaw(),
SpanLinkAttributes: sd.Links().At(i).Attributes().AsRaw(),
}
Expand Down
Loading