Skip to content

Commit 7c5ec23

Browse files
authored
Fix instrumentation tags (#634)
* Fix instrumentation tags * Don't use scenario span * Need the current span?
1 parent 7bf955a commit 7c5ec23

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

tests/conftest.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,15 @@ def pytest_bdd_before_scenario(request, feature, scenario):
8383
if tracer is None:
8484
return
8585

86-
span = tracer.start_span(
87-
scenario.name,
88-
span_type="scenario",
89-
child_of=tracer.current_trace_context(),
90-
activate=True,
91-
)
92-
setattr(scenario, "__dd_span__", span)
86+
span = tracer.current_span()
87+
span.set_tag("test.name", scenario.name)
88+
span.set_tag("test.suite", scenario.feature.filename.split("tests")[-1])
9389

9490

9591
def pytest_bdd_after_scenario(request, feature, scenario):
9692
ctx = request.getfixturevalue("context")
9793
for undo in reversed(ctx["undo_operations"]):
9894
undo()
99-
span = getattr(scenario, "__dd_span__", None)
100-
if span is not None:
101-
span.finish()
10295

10396

10497
def pytest_bdd_before_step(request, feature, scenario, step, step_func):
@@ -109,7 +102,7 @@ def pytest_bdd_before_step(request, feature, scenario, step, step_func):
109102
step.type,
110103
resource=step.name,
111104
span_type=step.type,
112-
child_of=getattr(scenario, "__dd_span__"),
105+
child_of=tracer.current_span(),
113106
activate=True,
114107
)
115108
setattr(step_func, "__dd_span__", span)
@@ -610,7 +603,9 @@ def execute_request(undo, context, client, api_version, _package):
610603
operation_id = api_request["request"].__name__
611604
response = api_request["response"][0]
612605

613-
context["undo_operations"].append(lambda: undo(api, api_version, operation_id, response))
606+
context["undo_operations"].append(
607+
lambda: undo(api, api_version, operation_id, response)
608+
)
614609

615610

616611
@then(parsers.parse('I should get an instance of "{name}"'))

0 commit comments

Comments
 (0)