Skip to content

Commit e251068

Browse files
committed
fix wrong destination nesting reported in #1088 and #1089
1 parent f6ba092 commit e251068

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

elasticapm/instrumentation/packages/botocore.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def handle_s3(operation_name, service, instance, args, kwargs, context):
9696
bucket = ""
9797
signature = f"S3 {operation_name} {bucket}"
9898

99-
context["destination"]["name"] = span_subtype
100-
context["destination"]["resource"] = bucket
101-
context["destination"]["service"] = {"type": span_type}
99+
context["destination"]["service"] = {"name": span_subtype, "resource": bucket, "type": span_type}
102100

103101
return HandlerInfo(signature, span_type, span_subtype, span_action, context)
104102

@@ -117,9 +115,7 @@ def handle_dynamodb(operation_name, service, instance, args, kwargs, context):
117115
if operation_name == "Query" and len(args) > 1 and "KeyConditionExpression" in args[1]:
118116
context["db"]["statement"] = args[1]["KeyConditionExpression"]
119117

120-
context["destination"]["name"] = span_subtype
121-
context["destination"]["resource"] = table
122-
context["destination"]["service"] = {"type": span_type}
118+
context["destination"]["service"] = {"name": span_subtype, "resource": table, "type": span_type}
123119
return HandlerInfo(signature, span_type, span_subtype, span_action, context)
124120

125121

@@ -137,9 +133,11 @@ def handle_sns(operation_name, service, instance, args, kwargs, context):
137133
if "TopicArn" in args[1]:
138134
topic_name = args[1]["TopicArn"].rsplit(":", maxsplit=1)[-1]
139135
signature = f"SNS {operation_name} {topic_name}".rstrip()
140-
context["destination"]["name"] = span_subtype
141-
context["destination"]["resource"] = f"{span_subtype}/{topic_name}" if topic_name else span_subtype
142-
context["destination"]["type"] = span_type
136+
context["destination"]["service"] = {
137+
"name": span_subtype,
138+
"resource": f"{span_subtype}/{topic_name}" if topic_name else span_subtype,
139+
"type": span_type,
140+
}
143141
return HandlerInfo(signature, span_type, span_subtype, span_action, context)
144142

145143

@@ -152,6 +150,8 @@ def handle_default(operation_name, service, instance, args, kwargs, destination)
152150
span_subtype = service.lower()
153151
span_action = operation_name
154152

153+
destination["service"] = {"name": span_subtype, "resource": span_subtype, "type": span_type}
154+
155155
signature = f"{service}:{operation_name}"
156156
return HandlerInfo(signature, span_type, span_subtype, span_action, destination)
157157

tests/instrumentation/botocore_tests.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def test_s3(instrument, elasticapm_client):
104104
assert span["context"]["destination"]["address"] == LOCALSTACK_ENDPOINT_URL.hostname
105105
assert span["context"]["destination"]["port"] == LOCALSTACK_ENDPOINT_URL.port
106106
assert span["context"]["destination"]["cloud"]["region"] == "us-east-1"
107-
assert span["context"]["destination"]["name"] == "s3"
108-
assert span["context"]["destination"]["resource"] == "xyz"
107+
assert span["context"]["destination"]["service"]["name"] == "s3"
108+
assert span["context"]["destination"]["service"]["resource"] == "xyz"
109109
assert span["context"]["destination"]["service"]["type"] == "storage"
110110
assert spans[0]["name"] == "S3 CreateBucket xyz"
111111
assert spans[0]["action"] == "CreateBucket"
@@ -162,9 +162,9 @@ def test_dynamodb(instrument, elasticapm_client, dynamodb):
162162
assert span["context"]["destination"]["address"] == LOCALSTACK_ENDPOINT_URL.hostname
163163
assert span["context"]["destination"]["port"] == LOCALSTACK_ENDPOINT_URL.port
164164
assert span["context"]["destination"]["cloud"]["region"] == "us-east-1"
165-
assert span["context"]["destination"]["name"] == "dynamodb"
166-
# assert span["context"]["destination"]["resource"] == "xyz"
167-
# assert span["context"]["destination"]["service"]["type"] == "storage"
165+
assert span["context"]["destination"]["service"]["name"] == "dynamodb"
166+
assert span["context"]["destination"]["service"]["resource"] == "Movies"
167+
assert span["context"]["destination"]["service"]["type"] == "db"
168168
assert spans[0]["name"] == "DynamoDB PutItem Movies"
169169
assert spans[1]["name"] == "DynamoDB Query Movies"
170170
assert spans[1]["context"]["db"]["statement"] == "title = :v1 and #y = :v2"
@@ -184,3 +184,9 @@ def test_sns(instrument, elasticapm_client):
184184
assert spans[2]["type"] == "messaging"
185185
assert spans[2]["subtype"] == "sns"
186186
assert spans[2]["action"] == "send"
187+
assert spans[2]["context"]["destination"]["address"] == LOCALSTACK_ENDPOINT_URL.hostname
188+
assert spans[2]["context"]["destination"]["port"] == LOCALSTACK_ENDPOINT_URL.port
189+
assert spans[2]["context"]["destination"]["cloud"]["region"] == "us-east-1"
190+
assert spans[2]["context"]["destination"]["service"]["name"] == "sns"
191+
assert spans[2]["context"]["destination"]["service"]["resource"] == "sns/mytopic"
192+
assert spans[2]["context"]["destination"]["service"]["type"] == "messaging"

0 commit comments

Comments
 (0)