Exemple #1
0
def get_tracer_provider() -> TracerProvider:
    """Gets the current global :class:`~.TracerProvider` object."""
    global _TRACER_PROVIDER  # pylint: disable=global-statement

    if _TRACER_PROVIDER is None:
        _TRACER_PROVIDER = cast(  # type: ignore
            "TracerProvider",
            _load_provider(OTEL_PYTHON_TRACER_PROVIDER, "tracer_provider"),
        )
    return _TRACER_PROVIDER
def get_meter_provider() -> MeterProvider:
    """Gets the current global :class:`~.MeterProvider` object."""

    if _METER_PROVIDER is None:
        if OTEL_PYTHON_METER_PROVIDER not in environ.keys():
            return _PROXY_METER_PROVIDER

        meter_provider: MeterProvider = _load_provider(
            OTEL_PYTHON_METER_PROVIDER, "meter_provider")
        _set_meter_provider(meter_provider, log=False)

    # _METER_PROVIDER will have been set by one thread
    return cast("MeterProvider", _METER_PROVIDER)
def get_tracer_provider() -> TracerProvider:
    """Gets the current global :class:`~.TracerProvider` object."""
    if _TRACER_PROVIDER is None:
        # if a global tracer provider has not been set either via code or env
        # vars, return a proxy tracer provider
        if OTEL_PYTHON_TRACER_PROVIDER not in os.environ:
            return _PROXY_TRACER_PROVIDER

        tracer_provider: TracerProvider = _load_provider(
            OTEL_PYTHON_TRACER_PROVIDER, "tracer_provider"
        )
        _set_tracer_provider(tracer_provider, log=False)
    # _TRACER_PROVIDER will have been set by one thread
    return cast("TracerProvider", _TRACER_PROVIDER)
def get_log_emitter_provider() -> LogEmitterProvider:
    """Gets the current global :class:`~.LogEmitterProvider` object."""
    global _LOG_EMITTER_PROVIDER  # pylint: disable=global-statement
    if _LOG_EMITTER_PROVIDER is None:
        if _OTEL_PYTHON_LOG_EMITTER_PROVIDER not in os.environ:
            _LOG_EMITTER_PROVIDER = LogEmitterProvider()
            return _LOG_EMITTER_PROVIDER

        _LOG_EMITTER_PROVIDER = cast(
            "LogEmitterProvider",
            _load_provider(_OTEL_PYTHON_LOG_EMITTER_PROVIDER,
                           "log_emitter_provider"),
        )

    return _LOG_EMITTER_PROVIDER
def get_tracer_provider() -> TracerProvider:
    """Gets the current global :class:`~.TracerProvider` object."""
    # pylint: disable=global-statement
    global _TRACER_PROVIDER
    global _PROXY_TRACER_PROVIDER

    if _TRACER_PROVIDER is None:
        # if a global tracer provider has not been set either via code or env
        # vars, return a proxy tracer provider
        if OTEL_PYTHON_TRACER_PROVIDER not in os.environ:
            if not _PROXY_TRACER_PROVIDER:
                _PROXY_TRACER_PROVIDER = ProxyTracerProvider()
            return _PROXY_TRACER_PROVIDER

        _TRACER_PROVIDER = cast(  # type: ignore
            "TracerProvider",
            _load_provider(OTEL_PYTHON_TRACER_PROVIDER, "tracer_provider"),
        )
    return _TRACER_PROVIDER