Skip to content

Commit

Permalink
move exporter to conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-yuwang committed Jul 15, 2024
1 parent 41ddbe1 commit c46f7f9
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
from pathlib import Path

import pytest
from opentelemetry import trace
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter

from snowflake.snowpark._internal.utils import warning_dict

Expand Down Expand Up @@ -102,12 +97,25 @@ def clear_warning_dict():
warning_dict.clear()


@pytest.fixture(scope="session")
def dict_exporter():
resource = Resource(attributes={SERVICE_NAME: "snowpark-python-open-telemetry"})
trace_provider = TracerProvider(resource=resource)
dict_exporter = InMemorySpanExporter()
processor = SimpleSpanProcessor(dict_exporter)
trace_provider.add_span_processor(processor)
trace.set_tracer_provider(trace_provider)
yield dict_exporter
# the fixture only works when opentelemetry is installed
try:
from opentelemetry import trace
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
InMemorySpanExporter,
)

@pytest.fixture(scope="session")
def dict_exporter():
resource = Resource(attributes={SERVICE_NAME: "snowpark-python-open-telemetry"})
trace_provider = TracerProvider(resource=resource)
dict_exporter = InMemorySpanExporter()
processor = SimpleSpanProcessor(dict_exporter)
trace_provider.add_span_processor(processor)
trace.set_tracer_provider(trace_provider)
yield dict_exporter

except ModuleNotFoundError:
pass

0 comments on commit c46f7f9

Please sign in to comment.