Skip to content

Commit 6cc5ad7

Browse files
authored
Remove tags (deprecated) + Update docs for 6.x (#1034)
* Update docs for 6.x * Remove tags (deprecated) + review suggestions
1 parent 1527843 commit 6cc5ad7

7 files changed

Lines changed: 33 additions & 131 deletions

File tree

CHANGELOG.asciidoc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,27 @@ endif::[]
3030
//===== Bug fixes
3131
//
3232
33-
[float]
34-
=== Unreleased
33+
[[release-notes-6.x]]
34+
=== Python Agent version 6.x
35+
36+
37+
[[release-notes-6.0.0]]
38+
==== v6.0.0
3539
36-
// Unreleased changes go here
37-
// When the next release happens, nest these changes under the "Python Agent version 5.x" heading
3840
[float]
3941
===== Breaking changes
4042
4143
* Python 2.7 and 3.5 support has been deprecated. The Python agent now requires Python 3.6+ {pull}1021[#1021]
4244
* No longer collecting body for `elasticsearch-py` `update` and `delete_by_query` {pull}1013[#1013]
4345
* Align `sanitize_field_names` config with the
4446
https://github.com/elastic/apm/blob/3fa78e2a1eeea81c73c2e16e96dbf6b2e79f3c64/specs/agents/sanitization.md[cross-agent spec].
45-
If you are using a non-default `sanitize_field_names`, surrounding each of your entries with stars (i.e.
46-
`\*secret\*`) will retain the old behavior. {pull}982[#982]
47+
If you are using a non-default `sanitize_field_names`, surrounding each of your entries with stars (e.g.
48+
`*secret*`) will retain the old behavior. {pull}982[#982]
4749
* Remove credit card sanitization for field values. This improves performance, and the security value of this check was
4850
dubious anyway. {pull}982[#982]
4951
* Remove HTTP querystring sanitization. This improves performance, and is meant to standardize behavior across the
5052
agents, as defined in https://github.com/elastic/apm/pull/334. {pull}982[#982]
51-
52-
[float]
53-
===== Features
54-
53+
* Remove `elasticapm.tag()` (deprecated since 5.0.0) {pull}1034[#1034]
5554
5655
[float]
5756
===== Bug fixes

docs/upgrading.asciidoc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,27 @@ The table below is a simplified description of this policy.
2525
|3.x |2020-01-20 |4.0
2626
|4.x |2020-05-14 |5.0
2727
|5.x |2021-02-05 |6.0
28+
|6.x |2022-08-01 |7.0
2829
|====
2930

31+
[[upgrading-6.x]]
32+
=== Upgrading to version 6 of the agent
33+
34+
==== Python 2 no longer supported
35+
36+
Please upgrade to Python 3.6+ to continue to receive regular updates.
37+
38+
==== `SANITIZE_FIELD_NAMES` changes
39+
40+
If you are using a non-default `sanitize_field_names` config, please note
41+
that your entries must be surrounded with stars (e.g. `*secret*`) in order to
42+
maintain previous behavior.
43+
44+
==== Tags removed (in favor of labels)
45+
46+
Tags were deprecated in the 5.x release (in favor of labels). They have now been
47+
removed.
48+
3049
[[upgrading-5.x]]
3150
=== Upgrading to version 5 of the agent
3251

@@ -42,7 +61,7 @@ we renamed "tags" to "labels", and introduced limited support for typed labels.
4261
While tag values were only allowed to be strings, label values can be strings, booleans, or numerical.
4362

4463
To benefit from this change, ensure that you run at least *APM Server 6.7*, and use `elasticapm.label()` instead of `elasticapm.tag()`.
45-
The `tag()` API will continue to work as before, but emit a `DeprecationWarning`. It will be removed in 6.0 of the agent.
64+
The `tag()` API will continue to work as before, but emit a `DeprecationWarning`. It will be removed in 6.0 of the agent.
4665

4766
[[upgrading-4.x]]
4867
=== Upgrading to version 4 of the agent

elasticapm/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
set_transaction_outcome,
4646
set_transaction_result,
4747
set_user_context,
48-
tag,
4948
)
5049
from elasticapm.utils.disttracing import trace_parent_from_headers, trace_parent_from_string # noqa: F401
5150

elasticapm/traces.py

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,17 @@
3434
import threading
3535
import time
3636
import timeit
37-
import warnings
3837
from collections import defaultdict
3938

4039
from elasticapm.conf import constants
4140
from elasticapm.conf.constants import LABEL_RE, SPAN, TRANSACTION
4241
from elasticapm.context import init_execution_context
4342
from elasticapm.metrics.base_metrics import Timer
4443
from elasticapm.utils import compat, encoding, get_name_from_func
45-
from elasticapm.utils.deprecation import deprecated
4644
from elasticapm.utils.disttracing import TraceParent, TracingOptions
4745
from elasticapm.utils.logging import get_logger
4846

49-
__all__ = ("capture_span", "tag", "label", "set_transaction_name", "set_custom_context", "set_user_context")
47+
__all__ = ("capture_span", "label", "set_transaction_name", "set_custom_context", "set_user_context")
5048

5149
error_logger = get_logger("elasticapm.errors")
5250
logger = get_logger("elasticapm.traces")
@@ -116,23 +114,6 @@ def label(self, **labels):
116114
labels = encoding.enforce_label_format(labels)
117115
self.labels.update(labels)
118116

119-
@deprecated("transaction/span.label()")
120-
def tag(self, **tags):
121-
"""
122-
This method is deprecated, please use "label()" instead.
123-
124-
Tag this span with one or multiple key/value tags. Both the values should be strings
125-
126-
span_obj.tag(key1="value1", key2="value2")
127-
128-
Note that keys will be dedotted, replacing dot (.), star (*) and double quote (") with an underscore (_)
129-
130-
:param tags: key/value pairs of tags
131-
:return: None
132-
"""
133-
for key in tags.keys():
134-
self.labels[LABEL_RE.sub("_", compat.text_type(key))] = encoding.keyword_field(compat.text_type(tags[key]))
135-
136117
def set_success(self):
137118
self.outcome = "success"
138119

@@ -666,7 +647,6 @@ def __init__(
666647
extra=None,
667648
skip_frames=0,
668649
leaf=False,
669-
tags=None,
670650
labels=None,
671651
span_subtype=None,
672652
span_action=None,
@@ -681,14 +661,6 @@ def __init__(
681661
self.extra = extra
682662
self.skip_frames = skip_frames
683663
self.leaf = leaf
684-
if tags and not labels:
685-
warnings.warn(
686-
'The tags argument to capture_span is deprecated, use "labels" instead',
687-
category=DeprecationWarning,
688-
stacklevel=2,
689-
)
690-
labels = tags
691-
692664
self.labels = labels
693665
self.start = start
694666
self.duration = duration
@@ -750,18 +722,6 @@ def label(**labels):
750722
transaction.label(**labels)
751723

752724

753-
@deprecated("elasticapm.label")
754-
def tag(**tags):
755-
"""
756-
Tags current transaction. Both key and value of the label should be strings.
757-
"""
758-
transaction = execution_context.get_transaction()
759-
if not transaction:
760-
error_logger.warning("Ignored tags %s. No transaction currently active.", ", ".join(tags.keys()))
761-
else:
762-
transaction.tag(**tags)
763-
764-
765725
def set_transaction_name(name, override=True):
766726
"""
767727
Sets the name of the transaction

tests/client/client_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def test_transaction_keyword_truncation(elasticapm_client):
699699
assert len(expected) == KEYWORD_MAX_LENGTH
700700
assert expected[-1] != "x"
701701
elasticapm_client.begin_transaction(too_long)
702-
elasticapm.tag(val=too_long)
702+
elasticapm.label(val=too_long)
703703
elasticapm.set_user_context(username=too_long, email=too_long, user_id=too_long)
704704
with elasticapm.capture_span(name=too_long, span_type=too_long):
705705
pass

tests/client/exception_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_transaction_data_is_attached_to_errors_exc_handled_outside_span(elastic
304304

305305
def test_transaction_context_is_used_in_errors(elasticapm_client):
306306
elasticapm_client.begin_transaction("test")
307-
elasticapm.tag(foo="baz")
307+
elasticapm.label(foo="baz")
308308
elasticapm.set_custom_context({"a": "b"})
309309
elasticapm.set_user_context(username="foo", email="foo@example.com", user_id=42)
310310
elasticapm_client.capture_message("x", custom={"foo": "bar"})

tests/instrumentation/transactions_store_tests.py

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -336,73 +336,6 @@ def test_labels_dedot(elasticapm_client):
336336
assert transactions[0]["context"]["tags"] == {"d_o_t": "dot", "s_t_a_r": "star", "q_u_o_t_e": "quote"}
337337

338338

339-
### TESTING DEPRECATED TAGGING START ###
340-
341-
342-
def test_tagging_is_deprecated(elasticapm_client):
343-
elasticapm_client.begin_transaction("test")
344-
with pytest.warns(DeprecationWarning, match="Call to deprecated function tag. Use elasticapm.label instead"):
345-
elasticapm.tag(foo="bar")
346-
elasticapm_client.end_transaction("test", "OK")
347-
transactions = elasticapm_client.events[TRANSACTION]
348-
349-
assert transactions[0]["context"]["tags"] == {"foo": "bar"}
350-
351-
352-
def test_tag_transaction():
353-
requests_store = Tracer(lambda: [], lambda: [], lambda *args: None, Config(), None)
354-
transaction = requests_store.begin_transaction("test")
355-
elasticapm.tag(foo="bar")
356-
transaction.tag(baz="bazzinga")
357-
requests_store.end_transaction(200, "test")
358-
359-
assert transaction.labels == {"foo": "bar", "baz": "bazzinga"}
360-
transaction_dict = transaction.to_dict()
361-
assert transaction_dict["context"]["tags"] == {"foo": "bar", "baz": "bazzinga"}
362-
363-
364-
def test_tag_while_no_transaction(caplog):
365-
with caplog.at_level(logging.WARNING, "elasticapm.errors"):
366-
elasticapm.tag(foo="bar")
367-
record = caplog.records[0]
368-
assert record.levelno == logging.WARNING
369-
assert "foo" in record.args
370-
371-
372-
def test_tag_with_non_string_value():
373-
requests_store = Tracer(lambda: [], lambda: [], lambda *args: None, config=Config(), agent=None)
374-
t = requests_store.begin_transaction("test")
375-
elasticapm.tag(foo=1)
376-
requests_store.end_transaction(200, "test")
377-
assert t.labels == {"foo": "1"}
378-
379-
380-
def test_tags_merge(elasticapm_client):
381-
elasticapm_client.begin_transaction("test")
382-
elasticapm.tag(foo=1, bar="baz")
383-
elasticapm.tag(bar=3, boo="biz")
384-
elasticapm_client.end_transaction("test", "OK")
385-
transactions = elasticapm_client.events[TRANSACTION]
386-
387-
assert transactions[0]["context"]["tags"] == {"foo": "1", "bar": "3", "boo": "biz"}
388-
389-
390-
def test_tags_dedot(elasticapm_client):
391-
elasticapm_client.begin_transaction("test")
392-
elasticapm.tag(**{"d.o.t": "dot"})
393-
elasticapm.tag(**{"s*t*a*r": "star"})
394-
elasticapm.tag(**{'q"u"o"t"e': "quote"})
395-
396-
elasticapm_client.end_transaction("test_name", 200)
397-
398-
transactions = elasticapm_client.events[TRANSACTION]
399-
400-
assert transactions[0]["context"]["tags"] == {"d_o_t": "dot", "s_t_a_r": "star", "q_u_o_t_e": "quote"}
401-
402-
403-
### TESTING DEPRECATED TAGGING END ###
404-
405-
406339
def test_dedot_is_not_run_when_unsampled(elasticapm_client):
407340
for sampled in (True, False):
408341
t = elasticapm_client.begin_transaction("test")
@@ -542,20 +475,12 @@ def test_dotted_span_type_conversion(elasticapm_client):
542475
def test_span_labelling(elasticapm_client):
543476
elasticapm_client.begin_transaction("test")
544477
with elasticapm.capture_span("test", labels={"foo": "bar", "ba.z": "baz.zinga"}) as span:
545-
span.tag(lorem="ipsum")
478+
span.label(lorem="ipsum")
546479
elasticapm_client.end_transaction("test", "OK")
547480
span = elasticapm_client.events[SPAN][0]
548481
assert span["context"]["tags"] == {"foo": "bar", "ba_z": "baz.zinga", "lorem": "ipsum"}
549482

550483

551-
def test_span_tagging_raises_deprecation_warning(elasticapm_client):
552-
elasticapm_client.begin_transaction("test")
553-
with pytest.warns(DeprecationWarning, match="The tags argument to capture_span is deprecated"):
554-
with elasticapm.capture_span("test", tags={"foo": "bar", "ba.z": "baz.zinga"}) as span:
555-
span.tag(lorem="ipsum")
556-
elasticapm_client.end_transaction("test", "OK")
557-
558-
559484
def test_span_sync(elasticapm_client):
560485
elasticapm_client.begin_transaction("test")
561486
with capture_span("foo", "type", sync=True):

0 commit comments

Comments
 (0)