from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import SpanProcessor
from opentelemetry.sdk.trace.export import (
    SimpleSpanProcessor,
)

from ...wrappers import FileSpanExporter, ScopeFilterExporter
from ..base import Exporter
from .types import FileConfig


class FileExporter(Exporter):
    config: FileConfig

    def __init__(self, config: FileConfig):
        self.config = config

    def create_span_processor(self, resource: Resource) -> SpanProcessor:
        """Create a span processor for the file exporter w/ scope filtering."""
        file_span_exporter = FileSpanExporter(self.config["folder_path"])
        exporter = ScopeFilterExporter(
            file_span_exporter,
            self.config,
        )

        return SimpleSpanProcessor(exporter)
