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

Update to use latest semantic convention attribute names #108

Merged
merged 4 commits into from
Jan 29, 2020
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
2 changes: 1 addition & 1 deletion exporter/awsxrayexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
// TODO: pin a released version
github.com/open-telemetry/opentelemetry-collector v0.2.2
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200127212148-c4458c722b19
github.com/stretchr/testify v1.4.0
go.uber.org/zap v1.10.0
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
Expand Down
4 changes: 4 additions & 0 deletions exporter/awsxrayexporter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/open-telemetry/opentelemetry-collector v0.2.2 h1:fByPHI/xDbTw3X36/OiEr30Hu69/Xdwd4SEdy1WrIIY=
github.com/open-telemetry/opentelemetry-collector v0.2.2/go.mod h1:WxiK9mcisb/hM6M6+2BRV/VIU2c8VzlCRJED2S1MWns=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200123195845-9ecbe7589868 h1:tA6L7XXITw++T3iU5R5FIqc8kajx3gTn/Kh3Cx4ERkQ=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200123195845-9ecbe7589868/go.mod h1:QQpcOiQiiE1Jwsbp9HlJMRHy9gnPtBVFoONFJ5A1eis=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200127212148-c4458c722b19 h1:sBb4GnuXdznEBKLputJtGQrQCHxOfjAVXXWUb5I/zr4=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200127212148-c4458c722b19/go.mod h1:QQpcOiQiiE1Jwsbp9HlJMRHy9gnPtBVFoONFJ5A1eis=
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9 h1:QsgXACQhd9QJhEmRumbsMQQvBtmdS0mafoVEBplWXEg=
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
Expand Down
19 changes: 8 additions & 11 deletions exporter/awsxrayexporter/translator/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func makeHTTP(span *tracepb.Span) (map[string]string, *HTTPData) {
case semconventions.AttributeHTTPClientIP:
info.Request.ClientIP = value.GetStringValue().GetValue()
info.Request.XForwardedFor = true
case semconventions.AttributeHTTPUserAgent:
info.Request.UserAgent = value.GetStringValue().GetValue()
case semconventions.AttributeHTTPStatusCode:
info.Response.Status = value.GetIntValue()
case semconventions.AttributeHTTPURL:
Expand All @@ -81,16 +83,14 @@ func makeHTTP(span *tracepb.Span) (map[string]string, *HTTPData) {
if len(urlParts[key]) == 0 {
urlParts[key] = strconv.FormatInt(value.GetIntValue(), 10)
}
case semconventions.AttributePeerHost:
case semconventions.AttributeNetPeerName:
urlParts[key] = value.GetStringValue().GetValue()
case semconventions.AttributePeerPort:
case semconventions.AttributeNetPeerPort:
urlParts[key] = value.GetStringValue().GetValue()
if len(urlParts[key]) == 0 {
urlParts[key] = strconv.FormatInt(value.GetIntValue(), 10)
}
case semconventions.AttributePeerIpv4:
urlParts[key] = value.GetStringValue().GetValue()
case semconventions.AttributePeerIpv6:
case semconventions.AttributeNetPeerIP:
urlParts[key] = value.GetStringValue().GetValue()
default:
filtered[key] = value.GetStringValue().GetValue()
Expand Down Expand Up @@ -159,14 +159,11 @@ func constructClientURL(component string, urlParts map[string]string) string {
port := ""
host, ok := urlParts[semconventions.AttributeHTTPHost]
if !ok {
host, ok = urlParts[semconventions.AttributePeerHost]
host, ok = urlParts[semconventions.AttributeNetPeerName]
if !ok {
host, ok = urlParts[semconventions.AttributePeerIpv4]
if !ok {
host = urlParts[semconventions.AttributePeerIpv6]
}
host = urlParts[semconventions.AttributeNetPeerIP]
}
port, ok = urlParts[semconventions.AttributePeerPort]
port, ok = urlParts[semconventions.AttributeNetPeerPort]
if !ok {
port = ""
}
Expand Down
15 changes: 8 additions & 7 deletions exporter/awsxrayexporter/translator/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func TestClientSpanWithPeerAttributes(t *testing.T) {
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeHTTP
attributes[semconventions.AttributeHTTPMethod] = "GET"
attributes[semconventions.AttributeHTTPScheme] = "http"
attributes[semconventions.AttributePeerHost] = "kb234.example.com"
attributes[semconventions.AttributePeerPort] = 8080
attributes[semconventions.AttributePeerIpv4] = "10.8.17.36"
attributes[semconventions.AttributeNetPeerName] = "kb234.example.com"
attributes[semconventions.AttributeNetPeerPort] = 8080
attributes[semconventions.AttributeNetPeerIP] = "10.8.17.36"
attributes[semconventions.AttributeHTTPTarget] = "/users/junit"
attributes[semconventions.AttributeHTTPStatusCode] = 200
span := constructHTTPClientSpan(attributes)
Expand All @@ -101,8 +101,8 @@ func TestClientSpanWithPeerIp4Attributes(t *testing.T) {
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeHTTP
attributes[semconventions.AttributeHTTPMethod] = "GET"
attributes[semconventions.AttributeHTTPScheme] = "http"
attributes[semconventions.AttributePeerIpv4] = "10.8.17.36"
attributes[semconventions.AttributePeerPort] = "8080"
attributes[semconventions.AttributeNetPeerIP] = "10.8.17.36"
attributes[semconventions.AttributeNetPeerPort] = "8080"
attributes[semconventions.AttributeHTTPTarget] = "/users/junit"
span := constructHTTPClientSpan(attributes)

Expand All @@ -123,8 +123,8 @@ func TestClientSpanWithPeerIp6Attributes(t *testing.T) {
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeHTTP
attributes[semconventions.AttributeHTTPMethod] = "GET"
attributes[semconventions.AttributeHTTPScheme] = "https"
attributes[semconventions.AttributePeerIpv6] = "2001:db8:85a3::8a2e:370:7334"
attributes[semconventions.AttributePeerPort] = "443"
attributes[semconventions.AttributeNetPeerIP] = "2001:db8:85a3::8a2e:370:7334"
attributes[semconventions.AttributeNetPeerPort] = "443"
attributes[semconventions.AttributeHTTPTarget] = "/users/junit"
span := constructHTTPClientSpan(attributes)

Expand All @@ -146,6 +146,7 @@ func TestServerSpanWithURLAttribute(t *testing.T) {
attributes[semconventions.AttributeHTTPMethod] = "GET"
attributes[semconventions.AttributeHTTPURL] = "https://api.example.com/users/junit"
attributes[semconventions.AttributeHTTPClientIP] = "192.168.15.32"
attributes[semconventions.AttributeHTTPUserAgent] = "PostmanRuntime/7.21.0"
attributes[semconventions.AttributeHTTPStatusCode] = 200
span := constructHTTPServerSpan(attributes)

Expand Down
16 changes: 11 additions & 5 deletions exporter/awsxrayexporter/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func MakeSegment(name string, span *tracepb.Span) Segment {
awsfiltered, aws = makeAws(causefiltered, span.Resource)
service = makeService(span.Resource)
sqlfiltered, sql = makeSQL(awsfiltered)
annotations = makeAnnotations(sqlfiltered)
user, annotations = makeAnnotations(sqlfiltered)
namespace string
)

Expand All @@ -151,6 +151,7 @@ func MakeSegment(name string, span *tracepb.Span) Segment {
Cause: cause,
Origin: origin,
Namespace: namespace,
User: user,
HTTP: http,
AWS: aws,
Service: service,
Expand Down Expand Up @@ -273,18 +274,23 @@ func sanitizeAndTransferAnnotations(dest map[string]interface{}, src map[string]
}
}

func makeAnnotations(attributes map[string]string) map[string]interface{} {
func makeAnnotations(attributes map[string]string) (string, map[string]interface{}) {
var (
result = map[string]interface{}{}
user string
)

delete(attributes, semconventions.AttributeComponent)
userid, ok := attributes[semconventions.AttributeEnduserID]
if ok {
user = userid
delete(attributes, semconventions.AttributeEnduserID)
}
sanitizeAndTransferAnnotations(result, attributes)

if len(result) == 0 {
return nil
return user, nil
}
return result
return user, result
}

// fixSegmentName removes any invalid characters from the span name. AWS X-Ray defines
Expand Down
21 changes: 14 additions & 7 deletions exporter/awsxrayexporter/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestClientSpanWithGrpcComponent(t *testing.T) {
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeGRPC
attributes[semconventions.AttributeHTTPMethod] = "GET"
attributes[semconventions.AttributeHTTPScheme] = "ipv6"
attributes[semconventions.AttributePeerIpv6] = "2607:f8b0:4000:80c::2004"
attributes[semconventions.AttributePeerPort] = "9443"
attributes[semconventions.AttributeNetPeerIP] = "2607:f8b0:4000:80c::2004"
attributes[semconventions.AttributeNetPeerPort] = "9443"
attributes[semconventions.AttributeHTTPTarget] = spanName
labels := constructDefaultResourceLabels()
span := constructClientSpan(nil, spanName, 0, "OK", attributes, labels)
Expand Down Expand Up @@ -83,13 +83,17 @@ func TestServerSpanWithInternalServerError(t *testing.T) {
spanName := "/api/locations"
parentSpanID := newSegmentID()
errorMessage := "java.lang.NullPointerException"
userAgent := "PostmanRuntime/7.21.0"
enduser := "[email protected]"
attributes := make(map[string]interface{})
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeHTTP
attributes[semconventions.AttributeHTTPMethod] = "POST"
attributes[semconventions.AttributeHTTPURL] = "https://api.example.org/api/locations"
attributes[semconventions.AttributeHTTPTarget] = "/api/locations"
attributes[semconventions.AttributeHTTPStatusCode] = 500
attributes[semconventions.AttributeHTTPStatusText] = "java.lang.NullPointerException"
attributes[semconventions.AttributeHTTPUserAgent] = userAgent
attributes[semconventions.AttributeEnduserID] = enduser
labels := constructDefaultResourceLabels()
span := constructServerSpan(parentSpanID, spanName, tracetranslator.OCInternal, errorMessage, attributes, labels)
timeEvents := constructTimedEventsWithSentMessageEvent(span.StartTime)
Expand All @@ -109,6 +113,8 @@ func TestServerSpanWithInternalServerError(t *testing.T) {
testWriters.release(w)
assert.True(t, strings.Contains(jsonStr, spanName))
assert.True(t, strings.Contains(jsonStr, errorMessage))
assert.True(t, strings.Contains(jsonStr, userAgent))
assert.True(t, strings.Contains(jsonStr, enduser))
}

func TestClientSpanWithDbComponent(t *testing.T) {
Expand All @@ -120,9 +126,9 @@ func TestClientSpanWithDbComponent(t *testing.T) {
attributes[semconventions.AttributeDBInstance] = "customers"
attributes[semconventions.AttributeDBStatement] = spanName
attributes[semconventions.AttributeDBUser] = "userprefsvc"
attributes[semconventions.AttributePeerAddress] = "mysql://db.dev.example.com:3306"
attributes[semconventions.AttributePeerHost] = "db.dev.example.com"
attributes[semconventions.AttributePeerPort] = "3306"
attributes[semconventions.AttributeDBURL] = "mysql://db.dev.example.com:3306"
attributes[semconventions.AttributeNetPeerName] = "db.dev.example.com"
attributes[semconventions.AttributeNetPeerPort] = "3306"
attributes["enterprise.app.id"] = enterpriseAppID
labels := constructDefaultResourceLabels()
span := constructClientSpan(nil, spanName, 0, "OK", attributes, labels)
Expand Down Expand Up @@ -155,8 +161,8 @@ func TestSpanWithInvalidTraceId(t *testing.T) {
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeGRPC
attributes[semconventions.AttributeHTTPMethod] = "GET"
attributes[semconventions.AttributeHTTPScheme] = "ipv6"
attributes[semconventions.AttributePeerIpv6] = "2607:f8b0:4000:80c::2004"
attributes[semconventions.AttributePeerPort] = "9443"
attributes[semconventions.AttributeNetPeerIP] = "2607:f8b0:4000:80c::2004"
attributes[semconventions.AttributeNetPeerPort] = "9443"
attributes[semconventions.AttributeHTTPTarget] = spanName
labels := constructDefaultResourceLabels()
span := constructClientSpan(nil, spanName, 0, "OK", attributes, labels)
Expand Down Expand Up @@ -283,6 +289,7 @@ func constructSpanAttributes(attributes map[string]interface{}) map[string]*trac
func constructDefaultResourceLabels() map[string]string {
labels := make(map[string]string)
labels[semconventions.AttributeServiceName] = "signup_aggregator"
labels[semconventions.AttributeServiceVersion] = "semver:1.1.4"
labels[semconventions.AttributeContainerName] = "signup_aggregator"
labels[semconventions.AttributeContainerImage] = "otel/signupaggregator"
labels[semconventions.AttributeContainerTag] = "v1"
Expand Down
13 changes: 5 additions & 8 deletions exporter/awsxrayexporter/translator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ type ServiceData struct {

func makeService(resource *resourcepb.Resource) *ServiceData {
var (
ver string
service *ServiceData
)
if resource == nil {
return service
}
for key, value := range resource.Labels {
switch key {
case semconventions.AttributeContainerTag:
ver = value
}
verStr, ok := resource.Labels[semconventions.AttributeServiceVersion]
if !ok {
verStr = resource.Labels[semconventions.AttributeContainerTag]
}
if ver != "" {
if verStr != "" {
service = &ServiceData{
Version: ver,
Version: verStr,
}
}
return service
Expand Down
19 changes: 19 additions & 0 deletions exporter/awsxrayexporter/translator/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
semconventions "github.com/open-telemetry/opentelemetry-collector/translator/conventions"
"github.com/stretchr/testify/assert"
)

Expand All @@ -30,6 +31,24 @@ func TestServiceFromResource(t *testing.T) {

service := makeService(resource)

assert.NotNil(t, service)
w := testWriters.borrow()
if err := w.Encode(service); err != nil {
assert.Fail(t, "invalid json")
}
jsonStr := w.String()
testWriters.release(w)
assert.True(t, strings.Contains(jsonStr, "semver:1.1.4"))
}

func TestServiceFromResourceWithNoServiceVersion(t *testing.T) {
resource := &resourcepb.Resource{
Type: "container",
Labels: constructDefaultResourceLabels(),
}
delete(resource.Labels, semconventions.AttributeServiceVersion)
service := makeService(resource)

assert.NotNil(t, service)
w := testWriters.borrow()
if err := w.Encode(service); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exporter/awsxrayexporter/translator/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func makeSQL(attributes map[string]string) (map[string]string, *SQLData) {
}
for key, value := range attributes {
switch key {
case semconventions.AttributePeerAddress:
case semconventions.AttributeDBURL:
dbURL = value
case semconventions.AttributeDBType:
dbType = value
Expand Down
12 changes: 6 additions & 6 deletions exporter/awsxrayexporter/translator/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestClientSpanWithStatementAttribute(t *testing.T) {
attributes[semconventions.AttributeDBInstance] = "customers"
attributes[semconventions.AttributeDBStatement] = "SELECT * FROM user WHERE user_id = ?"
attributes[semconventions.AttributeDBUser] = "readonly_user"
attributes[semconventions.AttributePeerAddress] = "mysql://db.example.com:3306"
attributes[semconventions.AttributePeerHost] = "db.example.com"
attributes[semconventions.AttributePeerPort] = "3306"
attributes[semconventions.AttributeDBURL] = "mysql://db.example.com:3306"
attributes[semconventions.AttributeNetPeerName] = "db.example.com"
attributes[semconventions.AttributeNetPeerPort] = "3306"

filtered, sqlData := makeSQL(attributes)

Expand All @@ -53,9 +53,9 @@ func TestClientSpanWithHttpComponent(t *testing.T) {
attributes[semconventions.AttributeDBInstance] = "customers"
attributes[semconventions.AttributeDBStatement] = "SELECT * FROM user WHERE user_id = ?"
attributes[semconventions.AttributeDBUser] = "readonly_user"
attributes[semconventions.AttributePeerAddress] = "mysql://db.example.com:3306"
attributes[semconventions.AttributePeerHost] = "db.example.com"
attributes[semconventions.AttributePeerPort] = "3306"
attributes[semconventions.AttributeDBURL] = "mysql://db.example.com:3306"
attributes[semconventions.AttributeNetPeerName] = "db.example.com"
attributes[semconventions.AttributeNetPeerPort] = "3306"

filtered, sqlData := makeSQL(attributes)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/client9/misspell v0.3.4
github.com/google/addlicense v0.0.0-20190907113143-be125746c2c4
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200122010738-1a92a7ea5aea
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200127212148-c4458c722b19
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter v0.0.0-20200116182905-41c032071dce
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kinesisexporter v0.0.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200115225140-264426
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200115225140-264426a9cae4/go.mod h1:WxiK9mcisb/hM6M6+2BRV/VIU2c8VzlCRJED2S1MWns=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200122010738-1a92a7ea5aea h1:K6rD+EfYyeggEm5e0kSVPd4eTNl0ru8geKc+MCHnaqg=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200122010738-1a92a7ea5aea/go.mod h1:WxiK9mcisb/hM6M6+2BRV/VIU2c8VzlCRJED2S1MWns=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200123195845-9ecbe7589868 h1:tA6L7XXITw++T3iU5R5FIqc8kajx3gTn/Kh3Cx4ERkQ=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200123195845-9ecbe7589868/go.mod h1:QQpcOiQiiE1Jwsbp9HlJMRHy9gnPtBVFoONFJ5A1eis=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200127212148-c4458c722b19 h1:sBb4GnuXdznEBKLputJtGQrQCHxOfjAVXXWUb5I/zr4=
github.com/open-telemetry/opentelemetry-collector v0.2.4-0.20200127212148-c4458c722b19/go.mod h1:QQpcOiQiiE1Jwsbp9HlJMRHy9gnPtBVFoONFJ5A1eis=
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
2 changes: 1 addition & 1 deletion testbed/tests/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestTrace10kSPS(t *testing.T) {
testbed.NewOCTraceDataSender(testbed.GetAvailablePort(t)),
testbed.NewOCDataReceiver(testbed.GetAvailablePort(t)),
testbed.ResourceSpec{
ExpectedMaxCPU: 40,
ExpectedMaxCPU: 42,
ExpectedMaxRAM: 71,
},
},
Expand Down