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

Set all azcosmos telemetry spans to have the Kind of SpanKindClient #23618

Merged
merged 2 commits into from
Oct 23, 2024
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
1 change: 1 addition & 0 deletions sdk/data/azcosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.1.1 (Unreleased)

### Features Added
* Set all Telemetry spans to have the Kind of SpanKindClient

### Breaking Changes

Expand Down
4 changes: 2 additions & 2 deletions sdk/data/azcosmos/cosmos_item_request_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ type ItemOptions struct {
func (options *ItemOptions) toHeaders() *map[string]string {
headers := make(map[string]string)

if options.PreTriggers != nil && len(options.PreTriggers) > 0 {
if len(options.PreTriggers) > 0 {
headers[cosmosHeaderPreTriggerInclude] = strings.Join(options.PreTriggers, ",")
}

if options.PostTriggers != nil && len(options.PostTriggers) > 0 {
if len(options.PostTriggers) > 0 {
headers[cosmosHeaderPostTriggerInclude] = strings.Join(options.PostTriggers, ",")
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/data/azcosmos/cosmos_location_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestGetLocation(t *testing.T) {
if err != nil {
t.Fatalf("Received error Reading DB account: %s", err.Error())
}
if dbAcct.WriteRegions == nil || len(dbAcct.WriteRegions) == 0 {
if len(dbAcct.WriteRegions) == 0 {
t.Fatal("Write Regions are empty")
}
actual := lc.getLocation(*defaultEndpoint)
Expand Down
10 changes: 5 additions & 5 deletions sdk/data/azcosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0
github.com/stretchr/testify v1.9.0
Expand All @@ -18,9 +18,9 @@ require (
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions sdk/data/azcosmos/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0 h1:nyQWyZvwGTvunIMxi1Y9uXkcyr+I7TeNrr/foo4Kpk8=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0/go.mod h1:l38EPgmsp71HHLq9j7De57JcKOWPyhrsW1Awm1JS6K0=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0/go.mod h1:YL1xnZ6QejvQHWJrX/AvhFl4WW4rqHVoKspWNVwFk0M=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH5sE0o6eCJuNDTmH09nDpbc=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=
Expand All @@ -28,15 +28,15 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
51 changes: 30 additions & 21 deletions sdk/data/azcosmos/otel_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ func getSpanNameForItems(endpoint *url.URL, operationType operationType, databas
}

func getSpanPropertiesForClient(endpoint *url.URL, operationName string) runtime.StartSpanOptions {
options := runtime.StartSpanOptions{Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
}}
options := runtime.StartSpanOptions{
Kind: tracing.SpanKindClient,
Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
},
}

if endpoint.Port() != "443" {
options.Attributes = append(options.Attributes, tracing.Attribute{Key: "server.port", Value: endpoint.Port()})
Expand All @@ -158,13 +161,16 @@ func getSpanPropertiesForClient(endpoint *url.URL, operationName string) runtime
}

func getSpanPropertiesForDatabase(endpoint *url.URL, operationName string, id string) runtime.StartSpanOptions {
options := runtime.StartSpanOptions{Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.namespace", Value: id},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
}}
options := runtime.StartSpanOptions{
Kind: tracing.SpanKindClient,
Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.namespace", Value: id},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
},
}

if endpoint.Port() != "443" {
options.Attributes = append(options.Attributes, tracing.Attribute{Key: "server.port", Value: endpoint.Port()})
Expand All @@ -174,14 +180,17 @@ func getSpanPropertiesForDatabase(endpoint *url.URL, operationName string, id st
}

func getSpanPropertiesForContainer(endpoint *url.URL, operationName string, database string, id string) runtime.StartSpanOptions {
options := runtime.StartSpanOptions{Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.namespace", Value: database},
{Key: "db.collection.name", Value: id},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
}}
options := runtime.StartSpanOptions{
Kind: tracing.SpanKindClient,
Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.namespace", Value: database},
{Key: "db.collection.name", Value: id},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
},
}

if endpoint.Port() != "443" {
options.Attributes = append(options.Attributes, tracing.Attribute{Key: "server.port", Value: endpoint.Port()})
Expand Down
15 changes: 15 additions & 0 deletions sdk/data/azcosmos/otel_constants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func TestSpanForClient(t *testing.T) {
if aSpan.name != "query_databases test" {
t.Fatalf("Expected span name to be 'query_databases test', but got %s", aSpan.name)
}

if aSpan.options.Kind != tracing.SpanKindClient {
t.Fatalf("Expected span kind to be 'SpanKindClient (%v)', got %v", tracing.SpanKindClient, aSpan.options.Kind)
}

if len(aSpan.options.Attributes) == 0 {
t.Fatalf("Expected span options to have attributes, but got none")
}
Expand Down Expand Up @@ -64,6 +69,11 @@ func TestSpanForDatabases(t *testing.T) {
if aSpan.name != "create_database test" {
t.Fatalf("Expected span name to be 'create_database test', but got %s", aSpan.name)
}

if aSpan.options.Kind != tracing.SpanKindClient {
t.Fatalf("Expected span kind to be 'SpanKindClient (%v)', got %v", tracing.SpanKindClient, aSpan.options.Kind)
}

if len(aSpan.options.Attributes) == 0 {
t.Fatalf("Expected span options to have attributes, but got none")
}
Expand Down Expand Up @@ -113,6 +123,11 @@ func TestSpanForContainers(t *testing.T) {
if aSpan.name != "create_container test" {
t.Fatalf("Expected span name to be 'create_container test', but got %s", aSpan.name)
}

if aSpan.options.Kind != tracing.SpanKindClient {
t.Fatalf("Expected span kind to be 'SpanKindClient (%v)', got %v", tracing.SpanKindClient, aSpan.options.Kind)
}

if len(aSpan.options.Attributes) == 0 {
t.Fatalf("Expected span options to have attributes, but got none")
}
Expand Down