Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ddtrace/_trace/_inferred_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def finish_callback(_):


def set_inferred_proxy_span_tags(span, proxy_context) -> Span:
span.set_tag_str(COMPONENT, supported_proxies[proxy_context["proxy_system_name"]]["component"])
span._set_tag_str(COMPONENT, supported_proxies[proxy_context["proxy_system_name"]]["component"])

span.set_tag_str(http.METHOD, proxy_context["method"])
span.set_tag_str(http.URL, f"{proxy_context['domain_name']}{proxy_context['path']}")
span.set_tag_str("stage", proxy_context["stage"])
span._set_tag_str(http.METHOD, proxy_context["method"])
span._set_tag_str(http.URL, f"{proxy_context['domain_name']}{proxy_context['path']}")
span._set_tag_str("stage", proxy_context["stage"])

span.set_metric("_dd.inferred_span", 1)
return span
Expand Down
10 changes: 5 additions & 5 deletions ddtrace/_trace/processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ class TraceTagsProcessor(TraceProcessor):
def _set_git_metadata(self, chunk_root):
repository_url, commit_sha, main_package = gitmetadata.get_git_tags()
if repository_url:
chunk_root.set_tag_str("_dd.git.repository_url", repository_url)
chunk_root._set_tag_str("_dd.git.repository_url", repository_url)
if commit_sha:
chunk_root.set_tag_str("_dd.git.commit.sha", commit_sha)
chunk_root._set_tag_str("_dd.git.commit.sha", commit_sha)
if main_package:
chunk_root.set_tag_str("_dd.python_main_package", main_package)
chunk_root._set_tag_str("_dd.python_main_package", main_package)

def process_trace(self, trace: List[Span]) -> Optional[List[Span]]:
if not trace:
Expand All @@ -249,11 +249,11 @@ def process_trace(self, trace: List[Span]) -> Optional[List[Span]]:
for span in spans_to_tag:
span._update_tags_from_context()
self._set_git_metadata(span)
span.set_tag_str("language", "python")
span._set_tag_str("language", "python")
# for 128 bit trace ids
if span.trace_id > MAX_UINT_64BITS:
trace_id_hob = _get_64_highest_order_bits_as_hex(span.trace_id)
span.set_tag_str(HIGHER_ORDER_TRACE_ID_BITS, trace_id_hob)
span._set_tag_str(HIGHER_ORDER_TRACE_ID_BITS, trace_id_hob)

if LAST_DD_PARENT_ID_KEY in span._meta and span._parent is not None:
# we should only set the last parent id on local root spans
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/_trace/processor/resource_renaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def on_span_finish(self, span):
if not route or config._trace_resource_renaming_always_simplified_endpoint:
url = span.get_tag(http.URL)
endpoint = self._compute_simplified_endpoint(url)
span.set_tag_str(http.ENDPOINT, endpoint)
span._set_tag_str(http.ENDPOINT, endpoint)
7 changes: 6 additions & 1 deletion ddtrace/_trace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def get_struct_tag(self, key: str) -> Optional[Dict[str, Any]]:
"""
return self._get_struct_tag(key)

def set_tag_str(self, key: _TagNameType, value: Text) -> None:
def _set_tag_str(self, key: _TagNameType, value: Text) -> None:
"""Set a value for a tag. Values are coerced to unicode in Python 2 and
str in Python 3, with decoding errors in conversion being replaced with
U+FFFD.
Expand All @@ -448,6 +448,11 @@ def set_tag_str(self, key: _TagNameType, value: Text) -> None:
raise e
log.warning("Failed to set text tag '%s'", key, exc_info=True)

@removals.remove(message="use Span.set_tag instead", removal_version="4.0.0")
def set_tag_str(self, key: _TagNameType, value: Text) -> None:
"""Deprecated: use `set_tag` instead."""
self._set_tag_str(key, value)

