diff --git a/module/apmazure/blob.go b/module/apmazure/blob.go index a3d8a43b1..e24d6d5ed 100644 --- a/module/apmazure/blob.go +++ b/module/apmazure/blob.go @@ -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 } diff --git a/module/apmazure/file.go b/module/apmazure/file.go index 9495885ea..f91e905b3 100644 --- a/module/apmazure/file.go +++ b/module/apmazure/file.go @@ -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 } diff --git a/module/apmazure/queue.go b/module/apmazure/queue.go index 228b82816..75738970d 100644 --- a/module/apmazure/queue.go +++ b/module/apmazure/queue.go @@ -30,6 +30,7 @@ type queueRPC struct { accountName string resourceName string req pipeline.Request + queueName string } func (q *queueRPC) name() string { @@ -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 } diff --git a/module/apmazure/queue_test.go b/module/apmazure/queue_test.go index d2aa278a9..9052519f3 100644 --- a/module/apmazure/queue_test.go +++ b/module/apmazure/queue_test.go @@ -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() @@ -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() @@ -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) { diff --git a/module/apmazure/storage.go b/module/apmazure/storage.go index b0a69e984..cddcdc5d9 100644 --- a/module/apmazure/storage.go +++ b/module/apmazure/storage.go @@ -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 { @@ -127,6 +131,7 @@ type azureRPC interface { name() string _type() string subtype() string + targetName() string storageAccountName() string resource() string operation() string @@ -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{ @@ -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 "" +}