# Path: e2e-test-server/e2e_test_server/constants.py
# INSTRUMENTING_MODULE_NAME = "opentelemetry-ops-e2e-test-server"
# 
# PROJECT_ID = os.environ["PROJECT_ID"]
# 
# TEST_ID = "test_id"
# 
# TRACE_ID = "trace_id"


import contextlib
import dataclasses
from typing import Callable, Iterator, Mapping
from google.rpc import code_pb2
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.propagators.cloud_trace_propagator import (
    CloudTraceFormatPropagator,
)
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace.sampling import ALWAYS_ON
from opentelemetry.trace import SpanKind, Tracer, format_trace_id
from pydantic import BaseModel
from .constants import INSTRUMENTING_MODULE_NAME, PROJECT_ID, TEST_ID, TRACE_ID




class Request(BaseModel):
    test_id: str
    headers: Mapping[str, str]
    data: bytes


@dataclasses.dataclass
class Response:
    status_code: code_pb2.Code
    headers: dict[str, str] = dataclasses.field(default_factory=dict)
    data: bytes = bytes()


@contextlib.contextmanager
def _tracer_setup() -> Iterator[Tracer]:
    """\
    Context manager with common setup for tracing endpoints

    Yields a tracer (from a fresh SDK with new exporter) then finally flushes
    spans created during the test after.
    """

    tracer_provider = TracerProvider(sampler=ALWAYS_ON)
    tracer_provider.add_span_processor(
        BatchSpanProcessor(CloudTraceSpanExporter(project_id=PROJECT_ID))
    )

# Path: e2e-test-server/e2e_test_server/constants.py
# INSTRUMENTING_MODULE_NAME = "opentelemetry-ops-e2e-test-server"
# 
# PROJECT_ID = os.environ["PROJECT_ID"]
# 
# TEST_ID = "test_id"
# 
# TRACE_ID = "trace_id"


# Path: e2e-test-server/e2e_test_server/scenarios.py
import contextlib
import dataclasses
from typing import Callable, Iterator, Mapping
from google.rpc import code_pb2
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.propagators.cloud_trace_propagator import (
    CloudTraceFormatPropagator,
)
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace.sampling import ALWAYS_ON
from opentelemetry.trace import SpanKind, Tracer, format_trace_id
from pydantic import BaseModel
from .constants import INSTRUMENTING_MODULE_NAME, PROJECT_ID, TEST_ID, TRACE_ID





class Request(BaseModel):
    test_id: str
    headers: Mapping[str, str]
    data: bytes


@dataclasses.dataclass
class Response:
    status_code: code_pb2.Code
    headers: dict[str, str] = dataclasses.field(default_factory=dict)
    data: bytes = bytes()


@contextlib.contextmanager
def _tracer_setup() -> Iterator[Tracer]:
    """\
    Context manager with common setup for tracing endpoints

    Yields a tracer (from a fresh SDK with new exporter) then finally flushes
    spans created during the test after.
    """

    tracer_provider = TracerProvider(sampler=ALWAYS_ON)
    tracer_provider.add_span_processor(
        BatchSpanProcessor(CloudTraceSpanExporter(project_id=PROJECT_ID))
    )

    tracer = tracer_provider.get_tracer(INSTRUMENTING_MODULE_NAME)