Skip to content

Commit

Permalink
Set instance id in github CI run, uninstrument flask auto during inte…
Browse files Browse the repository at this point in the history
…gration test run
  • Loading branch information
BryanFauble committed Nov 22, 2024
1 parent 14aa510 commit 7a1c183
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ jobs:
LOGGING_EXPORT_FORMAT: ${{ vars.LOGGING_EXPORT_FORMAT }}
TRACING_SERVICE_NAME: ${{ vars.TRACING_SERVICE_NAME }}
LOGGING_SERVICE_NAME: ${{ vars.LOGGING_SERVICE_NAME }}
SERVICE_INSTANCE_ID: ${{ github.head_ref || github.ref_name }}
run: >
poetry run pytest --durations=0 --cov-append --cov-report=term --cov-report=html:htmlcov --cov-report=xml:coverage.xml --cov=schematic/
-m "not (rule_benchmark or single_process_execution)" --reruns 4 -n 8 --ignore=tests/unit
Expand Down
11 changes: 10 additions & 1 deletion schematic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
from opentelemetry.sdk.resources import DEPLOYMENT_ENVIRONMENT, SERVICE_NAME, Resource
from opentelemetry.sdk.resources import (
DEPLOYMENT_ENVIRONMENT,
SERVICE_INSTANCE_ID,
SERVICE_NAME,
Resource,
)
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, Span
from opentelemetry.sdk.trace.sampling import ALWAYS_OFF
Expand Down Expand Up @@ -91,10 +96,12 @@ def set_up_tracing(session: requests.Session) -> None:
Synapse.enable_open_telemetry(True)
tracing_service_name = os.environ.get("TRACING_SERVICE_NAME", "schematic-api")
deployment_environment = os.environ.get("DEPLOYMENT_ENVIRONMENT", "")
service_instance_id = os.environ.get("SERVICE_INSTANCE_ID", "")
trace.set_tracer_provider(
TracerProvider(
resource=Resource(
attributes={
SERVICE_INSTANCE_ID: service_instance_id,
SERVICE_NAME: tracing_service_name,
# TODO: Revisit this portion later on. As of 11/12/2024 when
# deploying this to ECS or running within a docker container,
Expand Down Expand Up @@ -122,9 +129,11 @@ def set_up_logging(session: requests.Session) -> None:
logging_export = os.environ.get("LOGGING_EXPORT_FORMAT", None)
logging_service_name = os.environ.get("LOGGING_SERVICE_NAME", "schematic-api")
deployment_environment = os.environ.get("DEPLOYMENT_ENVIRONMENT", "")
service_instance_id = os.environ.get("SERVICE_INSTANCE_ID", "")
if logging_export == "otlp":
resource = Resource.create(
{
SERVICE_INSTANCE_ID: service_instance_id,
SERVICE_NAME: logging_service_name,
DEPLOYMENT_ENVIRONMENT: deployment_environment,
}
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dotenv import load_dotenv
from flask.testing import FlaskClient
from opentelemetry import trace
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from synapseclient.client import Synapse

from schematic.configuration.configuration import CONFIG, Configuration
Expand Down Expand Up @@ -42,6 +43,8 @@
TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(TESTS_DIR, "data")

FlaskInstrumentor().uninstrument()


@pytest.fixture(scope="session")
def dataset_id():
Expand Down

0 comments on commit 7a1c183

Please sign in to comment.