Skip to content

Commit

Permalink
[SCHEMATIC-212] Prevent traces from being combined (#1552)
Browse files Browse the repository at this point in the history
* Set instance id in github CI run, uninstrument flask auto during integration test run
  • Loading branch information
BryanFauble authored Nov 25, 2024
1 parent 998e295 commit c3e0732
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
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
2 changes: 2 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ SERVICE_ACCOUNT_CREDS='Provide service account creds'
# LOGGING_EXPORT_FORMAT=otlp
# TRACING_SERVICE_NAME=schematic-api
# LOGGING_SERVICE_NAME=schematic-api
## Instance ID is used during integration tests export to identify the git branch
# SERVICE_INSTANCE_ID=schematic-1234
## Other examples: dev, staging, prod
# DEPLOYMENT_ENVIRONMENT=local
# OTEL_EXPORTER_OTLP_ENDPOINT=https://..../telemetry
Expand Down
5 changes: 5 additions & 0 deletions schematic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
from opentelemetry.sdk.resources import (
DEPLOYMENT_ENVIRONMENT,
SERVICE_INSTANCE_ID,
SERVICE_NAME,
SERVICE_VERSION,
Resource,
Expand Down Expand Up @@ -97,10 +98,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,
SERVICE_VERSION: __version__,
DEPLOYMENT_ENVIRONMENT: deployment_environment,
Expand All @@ -124,9 +127,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,
SERVICE_VERSION: __version__,
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 c3e0732

Please sign in to comment.