Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

otel-extensions-pytest

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

otel-extensions-pytest

pytest extensions for OpenTelemetry

  • 0.2.1
  • Source
  • PyPI
  • Socket score

Maintainers
1

otel-extensions-pytest: A pytest extension for OpenTelemetry

otel-extensions-pytest is a pytest plugin that will automatically instrument a pytest-based test session, wrapping the test session in a span and wrapping each test in a child span.

Dependencies

  • Python >= 3.6
  • pytest >= 6.2

Installation

pip install

You can install through pip using:

pip install otel-extensions-pytest

(you may need to run pip with root permission: sudo pip install otel-extensions-pytest)

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Usage

Enable the plugin by adding

pytest_plugins = ("otel_extensions_pytest",)

to your conftest.py, or by adding the option -p otel_extensions_pytest to the pytest command line.

For tracing to be enabled, you need to specify a trace receiver endpoint using the command-line option --otel-endpoint or by setting the environment variable OTEL_EXPORTER_OTLP_ENDPOINT. e.g. --otel-endpoint http://localhost:4317/

The full set of options are shown here:

Command-line OptionEnvironment VariableDescription
--otel_service_nameOTEL_SERVICE_NAMEName of resource/service for traces
--otel_session_nameOTEL_SESSION_NAMEName of parent session span
--otel_endpointOTEL_EXPORTER_OTLP_ENDPOINTOTLP Receiver Endpoint
--otel_protocolOTEL_EXPORTER_OTLP_PROTOCOLprotocol for OTLP receiver (supported: gprc , http/protobuf , custom)
--otel_processor_typeOTEL_PROCESSOR_TYPESpan Processor type (batch: use BatchSpanProcessor, simple: use SimpleSpanProcessor
--otel_traceparentTRACEPARENTParent span id. Will be injected into current context (useful when running automated tests using the OpenTelemetry Jenkins plugin)
n/aOTEL_EXPORTER_OTLP_CERTIFICATEpath to CA bundle for verifying TLS cert of receiver endpoint
n/aOTEL_EXPORTER_CUSTOM_SPAN_EXPORTER_TYPECustom span exporter class (needed if protocol set to custom)

Additional Features

@instrumented_fixture decorator

You can decorate fixtures by using the @instrumented_fixture decorator. If the fixture is a generator (i.e. has a yield statement), separate spans will be created for the setup and teardown phases.

from otel_extensions_pytest import instrumented_fixture

# note: all options of pytest.fixture() are supported (autouse, etc)
@instrumented_fixture(scope="function")
def my_fixture():
    """ Span is automatically created using `my_fixture` as span name """
    return "foo"

@instrumented_fixture(scope="function")
def my_generator_fixture():
    # A span named `my_generator_fixture (setup)` is automatically created for this section
    time.sleep(5)
    
    yield "foo"
    
    # A span named `my_generator_fixture (teardown)` is automatically created for this section
    time.sleep(5)
    

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc