Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Otel pytest plugin #1217

Merged
merged 13 commits into from
Jul 27, 2021
Merged

Conversation

kuisathaverat
Copy link
Contributor

@kuisathaverat kuisathaverat commented Jul 22, 2021

What does this PR do?

  • Reimplementation of our pytest_apm plugin to work with OpenTelemetry

Why is it important?

With this plugin we can report OpenTelemetry data related with the execution of tests implemented with pytest

Test Locally

  1. Run the OpenTelemetry Collector in debug mode
git clone [email protected]:kuisathaverat/apm-pipeline-library.git 
cd apm-pipeline-library/resources/scripts/pytest_otel
git checkout pytest_otel
make run-otel-collector
  1. In another terminal in the same folder run the sample tests
make test
  1. Check the OpenTelemetry Collector console output to see the transactions and span logs.
InstrumentationLibrary Test Suit 
Span #0
    Trace ID       : d2e52557b4865e2f3c19ec9e3f3c779b
    Parent ID      : 
    ID             : 200590773ff3bf30
    Name           : Running test_xfail
    Kind           : SPAN_KIND_INTERNAL
    Start time     : 2021-07-22 17:27:04.595932 +0000 UTC
    End time       : 2021-07-22 17:27:12.602354 +0000 UTC
    Status code    : STATUS_CODE_ERROR
    Status message : 
Attributes:
     -> test.name: STRING(test_xfail)
     -> test.stack_trace: STRING(['Traceback (most recent call last):\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/_pytest/python.py", line 1641, in runtest\n    self.ihook.pytest_pyfunc_call(pyfuncitem=self)\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__\n    return self._hookexec(self, self.get_hookimpls(), kwargs)\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec\n    return self._inner_hookexec(hook, methods, kwargs)\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>\n    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall\n    return outcome.get_result()\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result\n    raise ex[1].with_traceback(ex[2])\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall\n    res = hook_impl.function(*args)\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/.venv/lib/python3.9/site-packages/_pytest/python.py", line 183, in pytest_pyfunc_call\n    result = testfunction(**testargs)\n', '  File "/home/myuser/src/apm-pipeline-library/resources/scripts/pytest_otel/test_pytest_otel.py", line 56, in test_xfail\n    assert False\n', 'AssertionError: assert False\n'])
     -> test.error: STRING(assert False)
     -> test.last_value: STRING(assert False)
     -> test.last_type: STRING(<class 'AssertionError'>)
     -> test.xfailed: STRING()
     -> test.outcome: STRING(failed)
Span #1
    Trace ID       : 4b3603762fe8cbb8e829f284f1dd4e93
    Parent ID      : 
    ID             : 1554f2907ae6edb1
    Name           : Test Suit
    Kind           : SPAN_KIND_INTERNAL
    Start time     : 2021-07-22 17:26:38.497736 +0000 UTC
    End time       : 2021-07-22 17:27:12.635571 +0000 UTC
    Status code    : STATUS_CODE_OK
    Status message : 
Attributes:
     -> test.outcome: STRING(passed)

Test with APM Server

OTEL_EXPORTER_OTLP_ENDPOINT=https://apm.example.com OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer ${APM_TOKEN}" make test

image

@kuisathaverat kuisathaverat added test Team:Automation Label for the Observability productivity team labels Jul 22, 2021
@kuisathaverat kuisathaverat requested review from cyrille-leclerc and a team July 22, 2021 17:40
@kuisathaverat kuisathaverat self-assigned this Jul 22, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Jul 22, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-07-27T09:48:13.072+0000

  • Duration: 11 min 28 sec

  • Commit: ec43df6

Test stats 🧪

Test Results
Failed 0
Passed 1181
Skipped 2
Total 1183

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 1181
Skipped 2
Total 1183

@cyrille-leclerc
Copy link
Contributor

It's very exciting, would it deserve a dedicated github repository pytest-otel that could eventually end up being donated to https://github.com/pytest-dev ?

Co-authored-by: Cyrille Le Clerc <[email protected]>
@v1v v1v changed the title feat: Otel pytest pluging feat: Otel pytest plugin Jul 23, 2021
@kuisathaverat
Copy link
Contributor Author

It's very exciting, would it deserve a dedicated github repository pytest-otel that could eventually end up being donated to https://github.com/pytest-dev ?

sure let's tested in a couple of our projects tune it and then we would create a new repo for it

resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/README.md Outdated Show resolved Hide resolved
resources/scripts/pytest_otel/pytest_otel.py Outdated Show resolved Hide resolved
@v1v v1v mentioned this pull request Jul 26, 2021
Copy link
Member

@v1v v1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding!!! 🤟

@kuisathaverat kuisathaverat merged commit 9c1f57a into elastic:master Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Automation Label for the Observability productivity team test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants