Skip to content

Commit

Permalink
SNOW-1306434:Change tracer scope name to reflect class (snowflakedb#1370
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sfc-gh-yuwang authored Apr 9, 2024
1 parent bbf6333 commit cc41439
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/snowflake/snowpark/_internal/open_telemetry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
#

#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#
Expand All @@ -18,16 +22,19 @@
except ImportError:
open_telemetry_found = False

if open_telemetry_found:
tracer = trace.get_tracer("snow.snowpark.dataframe")


@contextmanager
def open_telemetry_context_manager(func, dataframe):

# trace when required package is installed
if open_telemetry_found:
name = func.__qualname__
class_name = func.__qualname__
name = func.__name__
tracer = (
trace.get_tracer(f"snow.snowpark.{class_name.split('.')[0].lower()}")
if "." in class_name
else class_name
)
with tracer.start_as_current_span(name) as cur_span:
try:
if cur_span.is_recording():
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_open_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def test_open_telemetry_span_from_dataframe_writer_and_dataframe():
lineno = inspect.currentframe().f_lineno - 1

spans = spans_to_dict(dict_exporter.get_finished_spans())
assert "DataFrameWriter.save_as_table" in spans
span = spans["DataFrameWriter.save_as_table"]
assert "save_as_table" in spans
span = spans["save_as_table"]
assert span.attributes["method.chain"] == "DataFrame.to_df().save_as_table()"
assert (
os.path.basename(span.attributes["code.filepath"]) == "test_open_telemetry.py"
Expand All @@ -89,8 +89,8 @@ def test_open_telemetry_span_from_dataframe_writer():
lineno = inspect.currentframe().f_lineno - 1

spans = spans_to_dict(dict_exporter.get_finished_spans())
assert "DataFrame.collect" in spans
span = spans["DataFrame.collect"]
assert "collect" in spans
span = spans["collect"]
assert span.attributes["method.chain"] == "DataFrame.to_df().collect()"
assert (
os.path.basename(span.attributes["code.filepath"]) == "test_open_telemetry.py"
Expand Down

0 comments on commit cc41439

Please sign in to comment.