Skip to content

Commit f8c18a1

Browse files
authored
label no longer fails when called without a client (#1596)
1 parent 04bea0a commit f8c18a1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎elasticapm/traces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,8 @@ def label(**labels):
10891089
"""
10901090
transaction = execution_context.get_transaction()
10911091
if not transaction:
1092-
if elasticapm.get_client().config.enabled:
1092+
client = elasticapm.get_client()
1093+
if not client or client.config.enabled:
10931094
error_logger.warning("Ignored labels %s. No transaction currently active.", ", ".join(labels.keys()))
10941095
else:
10951096
transaction.label(**labels)

‎tests/client/client_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,7 @@ def test_check_server_version(elasticapm_client):
536536
)
537537
def test_user_agent(elasticapm_client, expected):
538538
assert elasticapm_client.get_user_agent() == "apm-agent-python/unknown (myapp{})".format(expected)
539+
540+
541+
def test_label_without_client():
542+
elasticapm.label(foo="foo")

0 commit comments

Comments
 (0)