def get_tag(self, key: _TagNameType) -> Optional[Text]:
"""Return the given tag or None if it doesn't exist."""
return self._meta.get(key, None)
Expand Down
94 changes: 47 additions & 47 deletions ddtrace/_trace/trace_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def _finish_span(


def _set_web_frameworks_tags(ctx, span, int_config):
span.set_tag_str(COMPONENT, int_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.SERVER)
span._set_tag_str(COMPONENT, int_config.integration_name)
span._set_tag_str(SPAN_KIND, SpanKind.SERVER)
# PERF: avoid setting via Span.set_tag
span.set_metric(_SPAN_MEASURED_KEY, 1)

Expand Down Expand Up @@ -223,7 +223,7 @@ def _on_web_framework_finish_request(
)
_set_inferred_proxy_tags(span, status_code)
for tk, tv in core.get_item("additional_tags", default=dict()).items():
span.set_tag_str(tk, tv)
span._set_tag_str(tk, tv)

if finish:
span.finish()
Expand Down Expand Up @@ -308,7 +308,7 @@ def _maybe_start_http_response_span(ctx: core.ExecutionContext) -> None:
request_span, middleware._config, status_code=status_code, response_headers=ctx.get_item("environ")
)
if ctx.get_item("start_span", False):
request_span.set_tag_str(http.STATUS_MSG, status_msg)
request_span._set_tag_str(http.STATUS_MSG, status_msg)
_start_span(
ctx,
call_trace=False,
Expand All @@ -320,9 +320,9 @@ def _maybe_start_http_response_span(ctx: core.ExecutionContext) -> None:
def _on_request_prepare(ctx, start_response):
middleware = ctx.get_item("middleware")
req_span = ctx.get_item("req_span")
req_span.set_tag_str(COMPONENT, middleware._config.integration_name)
req_span._set_tag_str(COMPONENT, middleware._config.integration_name)
# set span.kind to the type of operation being performed
req_span.set_tag_str(SPAN_KIND, SpanKind.SERVER)
req_span._set_tag_str(SPAN_KIND, SpanKind.SERVER)
if hasattr(middleware, "_request_call_modifier"):
modifier = middleware._request_call_modifier
args = [ctx]
Expand All @@ -336,7 +336,7 @@ def _on_request_prepare(ctx, start_response):
else middleware._application_span_name
)

app_span.set_tag_str(COMPONENT, middleware._config.integration_name)
app_span._set_tag_str(COMPONENT, middleware._config.integration_name)
ctx.set_item("app_span", app_span)

if hasattr(middleware, "_wrapped_start_response"):
Expand Down Expand Up @@ -385,7 +385,7 @@ def _on_request_complete(ctx, closing_iterable, app_is_iterator):
activate=True,
)

resp_span.set_tag_str(COMPONENT, middleware._config.integration_name)
resp_span._set_tag_str(COMPONENT, middleware._config.integration_name)

