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

Support new sematic conventions. #267

Merged
merged 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
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.

3 changes: 2 additions & 1 deletion exporter/awsxrayexporter/internal/translator/aws.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"
"go.opentelemetry.io/collector/pdata/pcommon"
conventionsV127 "go.opentelemetry.io/collector/semconv/v1.27.0"
zzhlogin marked this conversation as resolved.
Show resolved Hide resolved
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray"
Expand Down Expand Up @@ -90,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:
case conventions.AttributeTelemetryAutoVersion, conventionsV127.AttributeTelemetryDistroVersion:
autoVersion = value.Str()
case conventions.AttributeContainerID:
containerID = value.Str()
Expand Down
18 changes: 18 additions & 0 deletions 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 @@ -360,6 +361,23 @@ func TestJavaAutoInstrumentation(t *testing.T) {
assert.True(t, *awsData.XRay.AutoInstrumentation)
}

func TestJavaAutoInstrumentationStable(t *testing.T) {
attributes := make(map[string]pcommon.Value)
resource := pcommon.NewResource()
resource.Attributes().PutStr(conventionsV127.AttributeTelemetrySDKName, "opentelemetry")
resource.Attributes().PutStr(conventionsV127.AttributeTelemetrySDKLanguage, "java")
resource.Attributes().PutStr(conventionsV127.AttributeTelemetrySDKVersion, "1.2.3")
resource.Attributes().PutStr(conventionsV127.AttributeTelemetryDistroVersion, "3.4.5")

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

assert.NotNil(t, filtered)
assert.NotNil(t, awsData)
assert.Equal(t, "opentelemetry for java", *awsData.XRay.SDK)
assert.Equal(t, "1.2.3", *awsData.XRay.SDKVersion)
assert.True(t, *awsData.XRay.AutoInstrumentation)
}

func TestGoSDK(t *testing.T) {
attributes := make(map[string]pcommon.Value)
resource := pcommon.NewResource()
Expand Down
7 changes: 5 additions & 2 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 @@ -150,6 +150,9 @@ 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(conventionsV127.AttributeHTTPResponseStatusCode)
}

