Skip to content

Commit

Permalink
Merge in latest semconv pkg.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhlogin committed Dec 18, 2024
1 parent 831e4d6 commit c176b07
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 112 deletions.
2 changes: 1 addition & 1 deletion exporter/awsxrayexporter/awsxray.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newTracesExporter(
}
return err
},
exporterhelper.WithStart(func(ctx context.Context, host component.Host) error {
exporterhelper.WithStart(func(_ context.Context, host component.Host) error {
awsConfig, session, err := awsutil.GetAWSConfigSession(logger, cn, &cfg.AWSSessionSettings)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions exporter/awsxrayexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.103.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray v0.103.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.103.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/collector/component v0.103.0
go.opentelemetry.io/collector/confmap v0.103.0
go.opentelemetry.io/collector/consumer v0.103.0
go.opentelemetry.io/collector/exporter v0.103.0
go.opentelemetry.io/collector/featuregate v1.10.0
go.opentelemetry.io/collector/pdata v1.10.0
go.opentelemetry.io/collector/semconv v0.103.0
go.opentelemetry.io/collector/semconv v0.116.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
go.uber.org/goleak v1.3.0
Expand Down
4 changes: 4 additions & 0 deletions exporter/awsxrayexporter/go.sum

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

7 changes: 2 additions & 5 deletions exporter/awsxrayexporter/internal/translator/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import (

"github.com/aws/aws-sdk-go/aws"
"go.opentelemetry.io/collector/pdata/pcommon"
conventionsV127 "go.opentelemetry.io/collector/semconv/v1.27.0"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

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

const (
AttributeTelemetryDistroVersion = "telemetry.distro.version"
)

func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, logGroupNames []string) (map[string]pcommon.Value, *awsxray.AWSData) {
var (
cloud string
Expand Down Expand Up @@ -94,7 +91,7 @@ func makeAws(attributes map[string]pcommon.Value, resource pcommon.Resource, log
sdkLanguage = value.Str()
case conventions.AttributeTelemetrySDKVersion:
sdkVersion = value.Str()
case conventions.AttributeTelemetryAutoVersion, AttributeTelemetryDistroVersion:
case conventions.AttributeTelemetryAutoVersion, conventionsV127.AttributeTelemetryDistroVersion:
autoVersion = value.Str()
case conventions.AttributeContainerID:
containerID = value.Str()
Expand Down
3 changes: 2 additions & 1 deletion exporter/awsxrayexporter/internal/translator/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
conventionsV127 "go.opentelemetry.io/collector/semconv/v1.27.0"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray"
Expand Down Expand Up @@ -366,7 +367,7 @@ func TestJavaAutoInstrumentationStable(t *testing.T) {
resource.Attributes().PutStr(conventions.AttributeTelemetrySDKName, "opentelemetry")
resource.Attributes().PutStr(conventions.AttributeTelemetrySDKLanguage, "java")
resource.Attributes().PutStr(conventions.AttributeTelemetrySDKVersion, "1.2.3")
resource.Attributes().PutStr(AttributeTelemetryDistroVersion, "3.4.5")
resource.Attributes().PutStr(conventionsV127.AttributeTelemetryDistroVersion, "3.4.5")

filtered, awsData := makeAws(attributes, resource, nil)

Expand Down
6 changes: 3 additions & 3 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
conventionsV127 "go.opentelemetry.io/collector/semconv/v1.27.0"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray"
Expand All @@ -24,7 +25,6 @@ import (
const ExceptionEventName = "exception"
const AwsIndividualHTTPEventName = "HTTP request failure"
const AwsIndividualHTTPErrorEventType = "aws.http.error.event"
const AwsIndividualHTTPErrorCodeAttr = "http.response.status_code"
const AwsIndividualHTTPErrorMsgAttr = "aws.http.error_message"

func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource pcommon.Resource) (isError, isFault, isThrottle bool,
Expand Down Expand Up @@ -88,7 +88,7 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
parsed := parseException(exceptionType, message, stacktrace, isRemote, language)
exceptions = append(exceptions, parsed...)
} else if isAwsSdkSpan && event.Name() == AwsIndividualHTTPEventName {
errorCode, ok1 := event.Attributes().Get(AwsIndividualHTTPErrorCodeAttr)
errorCode, ok1 := event.Attributes().Get(conventionsV127.AttributeHTTPResponseStatusCode)
errorMessage, ok2 := event.Attributes().Get(AwsIndividualHTTPErrorMsgAttr)
if ok1 && ok2 {
eventEpochTime := event.Timestamp().AsTime().UnixMicro()
Expand Down Expand Up @@ -151,7 +151,7 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p

val, ok := span.Attributes().Get(conventions.AttributeHTTPStatusCode)
if !ok {
val, ok = span.Attributes().Get(AwsIndividualHTTPErrorCodeAttr)
val, ok = span.Attributes().Get(conventionsV127.AttributeHTTPResponseStatusCode)
}

switch {
Expand Down
15 changes: 8 additions & 7 deletions exporter/awsxrayexporter/internal/translator/cause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
conventionsV127 "go.opentelemetry.io/collector/semconv/v1.27.0"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ func TestMakeCauseAwsSdkSpan(t *testing.T) {

event1 := span.Events().AppendEmpty()
event1.SetName(AwsIndividualHTTPEventName)
event1.Attributes().PutStr(AwsIndividualHTTPErrorCodeAttr, "503")
event1.Attributes().PutStr(conventionsV127.AttributeHTTPResponseStatusCode, "503")
event1.Attributes().PutStr(AwsIndividualHTTPErrorMsgAttr, "service is temporarily unavailable")
timestamp := pcommon.NewTimestampFromTime(time.UnixMicro(1696954761000001))
event1.SetTimestamp(timestamp)
Expand Down Expand Up @@ -201,7 +202,7 @@ func TestCauseWithStatusMessageStable(t *testing.T) {
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[AwsIndividualHTTPErrorCodeAttr] = 500
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 500
span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
span.Status().SetMessage(errorMsg)
filtered, _ := makeHTTP(span)
Expand Down Expand Up @@ -251,7 +252,7 @@ func TestCauseWithHttpStatusMessageStable(t *testing.T) {
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[AwsIndividualHTTPErrorCodeAttr] = 500
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 500
attributes["http.status_text"] = errorMsg
span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
filtered, _ := makeHTTP(span)
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestCauseWithZeroStatusMessageAndFaultHttpCodeStable(t *testing.T) {
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[AwsIndividualHTTPErrorCodeAttr] = 500
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 500
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeUnset)
Expand Down Expand Up @@ -417,7 +418,7 @@ func TestCauseWithZeroStatusMessageAndFaultErrorCodeStable(t *testing.T) {
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[AwsIndividualHTTPErrorCodeAttr] = 400
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 400
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeUnset)
Expand Down Expand Up @@ -462,7 +463,7 @@ func TestCauseWithClientErrorMessageStable(t *testing.T) {
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[AwsIndividualHTTPErrorCodeAttr] = 499
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 499
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
Expand Down Expand Up @@ -504,7 +505,7 @@ func TestCauseWithThrottledStable(t *testing.T) {
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[AwsIndividualHTTPErrorCodeAttr] = 429
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 429
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
Expand Down
43 changes: 15 additions & 28 deletions exporter/awsxrayexporter/internal/translator/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,12 @@ import (
"github.com/aws/aws-sdk-go/aws"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
conventionsV127 "go.opentelemetry.io/collector/semconv/v1.27.0"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

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

const (
AttributeHTTPRequestMethod = "http.request.method"
AttributeHTTPResponseStatusCode = "http.response.status_code"
AttributeServerAddress = "server.address"
AttributeServerPort = "server.port"
AttributeNetworkPeerAddress = "network.peer.address"
AttributeClientAddress = "client.address"
AttributeURLScheme = "url.scheme"
AttributeURLFull = "url.full"
AttributeURLPath = "url.path"
AttributeURLQuery = "url.query"
AttributeUserAgentOriginal = "user_agent.original"
)

func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
var (
info = awsxray.HTTPData{
Expand All @@ -49,30 +36,30 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {

span.Attributes().Range(func(key string, value pcommon.Value) bool {
switch key {
case conventions.AttributeHTTPMethod, AttributeHTTPRequestMethod:
case conventions.AttributeHTTPMethod, conventionsV127.AttributeHTTPRequestMethod:
info.Request.Method = awsxray.String(value.Str())
hasHTTP = true
case conventions.AttributeHTTPClientIP:
info.Request.ClientIP = awsxray.String(value.Str())
hasHTTP = true
case conventions.AttributeHTTPUserAgent, AttributeUserAgentOriginal:
case conventions.AttributeHTTPUserAgent, conventionsV127.AttributeUserAgentOriginal:
info.Request.UserAgent = awsxray.String(value.Str())
hasHTTP = true
case conventions.AttributeHTTPStatusCode, AttributeHTTPResponseStatusCode:
case conventions.AttributeHTTPStatusCode, conventionsV127.AttributeHTTPResponseStatusCode:
info.Response.Status = aws.Int64(value.Int())
hasHTTP = true
case conventions.AttributeHTTPURL, AttributeURLFull:
case conventions.AttributeHTTPURL, conventionsV127.AttributeURLFull:
urlParts[conventions.AttributeHTTPURL] = value.Str()
hasHTTP = true
hasHTTPRequestURLAttributes = true
case conventions.AttributeHTTPScheme, AttributeURLScheme:
case conventions.AttributeHTTPScheme, conventionsV127.AttributeURLScheme:
urlParts[conventions.AttributeHTTPScheme] = value.Str()
hasHTTP = true
case conventions.AttributeHTTPHost:
urlParts[key] = value.Str()
hasHTTP = true
hasHTTPRequestURLAttributes = true
case conventions.AttributeHTTPTarget, AttributeURLQuery:
case conventions.AttributeHTTPTarget, conventionsV127.AttributeURLQuery:
urlParts[conventions.AttributeHTTPTarget] = value.Str()
hasHTTP = true
case conventions.AttributeHTTPServerName:
Expand Down Expand Up @@ -107,7 +94,7 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
hasNetPeerAddr = true
case AttributeNetworkPeerAddress:
case conventionsV127.AttributeNetworkPeerAddress:
// Prefer HTTP forwarded information (AttributeHTTPClientIP) when present.
if net.ParseIP(value.Str()) != nil {
if info.Request.ClientIP == nil {
Expand All @@ -116,17 +103,17 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
hasHTTPRequestURLAttributes = true
hasNetPeerAddr = true
}
case AttributeClientAddress:
case conventionsV127.AttributeClientAddress:
if net.ParseIP(value.Str()) != nil {
info.Request.ClientIP = awsxray.String(value.Str())
}
case AttributeURLPath:
case conventionsV127.AttributeURLPath:
urlParts[key] = value.Str()
hasHTTP = true
case AttributeServerAddress:
case conventionsV127.AttributeServerAddress:
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
case AttributeServerPort:
case conventionsV127.AttributeServerPort:
urlParts[key] = value.Str()
if len(urlParts[key]) == 0 {
urlParts[key] = strconv.FormatInt(value.Int(), 10)
Expand Down Expand Up @@ -247,13 +234,13 @@ func constructServerURL(urlParts map[string]string) string {
if !ok {
host, ok = urlParts[conventions.AttributeHostName]
if !ok {
host = urlParts[AttributeServerAddress]
host = urlParts[conventionsV127.AttributeServerAddress]
}
}
}
port, ok = urlParts[conventions.AttributeNetHostPort]
if !ok {
port, ok = urlParts[AttributeServerPort]
port, ok = urlParts[conventionsV127.AttributeServerPort]
if !ok {
port = ""
}
Expand All @@ -267,7 +254,7 @@ func constructServerURL(urlParts map[string]string) string {
if ok {
url += target
} else {
path, ok := urlParts[AttributeURLPath]
path, ok := urlParts[conventionsV127.AttributeURLPath]
if ok {
url += path
} else {
Expand Down
Loading

0 comments on commit c176b07

Please sign in to comment.