modifier = (
middleware._response_call_modifier
Expand All @@ -401,7 +401,7 @@ def _on_response_prepared(resp_span, response):
if hasattr(response, "__class__"):
resp_class = getattr(response.__class__, "__name__", None)
if resp_class:
resp_span.set_tag_str("result_class", resp_class)
resp_span._set_tag_str("result_class", resp_class)


def _on_request_prepared(middleware, req_span, url, request_headers, environ):
Expand All @@ -416,19 +416,19 @@ def _on_request_prepared(middleware, req_span, url, request_headers, environ):

def _set_flask_request_tags(request, span, flask_config):
try:
span.set_tag_str(COMPONENT, flask_config.integration_name)
span._set_tag_str(COMPONENT, flask_config.integration_name)

if span.name.split(".")[-1] == "request":
span.set_tag_str(SPAN_KIND, SpanKind.SERVER)
span._set_tag_str(SPAN_KIND, SpanKind.SERVER)

# DEV: This name will include the blueprint name as well (e.g. `bp.index`)
if not span.get_tag(FLASK_ENDPOINT) and request.endpoint:
span.resource = " ".join((request.method, request.endpoint))
span.set_tag_str(FLASK_ENDPOINT, request.endpoint)
span._set_tag_str(FLASK_ENDPOINT, request.endpoint)

if not span.get_tag(FLASK_URL_RULE) and request.url_rule and request.url_rule.rule:
span.resource = " ".join((request.method, request.url_rule.rule))
span.set_tag_str(FLASK_URL_RULE, request.url_rule.rule)
span._set_tag_str(FLASK_URL_RULE, request.url_rule.rule)

if not span.get_tag(FLASK_VIEW_ARGS) and request.view_args and flask_config.get("collect_view_args"):
for k, v in request.view_args.items():
Expand Down Expand Up @@ -487,7 +487,7 @@ def _on_flask_render(template, flask_config):
name = maybe_stringify(getattr(template, "name", None) or flask_config.get("template_default_name"))
if name is not None:
span.resource = name
span.set_tag_str("flask.template_name", name)
span._set_tag_str("flask.template_name", name)


def _on_request_span_modifier(
Expand All @@ -504,7 +504,7 @@ def _on_request_span_modifier(
# PERF: avoid setting via Span.set_tag
span.set_metric(_SPAN_MEASURED_KEY, 1)

span.set_tag_str(flask_version, flask_version_str)
span._set_tag_str(flask_version, flask_version_str)


def _on_request_span_modifier_post(ctx, flask_config, request, req_body):
Expand Down Expand Up @@ -589,7 +589,7 @@ def _on_django_func_wrapped(_unused1, _unused2, _unused3, ctx, ignored_excs):

def _on_django_block_request(ctx: core.ExecutionContext, metadata: Dict[str, str], django_config, url: str, query: str):
for tk, tv in metadata.items():
ctx.span.set_tag_str(tk, tv)
ctx.span._set_tag_str(tk, tv)
_set_url_tag(django_config, ctx.span, url, query)


Expand Down Expand Up @@ -717,8 +717,8 @@ def _on_botocore_patched_bedrock_api_call_started(ctx, request_params):
integration = ctx.get_item("bedrock_integration")
integration._tag_proxy_request(ctx)

span.set_tag_str("bedrock.request.model_provider", ctx.get_item("model_provider"))
span.set_tag_str("bedrock.request.model", ctx.get_item("model_name"))
span._set_tag_str("bedrock.request.model_provider", ctx.get_item("model_provider"))
span._set_tag_str("bedrock.request.model", ctx.get_item("model_name"))

if "n" in request_params:
ctx.set_item("num_generations", str(request_params["n"]))
Expand Down Expand Up @@ -749,7 +749,7 @@ def _after_job_execution(ctx, job_failed, span_tags):
if job_failed:
span.error = 1
for k in span_tags.keys():
span.set_tag_str(k, span_tags[k])
span._set_tag_str(k, span_tags[k])


def _on_end_of_traced_method_in_fork(ctx):
Expand Down Expand Up @@ -859,26 +859,26 @@ def _set_span_pointer(span: "Span", span_pointer_description: _SpanPointerDescri


def _set_azure_function_tags(span, azure_functions_config, function_name, trigger, span_kind):
span.set_tag_str(COMPONENT, azure_functions_config.integration_name)
span.set_tag_str(SPAN_KIND, span_kind)
span.set_tag_str("aas.function.name", function_name) # codespell:ignore
span.set_tag_str("aas.function.trigger", trigger) # codespell:ignore
span._set_tag_str(COMPONENT, azure_functions_config.integration_name)
span._set_tag_str(SPAN_KIND, span_kind)
span._set_tag_str("aas.function.name", function_name) # codespell:ignore
span._set_tag_str("aas.function.trigger", trigger) # codespell:ignore


def _set_azure_messaging_tags(ctx, entity_name, operation, system, fully_qualified_namespace, message_id, batch_count):
span = ctx.span
span.set_tag_str(MESSAGING_DESTINATION_NAME, entity_name)
span.set_tag_str(MESSAGING_OPERATION, operation)
span.set_tag_str(MESSAGING_SYSTEM, system)
span._set_tag_str(MESSAGING_DESTINATION_NAME, entity_name)
span._set_tag_str(MESSAGING_OPERATION, operation)
span._set_tag_str(MESSAGING_SYSTEM, system)

if fully_qualified_namespace is not None:
span.set_tag_str(net.TARGET_NAME, fully_qualified_namespace)
span._set_tag_str(net.TARGET_NAME, fully_qualified_namespace)

if batch_count is not None:
span.set_tag_str(MESSAGING_BATCH_COUNT, batch_count)
span._set_tag_str(MESSAGING_BATCH_COUNT, batch_count)

if message_id is not None:
span.set_tag_str(MESSAGING_MESSAGE_ID, message_id)
span._set_tag_str(MESSAGING_MESSAGE_ID, message_id)


def _on_azure_functions_request_span_modifier(ctx, azure_functions_config, req):
Expand Down Expand Up @@ -943,8 +943,8 @@ def _on_azure_message_modifier(
ctx, azure_config, operation, system, entity_name, fully_qualified_namespace, message_id, batch_count
):
span = ctx.span
span.set_tag_str(COMPONENT, azure_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.PRODUCER)
span._set_tag_str(COMPONENT, azure_config.integration_name)
span._set_tag_str(SPAN_KIND, SpanKind.PRODUCER)

_set_azure_messaging_tags(ctx, entity_name, operation, system, fully_qualified_namespace, message_id, batch_count)

Expand All @@ -960,17 +960,17 @@ def _on_router_match(route):
MOLTEN_ROUTE = "molten.route"

if not req_span.get_tag(MOLTEN_ROUTE):
req_span.set_tag_str(MOLTEN_ROUTE, route.name)
req_span._set_tag_str(MOLTEN_ROUTE, route.name)
if not req_span.get_tag(http.ROUTE):
req_span.set_tag_str(http.ROUTE, route.template)
req_span._set_tag_str(http.ROUTE, route.template)


def _set_websocket_message_tags_on_span(websocket_span: Span, message: Mapping[str, Any]):
if "text" in message:
websocket_span.set_tag_str(websocket.MESSAGE_TYPE, "text")
websocket_span._set_tag_str(websocket.MESSAGE_TYPE, "text")
websocket_span.set_metric(websocket.MESSAGE_LENGTH, len(message["text"].encode("utf-8")))
elif "binary" in message:
websocket_span.set_tag_str(websocket.MESSAGE_TYPE, "binary")
websocket_span._set_tag_str(websocket.MESSAGE_TYPE, "binary")
websocket_span.set_metric(websocket.MESSAGE_LENGTH, len(message["bytes"]))


Expand All @@ -987,10 +987,10 @@ def _set_client_ip_tags(scope: Mapping[str, Any], span: Span):
client = scope.get("client")
if len(client) >= 1: # type: ignore[arg-type]
client_ip = client[0] # type: ignore[index]
span.set_tag_str(net.TARGET_HOST, client_ip)
span._set_tag_str(net.TARGET_HOST, client_ip)
try:
is_valid_ip(client_ip)
span.set_tag_str("network.client.ip", client_ip)
span._set_tag_str("network.client.ip", client_ip)
except ValueError as e:
log.debug("Could not validate client IP address for websocket send message: %s", str(e))

Expand All @@ -1005,9 +1005,9 @@ def _on_asgi_websocket_receive_message(ctx, scope, message):
span = ctx.span
integration_config = ctx.get_item("integration_config")

span.set_tag_str(COMPONENT, integration_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.CONSUMER)
span.set_tag_str(websocket.RECEIVE_DURATION_TYPE, "blocking")
span._set_tag_str(COMPONENT, integration_config.integration_name)
span._set_tag_str(SPAN_KIND, SpanKind.CONSUMER)
span._set_tag_str(websocket.RECEIVE_DURATION_TYPE, "blocking")

_set_websocket_message_tags_on_span(span, message)

Expand Down Expand Up @@ -1036,8 +1036,8 @@ def _on_asgi_websocket_send_message(ctx, scope, message):
span = ctx.span
integration_config = ctx.get_item("integration_config")

span.set_tag_str(COMPONENT, integration_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.PRODUCER)
span._set_tag_str(COMPONENT, integration_config.integration_name)
span._set_tag_str(SPAN_KIND, SpanKind.PRODUCER)
_set_client_ip_tags(scope, span)
_set_websocket_message_tags_on_span(span, message)

Expand All @@ -1061,8 +1061,8 @@ def _on_asgi_websocket_close_message(ctx, scope, message):
span = ctx.span
integration_config = ctx.get_item("integration_config")

span.set_tag_str(COMPONENT, integration_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.PRODUCER)
span._set_tag_str(COMPONENT, integration_config.integration_name)
span._set_tag_str(SPAN_KIND, SpanKind.PRODUCER)

_set_client_ip_tags(scope, span)

Expand Down Expand Up @@ -1090,8 +1090,8 @@ def _on_asgi_websocket_disconnect_message(ctx, scope, message):
span = ctx.span
integration_config = ctx.get_item("integration_config")

span.set_tag_str(COMPONENT, integration_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.CONSUMER)
span._set_tag_str(COMPONENT, integration_config.integration_name)
span._set_tag_str(SPAN_KIND, SpanKind.CONSUMER)

_set_websocket_close_tags(span, message)

Expand Down Expand Up @@ -1119,7 +1119,7 @@ def _on_asgi_request(ctx: core.ExecutionContext) -> None:
ctx.set_item("req_span", span)

if scope["type"] == "websocket":
span.set_tag_str("http.upgraded", "websocket")
span._set_tag_str("http.upgraded", "websocket")

if "datadog" not in scope:
scope["datadog"] = {"request_spans": [span]}
Expand Down
8 changes: 4 additions & 4 deletions ddtrace/_trace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,18 +547,18 @@ def _start_span(
on_finish=[self._on_span_finish],
)
if config._report_hostname:
span.set_tag_str(_HOSTNAME_KEY, hostname.get_hostname())
span._set_tag_str(_HOSTNAME_KEY, hostname.get_hostname())

if not span._parent:
span.set_tag_str("runtime-id", get_runtime_id())
span._set_tag_str("runtime-id", get_runtime_id())
span._metrics[PID] = self._pid

# Apply default global tags.
if self._tags:
span.set_tags(self._tags)

if config.env:
span.set_tag_str(ENV_KEY, config.env)
span._set_tag_str(ENV_KEY, config.env)

# Only set the version tag on internal spans.
if config.version:
Expand All @@ -570,7 +570,7 @@ def _start_span(
if (root_span is None and service == config.service) or (
root_span and root_span.service == service and root_span.get_tag(VERSION_KEY) is not None
):
span.set_tag_str(VERSION_KEY, config.version)
span._set_tag_str(VERSION_KEY, config.version)

if activate:
self.context_provider.activate(span)
Expand Down
Loading
Loading