Skip to content

Commit 1376e67

Browse files
Bastian KrolFerenc-
authored andcommitted
feat: improve robustness of custom service naming
Previously, we only added span.data.service to _entry_ spans (when the environment variable INSTANA_SERVICE_NAME is set). The requirements around this have changed, now we add this annotation to _all_ spans (but still only if it has been explicitly configured). Signed-off-by: Bastian Krol <[email protected]>
1 parent 649e607 commit 1376e67

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

instana/span.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def __init__(self, span, source, service_name, **kwargs):
203203
self.n = "sdk"
204204
self.k = span_kind[1]
205205

206-
if self.k == 1 and service_name is not None:
206+
if service_name is not None:
207207
self.data["service"] = service_name
208208

209209
self.data["sdk"]["name"] = span.operation_name
@@ -263,10 +263,10 @@ def __init__(self, span, source, service_name, **kwargs):
263263
self.n = span.operation_name
264264
self.k = 1
265265

266+
self.data["service"] = service_name
266267
if span.operation_name in self.ENTRY_SPANS:
267268
# entry
268269
self._populate_entry_span_data(span)
269-
self.data["service"] = service_name
270270
self._populate_extra_span_attributes(span)
271271
elif span.operation_name in self.EXIT_SPANS:
272272
self.k = 2 # exit

tests/opentracing/test_ot_span.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ def test_custom_service_name(self):
269269
exit_span = get_first_span_by_filter(spans, filter)
270270
assert (exit_span)
271271

272-
# Custom service name should be set on ENTRY spans and none other
273272
assert(entry_span)
274273
assert(len(entry_span.data['sdk']['custom']['tags']) == 2)
275274
assert(entry_span.data['sdk']['custom']['tags']['type'] == 'entry_span')
@@ -279,13 +278,13 @@ def test_custom_service_name(self):
279278
assert(intermediate_span)
280279
assert(len(intermediate_span.data['sdk']['custom']['tags']) == 1)
281280
assert(intermediate_span.data['sdk']['custom']['tags']['type'] == 'intermediate_span')
282-
assert("service" not in intermediate_span.data)
281+
assert(intermediate_span.data['service'] == 'custom_service_name')
283282
assert(intermediate_span.k == 3)
284283

285284
assert(exit_span)
286285
assert(len(exit_span.data['sdk']['custom']['tags']) == 2)
287286
assert(exit_span.data['sdk']['custom']['tags']['type'] == 'exit_span')
288-
assert("service" not in intermediate_span.data)
287+
assert(exit_span.data['service'] == 'custom_service_name')
289288
assert(exit_span.k == 2)
290289

291290
def test_span_log(self):

0 commit comments

Comments
 (0)