switch {
// The segment status for http spans will be based on their http.statuscode as we found some http
Expand Down
143 changes: 142 additions & 1 deletion 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 @@ -196,6 +197,31 @@ func TestCauseWithStatusMessage(t *testing.T) {
assert.True(t, strings.Contains(jsonStr, errorMsg))
}

func TestCauseWithStatusMessageStable(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
attributes[conventionsV127.AttributeHTTPRequestMethod] = "POST"
attributes[conventionsV127.AttributeURLFull] = "https://api.example.com/widgets"
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 500
span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
span.Status().SetMessage(errorMsg)
filtered, _ := makeHTTP(span)

res := pcommon.NewResource()
isError, isFault, isThrottle, filtered, cause := makeCause(span, filtered, res)

assert.True(t, isFault)
assert.False(t, isError)
assert.False(t, isThrottle)
assert.NotNil(t, filtered)
assert.NotNil(t, cause)
w := testWriters.borrow()
require.NoError(t, w.Encode(cause))
jsonStr := w.String()
testWriters.release(w)
assert.True(t, strings.Contains(jsonStr, errorMsg))
}

func TestCauseWithHttpStatusMessage(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
Expand All @@ -221,6 +247,31 @@ func TestCauseWithHttpStatusMessage(t *testing.T) {
assert.True(t, strings.Contains(jsonStr, errorMsg))
}

func TestCauseWithHttpStatusMessageStable(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
attributes[conventions.AttributeHTTPMethod] = "POST"
attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets"
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 500
attributes["http.status_text"] = errorMsg
span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
filtered, _ := makeHTTP(span)

res := pcommon.NewResource()
isError, isFault, isThrottle, filtered, cause := makeCause(span, filtered, res)

assert.True(t, isFault)
assert.False(t, isError)
assert.False(t, isThrottle)
assert.NotNil(t, filtered)
assert.NotNil(t, cause)
w := testWriters.borrow()
require.NoError(t, w.Encode(cause))
jsonStr := w.String()
testWriters.release(w)
assert.True(t, strings.Contains(jsonStr, errorMsg))
}

func TestCauseWithZeroStatusMessageAndFaultHttpCode(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
Expand All @@ -245,6 +296,30 @@ func TestCauseWithZeroStatusMessageAndFaultHttpCode(t *testing.T) {
assert.Nil(t, cause)
}

func TestCauseWithZeroStatusMessageAndFaultHttpCodeStable(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
attributes[conventionsV127.AttributeHTTPRequestMethod] = "POST"
attributes[conventionsV127.AttributeURLFull] = "https://api.example.com/widgets"
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 500
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeUnset)
filtered, _ := makeHTTP(span)
// Status is used to determine whether an error or not.
// This span illustrates incorrect instrumentation,
// marking a success status with an error http status code, and status wins.
// We do not expect to see such spans in practice.
res := pcommon.NewResource()
isError, isFault, isThrottle, filtered, cause := makeCause(span, filtered, res)

assert.False(t, isError)
assert.True(t, isFault)
assert.False(t, isThrottle)
assert.NotNil(t, filtered)
assert.Nil(t, cause)
}

func TestNonHttpUnsetCodeSpan(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
Expand Down Expand Up @@ -338,6 +413,30 @@ func TestCauseWithZeroStatusMessageAndFaultErrorCode(t *testing.T) {
assert.Nil(t, cause)
}

func TestCauseWithZeroStatusMessageAndFaultErrorCodeStable(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
attributes[conventionsV127.AttributeHTTPRequestMethod] = "POST"
attributes[conventionsV127.AttributeURLFull] = "https://api.example.com/widgets"
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 400
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeUnset)
filtered, _ := makeHTTP(span)
// Status is used to determine whether an error or not.
// This span illustrates incorrect instrumentation,
// marking a success status with an error http status code, and status wins.
// We do not expect to see such spans in practice.
res := pcommon.NewResource()
isError, isFault, isThrottle, filtered, cause := makeCause(span, filtered, res)

assert.True(t, isError)
assert.False(t, isFault)
assert.False(t, isThrottle)
assert.NotNil(t, filtered)
assert.Nil(t, cause)
}

func TestCauseWithClientErrorMessage(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
Expand All @@ -359,6 +458,27 @@ func TestCauseWithClientErrorMessage(t *testing.T) {
assert.NotNil(t, cause)
}

func TestCauseWithClientErrorMessageStable(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
attributes[conventionsV127.AttributeHTTPRequestMethod] = "POST"
attributes[conventionsV127.AttributeURLFull] = "https://api.example.com/widgets"
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 499
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
filtered, _ := makeHTTP(span)

res := pcommon.NewResource()
isError, isFault, isThrottle, filtered, cause := makeCause(span, filtered, res)

assert.True(t, isError)
assert.False(t, isFault)
assert.False(t, isThrottle)
assert.NotNil(t, filtered)
assert.NotNil(t, cause)
}

func TestCauseWithThrottled(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
Expand All @@ -380,6 +500,27 @@ func TestCauseWithThrottled(t *testing.T) {
assert.NotNil(t, cause)
}

func TestCauseWithThrottledStable(t *testing.T) {
errorMsg := "this is a test"
attributes := make(map[string]any)
attributes[conventionsV127.AttributeHTTPRequestMethod] = "POST"
attributes[conventionsV127.AttributeURLFull] = "https://api.example.com/widgets"
attributes[conventionsV127.AttributeHTTPResponseStatusCode] = 429
attributes["http.status_text"] = errorMsg

span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError)
filtered, _ := makeHTTP(span)

res := pcommon.NewResource()
isError, isFault, isThrottle, filtered, cause := makeCause(span, filtered, res)

assert.True(t, isError)
assert.False(t, isFault)
assert.True(t, isThrottle)
assert.NotNil(t, filtered)
assert.NotNil(t, cause)
}

func constructExceptionServerSpan(attributes map[string]any, statuscode ptrace.StatusCode) ptrace.Span {
endTime := time.Now().Round(time.Second)
startTime := endTime.Add(-90 * time.Second)
Expand Down
Loading