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

feat: add service target fields support to azure module #1280

Merged
merged 9 commits into from
Aug 1, 2022
4 changes: 4 additions & 0 deletions module/apmazure/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (b *blobRPC) subtype() string {
return "azureblob"
}

func (b *blobRPC) targetName() string {
return ""
}

func (b *blobRPC) storageAccountName() string {
return b.accountName
}
Expand Down
4 changes: 4 additions & 0 deletions module/apmazure/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (f *fileRPC) subtype() string {
return "azurefile"
}

func (f *fileRPC) targetName() string {
return ""
}

func (f *fileRPC) storageAccountName() string {
return f.accountName
}
Expand Down
5 changes: 5 additions & 0 deletions module/apmazure/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type queueRPC struct {
accountName string
resourceName string
req pipeline.Request
queueName string
}

func (q *queueRPC) name() string {
Expand All @@ -44,6 +45,10 @@ func (q *queueRPC) subtype() string {
return "azurequeue"
}

func (q *queueRPC) targetName() string {
return q.queueName
}

func (q *queueRPC) storageAccountName() string {
return q.accountName
}
Expand Down
8 changes: 6 additions & 2 deletions module/apmazure/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

func TestQueueSend(t *testing.T) {
p := WrapPipeline(queuePipeline())
u, err := url.Parse("https://fakeaccnt.queue.core.windows.net")
u, err := url.Parse("https://fakeaccnt.queue.core.windows.net/myqueue")
require.NoError(t, err)
queueURL := azqueue.NewQueueURL(*u, p)
msgURL := queueURL.NewMessagesURL()
Expand All @@ -55,13 +55,15 @@ func TestQueueSend(t *testing.T) {
assert.Equal(t, "fakeaccnt.queue.core.windows.net", destination.Address)
assert.Equal(t, 443, destination.Port)
assert.Equal(t, "azurequeue/fakeaccnt", destination.Service.Resource)
assert.Equal(t, "azurequeue", span.Context.Service.Target.Type)
assert.Equal(t, "myqueue", span.Context.Service.Target.Name)
}

func TestQueueReceive(t *testing.T) {
tracer, transport := transporttest.NewRecorderTracer()
defer tracer.Close()
p := WrapPipeline(queuePipeline(), WithTracer(tracer))
u, err := url.Parse("https://fakeaccnt.queue.core.windows.net")
u, err := url.Parse("https://fakeaccnt.queue.core.windows.net/myqueue")
require.NoError(t, err)
queueURL := azqueue.NewQueueURL(*u, p)
msgURL := queueURL.NewMessagesURL()
Expand All @@ -86,6 +88,8 @@ func TestQueueReceive(t *testing.T) {
assert.Equal(t, "fakeaccnt.queue.core.windows.net", destination.Address)
assert.Equal(t, 443, destination.Port)
assert.Equal(t, "azurequeue/fakeaccnt", destination.Service.Resource)
assert.Equal(t, "azurequeue", span.Context.Service.Target.Type)
assert.Equal(t, "myqueue", span.Context.Service.Target.Name)
}

func TestQueueGetOperation(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions module/apmazure/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (p *apmPipeline) Do(
span.Context.SetDestinationService(apm.DestinationServiceSpanContext{
Resource: rpc.subtype() + "/" + rpc.storageAccountName(),
})
span.Context.SetServiceTarget(apm.ServiceTargetSpanContext{
Type: rpc.subtype(),
Name: rpc.targetName(),
})

resp, err := p.next.Do(ctx, methodFactory, req)
if err != nil {
Expand All @@ -127,6 +131,7 @@ type azureRPC interface {
name() string
_type() string
subtype() string
targetName() string
storageAccountName() string
resource() string
operation() string
Expand All @@ -144,10 +149,12 @@ func newAzureRPC(req pipeline.Request) (azureRPC, error) {
req: req,
}
case "queue":

rpc = &queueRPC{
resourceName: strings.TrimPrefix(req.URL.Path, "/"),
accountName: accountName,
req: req,
queueName: queueNameFromURL(req.URL.Path),
}
case "file":
rpc = &fileRPC{
Expand All @@ -162,3 +169,11 @@ func newAzureRPC(req pipeline.Request) (azureRPC, error) {

return rpc, nil
}

func queueNameFromURL(urlPath string) string {
urlPath = strings.TrimPrefix(urlPath, "/")
if i := strings.Index(urlPath, "/"); i >= 0 {
return urlPath[:i]
}
return ""
}