/
test_distributed_tracing.py
69 lines (63 loc) · 2.27 KB
/
test_distributed_tracing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from _target_application import add, assert_dt
from testing_support.fixtures import override_application_settings
from testing_support.validators.validate_transaction_count import (
validate_transaction_count,
)
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)
from newrelic.api.background_task import background_task
@validate_transaction_metrics(
name="_target_application.assert_dt",
group="Celery",
rollup_metrics=[
("Supportability/DistributedTrace/AcceptPayload/Success", None),
("Supportability/TraceContext/Accept/Success", 1),
],
background_task=True,
index=-2,
)
@validate_transaction_metrics(
name="test_distributed_tracing:test_celery_task_distributed_tracing_enabled",
background_task=True,
)
@validate_transaction_count(2)
@background_task()
def test_celery_task_distributed_tracing_enabled():
result = assert_dt.apply_async()
result = result.get()
assert result == 1
@override_application_settings({"distributed_tracing.enabled": False})
@validate_transaction_metrics(
name="_target_application.add",
group="Celery",
rollup_metrics=[
("Supportability/DistributedTrace/AcceptPayload/Success", None),
("Supportability/TraceContext/Accept/Success", None), # No trace context should be accepted
],
background_task=True,
index=-2,
)
@validate_transaction_metrics(
name="test_distributed_tracing:test_celery_task_distributed_tracing_disabled",
background_task=True,
)
@validate_transaction_count(2)
@background_task()
def test_celery_task_distributed_tracing_disabled():
result = add.apply_async((1, 2))
result = result.get()
assert result == 3