Skip to content

Commit

Permalink
Add sklearn instrumentation and ML model feature support (#921)
Browse files Browse the repository at this point in the history
* Add tree model function traces (#691)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Follow two digit convention

* Make if-else a one-liner

* Abstract to re-usable instrumentation function

* Use wrap_method_trace & change to Function group

Co-authored-by: Timothy Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Fixup: use if-else one-liner

* Use hasattr instead of model name check

* Change component_sklearn to mlmodel_sklearn

* Fixup: replace in model names with hasattr

Co-authored-by: Timothy Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Add config setting for sklearn inference event capture. (#706)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Follow two digit convention

* Make if-else a one-liner

* Abstract to re-usable instrumentation function

* Add ML inference event capture config setting.

* [Mega-Linter] Apply linters fixes

* Fixup: remove component_sklearn files

* Add high security mode testing for ML events setting.

* [Mega-Linter] Apply linters fixes

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>

* Capture scorer results (#694)

* Add score results attributes to metric scorers

* Test un-subclassable types

* [Mega-Linter] Apply linters fixes

* [Mega-Linter] Apply linters fixes

* Trigger tests

* Remove custom subclassing code.

* [Mega-Linter] Apply linters fixes

* Remove unused function

* Add test for iterable score results

* Change name of object proxy

* Fixup: rename proxy in tests too

Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: Tim Pansino <timpansino@gmail.com>
Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>

* Add ensemble model function traces (#697)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Remove breakpoints

* Remove commited config files

* Group tests into more readable format

* Pin startlette latest < 0.23.1

* Convert PY3 checks to one-liners

* Use tuple checks for sklearn version

Use tuple checks for sklearn version, string checks can result in unexpected out of
order comparisons. Also use direct comparisons for easier readability.

* Fix VotingRegressor test

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Include training step in metric scorer name (#712)

* Include training step in scorer name

* Add fit_predict data proxying

* Remove name comments

* Fix predict being called before fit

* Re-use existing fixture

* Add cluster model function traces (#700)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Add cluster model instrumentaton

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Fix some cluster model tests

* Fix tests after ensemble PR merge

* Add transform to tests

* Remove accidental commits

* Modify cluster tests to be more readable

* Break up instrumentation models

* Remove duplicate ensemble module defs

* Modify VotingRegressor test

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add calibration model function traces (#709)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Remove breakpoints

* Create tests/instrumentation for calibration models

* Fix calibration tests

* Remove commented out code

* Remove yaml file in commit

* Remove duplicate ensemble module defs

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add svm model function traces (#733)

* Add svm models

* Remove extra conditionals from testing

* Add semi supervised models (#732)

* Add pipeline model function traces (#730)

* Add pipeline models

* Remove commented code

* Add neural network model function traces (#729)

* Add neural network models

* Fixup: merge conflict

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

* Add neighbors models (#728)

* Add mixture models (#725)

* Add model selection model function traces (#726)

* Add outline for model selection tests

* Add some testing to model selection

* Add hooks

* Add estimator

* Finish testing for model selection

* Add naive bayes models (#724)

* Add multioutput models (#723)

* Add multiclass models (#722)

* Add kernel ridge model function traces (#721)

* Add kernel ridge models

* Modify VotingRegressor test

* Add custom feature events for sklearn (#727)

* Add function traces around model methods

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Instrument predict function.

* Add data trains fixture.

* Add testing and cleanup for custom feature events.

* Update test_tree_models.

* Add back training step logic to predict proxy.

* Remove unused files.

* Add tree model function traces (#691)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Follow two digit convention

* Make if-else a one-liner

* Abstract to re-usable instrumentation function

* Use wrap_method_trace & change to Function group

Co-authored-by: Timothy Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Fixup: use if-else one-liner

* Use hasattr instead of model name check

* Change component_sklearn to mlmodel_sklearn

* Fixup: replace in model names with hasattr

Co-authored-by: Timothy Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Add config setting for sklearn inference event capture. (#706)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Follow two digit convention

* Make if-else a one-liner

* Abstract to re-usable instrumentation function

* Add ML inference event capture config setting.

* [Mega-Linter] Apply linters fixes

* Fixup: remove component_sklearn files

* Add high security mode testing for ML events setting.

* [Mega-Linter] Apply linters fixes

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>

* Capture scorer results (#694)

* Add score results attributes to metric scorers

* Test un-subclassable types

* [Mega-Linter] Apply linters fixes

* [Mega-Linter] Apply linters fixes

* Trigger tests

* Remove custom subclassing code.

* [Mega-Linter] Apply linters fixes

* Remove unused function

* Add test for iterable score results

* Change name of object proxy

* Fixup: rename proxy in tests too

Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: Tim Pansino <timpansino@gmail.com>
Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>

* Add ensemble model function traces (#697)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Remove breakpoints

* Remove commited config files

* Group tests into more readable format

* Pin startlette latest < 0.23.1

* Convert PY3 checks to one-liners

* Use tuple checks for sklearn version

Use tuple checks for sklearn version, string checks can result in unexpected out of
order comparisons. Also use direct comparisons for easier readability.

* Fix VotingRegressor test

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add function traces around model methods

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Instrument predict function.

* Add data trains fixture.

* Add testing and cleanup for custom feature events.

* Update test_tree_models.

* Include training step in metric scorer name (#712)

* Include training step in scorer name

* Add fit_predict data proxying

* Remove name comments

* Fix predict being called before fit

* Re-use existing fixture

* Add cluster model function traces (#700)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Add cluster model instrumentaton

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Fix some cluster model tests

* Fix tests after ensemble PR merge

* Add transform to tests

* Remove accidental commits

* Modify cluster tests to be more readable

* Break up instrumentation models

* Remove duplicate ensemble module defs

* Modify VotingRegressor test

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add calibration model function traces (#709)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Remove breakpoints

* Create tests/instrumentation for calibration models

* Fix calibration tests

* Remove commented out code

* Remove yaml file in commit

* Remove duplicate ensemble module defs

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add back training step logic to predict proxy.

* Remove unused files.

* Address py27 test failures and review comments.

* Fix py 3.7 failures.

* Remove old component_sklearn.py file

* Fix lint errors

* [Mega-Linter] Apply linters fixes

* Merge redis fix.

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: Timothy Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>
Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: Tim Pansino <timpansino@gmail.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add feature selection model function traces (#719)

* Add feature selection models

* Modify VotingRegressor test

* Add dummy model function traces (#718)

* Add gaussian process model function traces (#720)

* Add gaussian process models

* Modify VotingRegressor test

* Modify Gaussian Process models tests

* Add discriminant analysis model (#717)

* Add cross decomposition models (#716)

* Add covariance model (#714)

* Add compose models (#713)

* Add linear model function traces (#703)

* Add sklearn to tox

* Add function traces around model methods

* Support Python 2.7 & 3.7 sklearn

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Add ensemble models

* Add ensemble model tests

* Edit tests

* Add ensemble library models from sklearn

* Start tests with empty commit

* Clean up tests

* Initial linear model commit

* Clean up tests for linear models

* Fix tests for various versions of sklearn

* Fix ensemble tests with changes from tree PR

* [Mega-Linter] Apply linters fixes

* Remove breakpoints

* Merge changes from ensemble PR

* Fix tests for v0.20.0

* Rewrite linear tests to be more readable

* Break up instrumentation in config

* Remove commented code

* Remove yaml file in commit

* Remove duplicate ensemble module defs

* Remove old no longer used file

* Remove commented out code.

* Change test name and modify VotingRegressor test

* Push empty commit

* Modify VotingRegression test

* Add estimator to VotingRegressor

* Revert VotingRegressor test

* Fix ensemble tests

* Add different models for VotingRegressor test

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Add ml_model function wrapper API (#739)

* Add function traces around model methods

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Instrument predict function.

* Add data trains fixture.

* Add testing and cleanup for custom feature events.

* Update test_tree_models.

* Add back training step logic to predict proxy.

* Remove unused files.

* Add ml_model wrapper and tests.

* Add column name logic.

* Update branch.

* Update column name mapping logic.

* Fix py2 failures.

* Fix pypy37 failure.

* Revise feature_names logic.

* Add more ml_model wrapper testing.

* Fix linter unused import

* [Mega-Linter] Apply linters fixes

* Bump tests.

* Bump tests.

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>

* Report feature event w/o value (#754)

Report the feature event w/o the raw value if
`machine_learning.inference_event_value.enabled` is False.

* Prediction metric stats (#715)

* Add function traces around model methods

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Instrument predict function.

* Add data trains fixture.

* Add testing and cleanup for custom feature events.

* Update test_tree_models.

* Add back training step logic to predict proxy.

* Remove unused files.

* Update branch.

* Add impl and testing for label events.

* [Mega-Linter] Apply linters fixes

* Add feature_name to expected events for int test.

* Fix py37 test.

* Add function traces around model methods

* Add test for multiple calls to model method

* Fixup: add comments & organize

* Refactor

* Instrument predict function.

* Add data trains fixture.

* Add testing and cleanup for custom feature events.

* Update test_tree_models.

* Add back training step logic to predict proxy.

* Remove unused files.

* Update branch.

* Add impl and testing for label events.

* Add feature_name to expected events for int test.

* [Mega-Linter] Apply linters fixes

* Fix py37 test.

* Update logic to not report value when setting is disabled.

* Fixup flake8 unused import

* Touch up label event logic and rename test_feature_events to test_inference_events.

* Add test case for multilabel output.

* Fix 2D np array test.

* Add metrics about prediction data

* Fixup

* Fix user provided label names

* Fixup label related column name tests

* [Mega-Linter] Apply linters fixes

* Assert label events in multilabel output test

* Remove return of stats

* Remove spaces from version specification

* Fix py2.7 output difference in pandas test

---------

Co-authored-by: Uma Annamalai <uannamalai@newrelic.com>
Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Add new ML event type (#802)

* Add new machine learning event data type

Co-authored-by: Tim Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Validate new machine learning event data type

Co-authored-by: Tim Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Fixup: minor inconsistencies

* Fixup

* Remove code coverage fixture

* Fix lint errors

* Increase timeout for python tests

---------

Co-authored-by: Tim Pansino <TimPansino@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Add machine learning and ml_event config options (#811)

* Add machine learning config options

* machine_learning.enabled
* machine_learning.inference_events.enable
* machine_learning.inference_events.value.enabled
* event_harvest_config.harvest_limits.ml_event_data

Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Replace all TODOs w/ new config settings

* [Mega-Linter] Apply linters fixes

* Trigger tests

* Add insights settings & tests

* Remove collect_custom_events & inference_events.enabled

* Revert inference_events_value=>.value

* Remove TODO

* Fixup: format docstring

* Remove file

* Add tests for machine_learning.enabled

---------

Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>
Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>

* Dimensional Metrics (#815)

* Wiring dimensional metrics

* Squashed commit of the following:

commit c2d4629dfd7787354b6607160bb952913975d5f7
Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Date:   Wed May 10 15:59:13 2023 -0700

    Add required option for tox v4 (#795)

    * Add required option for tox v4

    * Update tox in GHA

    * Remove py27 no-cache-dir

commit a9636498ab5c20c266fb044a08359c0c9bbcf826
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Tue May 9 10:46:39 2023 -0700

    Run coverage around pytest (#813)

    * Run coverage around pytest

    * Trigger tests

    * Fixup

    * Add redis client_no_touch to ignore list

    * Temporarily remove kafka from coverage

    * Remove coverage for old libs

commit 3d8284540e0acd867c2cf680f43449bc128c0779
Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Date:   Wed May 3 14:50:30 2023 -0700

    Omit some frameworks from coverage analysis (#810)

    * Omit some frameworks from coverage analysis

    * Remove commas

    * Change format of omit

    * Add relative_files option to coverage

    * Add absolute directory

    * Add envsitepackagedir

    * Add coveragerc file

    * Add codecov.yml

    * [Mega-Linter] Apply linters fixes

    * Revert coveragerc file settings

    * Add files in packages and more frameworks

    * Remove commented line

    ---------

    Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
    Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

commit fd0fa35466b630e34e8476cc53ad0e163564e2de
Author: Uma Annamalai <uannamalai@newrelic.com>
Date:   Tue May 2 10:55:36 2023 -0700

    Add testing for genshi and mako. (#799)

    * Add testing for genshi and mako.

    * [Mega-Linter] Apply linters fixes

    ---------

    Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit be4fb3dda0e734889acd6bc53cf91f26c18c2118
Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Date:   Mon May 1 16:01:09 2023 -0700

    Add tests for Waitress (#797)

    * Change import format

    * Initial commit

    * Add more tests to adapter_waitress

    * Remove commented out code

    * [Mega-Linter] Apply linters fixes

    * Add assertions to all tests

    * Add more NR testing to waitress

    ---------

    Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 7103506ca5639d339e3e47dfb9e4affb546c839b
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Mon May 1 14:12:31 2023 -0700

    Add tests for pyodbc (#796)

    * Add tests for pyodbc

    * Move imports into tests to get import coverage

    * Fixup: remove time import

    * Trigger tests

    ---------

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 363122a0efe0ad9f4784fc1f67fda046cb9bb7e8
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Mon May 1 13:34:35 2023 -0700

    Pin virtualenv, fix pip arg deprecation & disable kafka tests (#803)

    * Pin virtualenv

    * Fixup: use 20.21.1 instead

    * Replace install-options with config-settings

    See https://github.com/pypa/pip/issues/11358.

    * Temporarily disable kafka tests

* Add dimensional stats table to stats engine

* Add attribute processing to metric identity

* Add testing for dimensional metrics

* Cover tags as list not dict

* Commit suggestions from code review

* Add OTLP protocol class & protos (#821)

* Add protos under packages for otlp

* Add common otlp proto payload methods

* Add new oltp protocol class

* Remove ML event from log message

* Remove params, add api-key header & expose path

The params are not relevant to OTLP so remove these.
The api-key header is how we provide the license key to OTLP so add this.
The path to upload dimensional metrics and events are different in OTLP so expose
the path so it can be overriden inside the coresponding data_collector methods.

* Add otlp_port and otlp_host settings

* Default to JSON if protobuf not available & warn

* Move otlp_utils to core

* Call encode in protocol class

* Patch issues with data collector

* Move resource to utils & add log proto imports

---------

Co-authored-by: Tim Pansino <timpansino@gmail.com>

* Fix Testing Failures (#828)

* Fix tastypie tests

* Adjust asgiref pinned version

* Make aioredis key PID unique

* Pin more asgiref versions

* Fix pytest test filtering when running tox (#823)

Co-authored-by: Uma Annamalai <uannamalai@newrelic.com>

* OTLP Serialization for Dimensional Metrics (#826)

* Add protos under packages for otlp

* Add common otlp proto payload methods

* Add new oltp protocol class

* Remove ML event from log message

* Remove params, add api-key header & expose path

The params are not relevant to OTLP so remove these.
The api-key header is how we provide the license key to OTLP so add this.
The path to upload dimensional metrics and events are different in OTLP so expose
the path so it can be overriden inside the coresponding data_collector methods.

* Add metric protos

* Use protos to create payload

* Squashed commit of the following:

commit 6f15520cea6a1098915c9ca340dbe42de6a5de1d
Author: Tim Pansino <timpansino@gmail.com>
Date:   Mon May 15 14:28:50 2023 -0700

    TEMP

commit 1a28d36f86dd3f1fa5ca7a8f56357d168aac69db
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 17:28:27 2023 -0700

    Cover tags as list not dict

commit 71261e3d468320569742a72c690f6ff4e9b3e621
Merge: 459e08567 c2d4629df
Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Date:   Thu May 11 16:59:11 2023 -0700

    Merge branch 'main' into feature-dimensional-metrics

commit 459e08567102cfadce398b57d245ecf99408400d
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 16:57:16 2023 -0700

    Add testing for dimensional metrics

commit ed33957cd2b20bc1f6e9759a0bad5e4f4a86a38c
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 16:56:31 2023 -0700

    Add attribute processing to metric identity

commit 6caf71ef4386395d950060e0e996f80dbcbfbc32
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 16:56:16 2023 -0700

    Add dimensional stats table to stats engine

commit 5e1cc9dea6d0d9623130dedd0f787408a8439388
Author: Tim Pansino <timpansino@gmail.com>
Date:   Wed May 10 16:00:42 2023 -0700

    Squashed commit of the following:

    commit c2d4629dfd7787354b6607160bb952913975d5f7
    Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
    Date:   Wed May 10 15:59:13 2023 -0700

        Add required option for tox v4 (#795)

        * Add required option for tox v4

        * Update tox in GHA

        * Remove py27 no-cache-dir

    commit a9636498ab5c20c266fb044a08359c0c9bbcf826
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Tue May 9 10:46:39 2023 -0700

        Run coverage around pytest (#813)

        * Run coverage around pytest

        * Trigger tests

        * Fixup

        * Add redis client_no_touch to ignore list

        * Temporarily remove kafka from coverage

        * Remove coverage for old libs

    commit 3d8284540e0acd867c2cf680f43449bc128c0779
    Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
    Date:   Wed May 3 14:50:30 2023 -0700

        Omit some frameworks from coverage analysis (#810)

        * Omit some frameworks from coverage analysis

        * Remove commas

        * Change format of omit

        * Add relative_files option to coverage

        * Add absolute directory

        * Add envsitepackagedir

        * Add coveragerc file

        * Add codecov.yml

        * [Mega-Linter] Apply linters fixes

        * Revert coveragerc file settings

        * Add files in packages and more frameworks

        * Remove commented line

        ---------

        Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
        Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

    commit fd0fa35466b630e34e8476cc53ad0e163564e2de
    Author: Uma Annamalai <uannamalai@newrelic.com>
    Date:   Tue May 2 10:55:36 2023 -0700

        Add testing for genshi and mako. (#799)

        * Add testing for genshi and mako.

        * [Mega-Linter] Apply linters fixes

        ---------

        Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit be4fb3dda0e734889acd6bc53cf91f26c18c2118
    Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
    Date:   Mon May 1 16:01:09 2023 -0700

        Add tests for Waitress (#797)

        * Change import format

        * Initial commit

        * Add more tests to adapter_waitress

        * Remove commented out code

        * [Mega-Linter] Apply linters fixes

        * Add assertions to all tests

        * Add more NR testing to waitress

        ---------

        Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit 7103506ca5639d339e3e47dfb9e4affb546c839b
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Mon May 1 14:12:31 2023 -0700

        Add tests for pyodbc (#796)

        * Add tests for pyodbc

        * Move imports into tests to get import coverage

        * Fixup: remove time import

        * Trigger tests

        ---------

        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit 363122a0efe0ad9f4784fc1f67fda046cb9bb7e8
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Mon May 1 13:34:35 2023 -0700

        Pin virtualenv, fix pip arg deprecation & disable kafka tests (#803)

        * Pin virtualenv

        * Fixup: use 20.21.1 instead

        * Replace install-options with config-settings

        See https://github.com/pypa/pip/issues/11358.

        * Temporarily disable kafka tests

commit c2d4629dfd7787354b6607160bb952913975d5f7
Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Date:   Wed May 10 15:59:13 2023 -0700

    Add required option for tox v4 (#795)

    * Add required option for tox v4

    * Update tox in GHA

    * Remove py27 no-cache-dir

commit a9636498ab5c20c266fb044a08359c0c9bbcf826
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Tue May 9 10:46:39 2023 -0700

    Run coverage around pytest (#813)

    * Run coverage around pytest

    * Trigger tests

    * Fixup

    * Add redis client_no_touch to ignore list

    * Temporarily remove kafka from coverage

    * Remove coverage for old libs

commit dc81a50a9fc5f2a5ce6978aa064fdfab1618328b
Author: Tim Pansino <timpansino@gmail.com>
Date:   Sat May 6 14:16:14 2023 -0700

    Wiring dimensional metrics

commit 3d8284540e0acd867c2cf680f43449bc128c0779
Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Date:   Wed May 3 14:50:30 2023 -0700

    Omit some frameworks from coverage analysis (#810)

    * Omit some frameworks from coverage analysis

    * Remove commas

    * Change format of omit

    * Add relative_files option to coverage

    * Add absolute directory

    * Add envsitepackagedir

    * Add coveragerc file

    * Add codecov.yml

    * [Mega-Linter] Apply linters fixes

    * Revert coveragerc file settings

    * Add files in packages and more frameworks

    * Remove commented line

    ---------

    Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
    Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

commit fd0fa35466b630e34e8476cc53ad0e163564e2de
Author: Uma Annamalai <uannamalai@newrelic.com>
Date:   Tue May 2 10:55:36 2023 -0700

    Add testing for genshi and mako. (#799)

    * Add testing for genshi and mako.

    * [Mega-Linter] Apply linters fixes

    ---------

    Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit be4fb3dda0e734889acd6bc53cf91f26c18c2118
Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Date:   Mon May 1 16:01:09 2023 -0700

    Add tests for Waitress (#797)

    * Change import format

    * Initial commit

    * Add more tests to adapter_waitress

    * Remove commented out code

    * [Mega-Linter] Apply linters fixes

    * Add assertions to all tests

    * Add more NR testing to waitress

    ---------

    Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 7103506ca5639d339e3e47dfb9e4affb546c839b
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Mon May 1 14:12:31 2023 -0700

    Add tests for pyodbc (#796)

    * Add tests for pyodbc

    * Move imports into tests to get import coverage

    * Fixup: remove time import

    * Trigger tests

    ---------

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Squashed commit of the following:

commit 7a384c5935f8d6d24db9b488a7e48a6854efedd6
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu Jun 1 12:10:59 2023 -0700

    Cleaning out agent protocol

commit c87d31d5d3a91eb7c584f32f9831fbebc1ffe378
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu Jun 1 12:10:46 2023 -0700

    Change content-type header

commit 5750e546797b16f96e71161f794cb34a253418a6
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu Jun 1 12:05:52 2023 -0700

    Add common utilities for OTLP

* Remove testing logic

* Adding metric serialization helpers

* Squashed commit of the following:

commit a47e209925a210e85bb6c57f0a2efa9e99630b7f
Author: Tim Pansino <timpansino@gmail.com>
Date:   Tue Jun 6 11:11:30 2023 -0700

    Commit suggestions from code review

commit 1a28d36f86dd3f1fa5ca7a8f56357d168aac69db
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 17:28:27 2023 -0700

    Cover tags as list not dict

commit 71261e3d468320569742a72c690f6ff4e9b3e621
Merge: 459e08567 c2d4629df
Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Date:   Thu May 11 16:59:11 2023 -0700

    Merge branch 'main' into feature-dimensional-metrics

commit 459e08567102cfadce398b57d245ecf99408400d
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 16:57:16 2023 -0700

    Add testing for dimensional metrics

commit ed33957cd2b20bc1f6e9759a0bad5e4f4a86a38c
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 16:56:31 2023 -0700

    Add attribute processing to metric identity

commit 6caf71ef4386395d950060e0e996f80dbcbfbc32
Author: Tim Pansino <timpansino@gmail.com>
Date:   Thu May 11 16:56:16 2023 -0700

    Add dimensional stats table to stats engine

commit 5e1cc9dea6d0d9623130dedd0f787408a8439388
Author: Tim Pansino <timpansino@gmail.com>
Date:   Wed May 10 16:00:42 2023 -0700

    Squashed commit of the following:

    commit c2d4629dfd7787354b6607160bb952913975d5f7
    Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
    Date:   Wed May 10 15:59:13 2023 -0700

        Add required option for tox v4 (#795)

        * Add required option for tox v4

        * Update tox in GHA

        * Remove py27 no-cache-dir

    commit a9636498ab5c20c266fb044a08359c0c9bbcf826
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Tue May 9 10:46:39 2023 -0700

        Run coverage around pytest (#813)

        * Run coverage around pytest

        * Trigger tests

        * Fixup

        * Add redis client_no_touch to ignore list

        * Temporarily remove kafka from coverage

        * Remove coverage for old libs

    commit 3d8284540e0acd867c2cf680f43449bc128c0779
    Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
    Date:   Wed May 3 14:50:30 2023 -0700

        Omit some frameworks from coverage analysis (#810)

        * Omit some frameworks from coverage analysis

        * Remove commas

        * Change format of omit

        * Add relative_files option to coverage

        * Add absolute directory

        * Add envsitepackagedir

        * Add coveragerc file

        * Add codecov.yml

        * [Mega-Linter] Apply linters fixes

        * Revert coveragerc file settings

        * Add files in packages and more frameworks

        * Remove commented line

        ---------

        Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
        Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

    commit fd0fa35466b630e34e8476cc53ad0e163564e2de
    Author: Uma Annamalai <uannamalai@newrelic.com>
    Date:   Tue May 2 10:55:36 2023 -0700

        Add testing for genshi and mako. (#799)

        * Add testing for genshi and mako.

        * [Mega-Linter] Apply linters fixes

        ---------

        Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit be4fb3dda0e734889acd6bc53cf91f26c18c2118
    Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
    Date:   Mon May 1 16:01:09 2023 -0700

        Add tests for Waitress (#797)

        * Change import format

        * Initial commit

        * Add more tests to adapter_waitress

        * Remove commented out code

        * [Mega-Linter] Apply linters fixes

        * Add assertions to all tests

        * Add more NR testing to waitress

        ---------

        Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit 7103506ca5639d339e3e47dfb9e4affb546c839b
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Mon May 1 14:12:31 2023 -0700

        Add tests for pyodbc (#796)

        * Add tests for pyodbc

        * Move imports into tests to get import coverage

        * Fixup: remove time import

        * Trigger tests

        ---------

        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit 363122a0efe0ad9f4784fc1f67fda046cb9bb7e8
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Mon May 1 13:34:35 2023 -0700

        Pin virtualenv, fix pip arg deprecation & disable kafka tests (#803)

        * Pin virtualenv

        * Fixup: use 20.21.1 instead

        * Replace install-options with config-settings

        See https://github.com/pypa/pip/issues/11358.

        * Temporarily disable kafka tests

commit c2d4629dfd7787354b6607160bb952913975d5f7
Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Date:   Wed May 10 15:59:13 2023 -0700

    Add required option for tox v4 (#795)

    * Add required option for tox v4

    * Update tox in GHA

    * Remove py27 no-cache-dir

commit a9636498ab5c20c266fb044a08359c0c9bbcf826
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Tue May 9 10:46:39 2023 -0700

    Run coverage around pytest (#813)

    * Run coverage around pytest

    * Trigger tests

    * Fixup

    * Add redis client_no_touch to ignore list

    * Temporarily remove kafka from coverage

    * Remove coverage for old libs

commit dc81a50a9fc5f2a5ce6978aa064fdfab1618328b
Author: Tim Pansino <timpansino@gmail.com>
Date:   Sat May 6 14:16:14 2023 -0700

    Wiring dimensional metrics

commit 3d8284540e0acd867c2cf680f43449bc128c0779
Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Date:   Wed May 3 14:50:30 2023 -0700

    Omit some frameworks from coverage analysis (#810)

    * Omit some frameworks from coverage analysis

    * Remove commas

    * Change format of omit

    * Add relative_files option to coverage

    * Add absolute directory

    * Add envsitepackagedir

    * Add coveragerc file

    * Add codecov.yml

    * [Mega-Linter] Apply linters fixes

    * Revert coveragerc file settings

    * Add files in packages and more frameworks

    * Remove commented line

    ---------

    Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
    Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

commit fd0fa35466b630e34e8476cc53ad0e163564e2de
Author: Uma Annamalai <uannamalai@newrelic.com>
Date:   Tue May 2 10:55:36 2023 -0700

    Add testing for genshi and mako. (#799)

    * Add testing for genshi and mako.

    * [Mega-Linter] Apply linters fixes

    ---------

    Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit be4fb3dda0e734889acd6bc53cf91f26c18c2118
Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Date:   Mon May 1 16:01:09 2023 -0700

    Add tests for Waitress (#797)

    * Change import format

    * Initial commit

    * Add more tests to adapter_waitress

    * Remove commented out code

    * [Mega-Linter] Apply linters fixes

    * Add assertions to all tests

    * Add more NR testing to waitress

    ---------

    Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 7103506ca5639d339e3e47dfb9e4affb546c839b
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Mon May 1 14:12:31 2023 -0700

    Add tests for pyodbc (#796)

    * Add tests for pyodbc

    * Move imports into tests to get import coverage

    * Fixup: remove time import

    * Trigger tests

    ---------

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Add protobuf to agent features tests

* Proper bucket dimensional metric serialization

* Wiring up OTLP protocol for metrics

* Correct metrics payloads

* Make default content-encoding header configurable

* Clean up otlp encoding

* Expand OTLP metrics testing

* Squashed commit of the following:

commit 30f0bf5ce27f239f70b236c639a49715f33ce948
Author: Hannah Stepanek <hstepanek@newrelic.com>
Date:   Fri Jun 9 16:12:09 2023 -0700

    Add OTLP protocol class & protos (#821)

    * Add protos under packages for otlp

    * Add common otlp proto payload methods

    * Add new oltp protocol class

    * Remove ML event from log message

    * Remove params, add api-key header & expose path

    The params are not relevant to OTLP so remove these.
    The api-key header is how we provide the license key to OTLP so add this.
    The path to upload dimensional metrics and events are different in OTLP so expose
    the path so it can be overriden inside the coresponding data_collector methods.

    * Add otlp_port and otlp_host settings

    * Default to JSON if protobuf not available & warn

    * Move otlp_utils to core

    * Call encode in protocol class

    * Patch issues with data collector

    * Move resource to utils & add log proto imports

    ---------

    Co-authored-by: Tim Pansino <timpansino@gmail.com>

commit e970884dac0e1f9c703c6fdbff408fb923502f51
Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Date:   Thu Jun 8 13:17:28 2023 -0700

    Dimensional Metrics (#815)

    * Wiring dimensional metrics

    * Squashed commit of the following:

    commit c2d4629dfd7787354b6607160bb952913975d5f7
    Author: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
    Date:   Wed May 10 15:59:13 2023 -0700

        Add required option for tox v4 (#795)

        * Add required option for tox v4

        * Update tox in GHA

        * Remove py27 no-cache-dir

    commit a9636498ab5c20c266fb044a08359c0c9bbcf826
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Tue May 9 10:46:39 2023 -0700

        Run coverage around pytest (#813)

        * Run coverage around pytest

        * Trigger tests

        * Fixup

        * Add redis client_no_touch to ignore list

        * Temporarily remove kafka from coverage

        * Remove coverage for old libs

    commit 3d8284540e0acd867c2cf680f43449bc128c0779
    Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
    Date:   Wed May 3 14:50:30 2023 -0700

        Omit some frameworks from coverage analysis (#810)

        * Omit some frameworks from coverage analysis

        * Remove commas

        * Change format of omit

        * Add relative_files option to coverage

        * Add absolute directory

        * Add envsitepackagedir

        * Add coveragerc file

        * Add codecov.yml

        * [Mega-Linter] Apply linters fixes

        * Revert coveragerc file settings

        * Add files in packages and more frameworks

        * Remove commented line

        ---------

        Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
        Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

    commit fd0fa35466b630e34e8476cc53ad0e163564e2de
    Author: Uma Annamalai <uannamalai@newrelic.com>
    Date:   Tue May 2 10:55:36 2023 -0700

        Add testing for genshi and mako. (#799)

        * Add testing for genshi and mako.

        * [Mega-Linter] Apply linters fixes

        ---------

        Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit be4fb3dda0e734889acd6bc53cf91f26c18c2118
    Author: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
    Date:   Mon May 1 16:01:09 2023 -0700

        Add tests for Waitress (#797)

        * Change import format

        * Initial commit

        * Add more tests to adapter_waitress

        * Remove commented out code

        * [Mega-Linter] Apply linters fixes

        * Add assertions to all tests

        * Add more NR testing to waitress

        ---------

        Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit 7103506ca5639d339e3e47dfb9e4affb546c839b
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Mon May 1 14:12:31 2023 -0700

        Add tests for pyodbc (#796)

        * Add tests for pyodbc

        * Move imports into tests to get import coverage

        * Fixup: remove time import

        * Trigger tests

        ---------

        Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

    commit 363122a0efe0ad9f4784fc1f67fda046cb9bb7e8
    Author: Hannah Stepanek <hstepanek@newrelic.com>
    Date:   Mon May 1 13:34:35 2023 -0700

        Pin virtualenv, fix pip arg deprecation & disable kafka tests (#803)

        * Pin virtualenv

        * Fixup: use 20.21.1 instead

        * Replace install-options with config-settings

        See https://github.com/pypa/pip/issues/11358.

        * Temporarily disable kafka tests

    * Add dimensional stats table to stats engine

    * Add attribute processing to metric identity

    * Add testing for dimensional metrics

    * Cover tags as list not dict

    * Commit suggestions from code review

* Fix missing resource error

* Add global settings override for otlp_host test

* Fix unbound local variable

* Remove redundant and miscategorized tests

* Migrate and merge otlp utils to core.

* Fix virtualenv for newer tox versions and Py27

* Fix validator for Py27

* Fix dimensional metric normalization

* Fix lint errors

* Fix pypy 27 naming

* Add debug override for metric serialization

* Fix exit code passthrough in tox script

* Make otlp_encode more robust

* Add json vs protobuf testing fixture

* Remove sklearn py27 testing

* Validate resource in OTLP

* Revert unrelated changes from code review

* Fixup: service.provider assertion

---------

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

* Fix attribute name mismatches from mlops sdk (#845)

* Convert numerical -> numeric

* Adjust attr names to match mlops sdk

* Add feature_/label_ prefix to type & name attrs
* model_name -> modelName

* Set event type to inferenceData

* Backport main into develop-scikitlearn (#847)

* Containerized CI Pipeline (#836)

* Revert "Remove Python 2.7 and pypy2 testing (#835)"

This reverts commit abb6405d2bfd629ed83f48e8a17b4a28e3a3c352.

* Containerize CI process

* Publish new docker container for CI images

* Rename github actions job

* Copyright tag scripts

* Drop debug line

* Swap to new CI image

* Move pip install to just main python

* Remove libcurl special case from tox

* Install special case packages into main image

* Remove unused packages

* Remove all other triggers besides manual

* Add make run command

* Cleanup small bugs

* Fix CI Image Tagging (#838)

* Correct templated CI image name

* Pin pypy2.7 in image

* Fix up scripting

* Temporarily Restore Old CI Pipeline (#841)

* Restore old pipelines

* Remove python 2 from setup-python

* Rework CI Pipeline (#839)

Change pypy to pypy27 in tox.

Fix checkout logic

Pin tox requires

* Fix Tests on New CI (#843)

* Remove non-root user

* Test new CI image

* Change pypy to pypy27 in tox.

* Fix checkout logic

* Fetch git tags properly

* Pin tox requires

* Adjust default db settings for github actions

* Rename elasticsearch services

* Reset to new pipelines

* [Mega-Linter] Apply linters fixes

* Fix timezone

* Fix docker networking

* Pin dev image to new sha

* Standardize gearman DB settings

* Fix elasticsearch settings bug

* Fix gearman bug

* Add missing odbc headers

* Add more debug messages

* Swap out dev ci image

* Fix required virtualenv version

* Swap out dev ci image

* Swap out dev ci image

* Remove aioredis v1 for EOL

* Add coverage paths for docker container

* Unpin ci container

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>

* Fix pypy27 dependency

* Add skip for OTLP on py27

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Use Dimensional Metrics in SKLearn (#850)

* Convert ML custom metrics to dimensional with tags

* Rename _class to class_

* Remove typo

* Adjust ML metric tests for dimensional metrics

* Pin sklearn to <1.11.0 for testing

* [Mega-Linter] Apply linters fixes

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>

* Fixup dependency pinning

* Hook up ml event to OTLP (#822)

* Use protos and otlp protocol class for ml_events

* inferenceData -> InferenceData

* Add LogsData import

* Add utf-8 encoding for json otlp payload

* Cast timestamp to int

* Use ml_event validator in tests

* Fixup payload tests

* Change str_value -> string_value

* Move event payload gen into otlp_utils

* Fixup: put back print

* Fixup: cast as str for py27

* Fixup lint errors

* Skip py2 protobuf

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Fix OTLP Count Metric Serialization (#856)

* Fix metric filtering in OTLP encoding

* Add regression test for duplicate metrics

* Make error message more clear

* Add pylint ignore C0123

* Add explanation comment

* Linting fixups

* Merge main (#874)

* Exclude command line functionality from test coverage (#855)

* FIX: resilient environment settings (#825)

if the application uses generalimport to manage optional depedencies,
it's possible that generalimport.MissingOptionalDependency is raised.
In this case, we should not report the module as it is not actually loaded and
is not a runtime dependency of the application.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

* Replace drop_transaction logic by using transaction context manager (#832)

* Replace drop_transaction call

* [Mega-Linter] Apply linters fixes

* Empty commit to start tests

* Change logic in BG Wrappers

---------

Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Upgrade to Pypy38 for TypedDict (#861)

* Fix base branch

* Revert tox dependencies

* Replace all pypy37 with pypy38

* Remove action.yml file

* Push Empty Commit

* Fix skip_missing_interpreters behavior

* Fix skip_missing_interpreters behavior

* Pin dev CI image sha

* Remove unsupported Tornado tests

* Add latest tests to Tornado

* Remove pypy38 (for now)

---------

Co-authored-by: Tim Pansino <timpansino@gmail.com>

* Add profile_trace testing (#858)

* Include isort stdlibs for determining stdlib modules

* Use isort & sys to eliminate std & builtin modules

Previously, the logic would fail to identify third party modules installed within the
local user socpe. This fixes that issue by skipping builtin and stdlib modules by name,
instead of attempting to identify third party modules based on file paths.

* Handle importlib_metadata.version being a callable

* Add isort into third party notices

* [Mega-Linter] Apply linters fixes

* Remove Python 2.7 and pypy2 testing (#835)

* Change setup-python to @v2 for py2.7

* Remove py27 and pypy testing

* Fix syntax errors

* Fix comma related syntax errors

* Fix more issues in tox

* Remove gearman test

* Containerized CI Pipeline (#836)

* Revert "Remove Python 2.7 and pypy2 testing (#835)"

This reverts commit abb6405d2bfd629ed83f48e8a17b4a28e3a3c352.

* Containerize CI process

* Publish new docker container for CI images

* Rename github actions job

* Copyright tag scripts

* Drop debug line

* Swap to new CI image

* Move pip install to just main python

* Remove libcurl special case from tox

* Install special case packages into main image

* Remove unused packages

* Remove all other triggers besides manual

* Add make run command

* Cleanup small bugs

* Fix CI Image Tagging (#838)

* Correct templated CI image name

* Pin pypy2.7 in image

* Fix up scripting

* Temporarily Restore Old CI Pipeline (#841)

* Restore old pipelines

* Remove python 2 from setup-python

* Rework CI Pipeline (#839)

Change pypy to pypy27 in tox.

Fix checkout logic

Pin tox requires

* Fix Tests on New CI (#843)

* Remove non-root user

* Test new CI image

* Change pypy to pypy27 in tox.

* Fix checkout logic

* Fetch git tags properly

* Pin tox requires

* Adjust default db settings for github actions

* Rename elasticsearch services

* Reset to new pipelines

* [Mega-Linter] Apply linters fixes

* Fix timezone

* Fix docker networking

* Pin dev image to new sha

* Standardize gearman DB settings

* Fix elasticsearch settings bug

* Fix gearman bug

* Add missing odbc headers

* Add more debug messages

* Swap out dev ci image

* Fix required virtualenv version

* Swap out dev ci image

* Swap out dev ci image

* Remove aioredis v1 for EOL

* Add coverage paths for docker container

* Unpin ci container

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>

* Trigger tests

* Add testing for profile trace.

* [Mega-Linter] Apply linters fixes

* Ignore __call__ from coverage on profile_trace.

* [Mega-Linter] Apply linters fixes

---------

Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>
Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>

* Add Transaction API Tests (#857)

* Test for suppress_apdex_metric

* Add custom_metrics tests

* Add distributed_trace_headers testing in existing tests

* [Mega-Linter] Apply linters fixes

* Remove redundant if-statement

* Ignore deprecated transaction function from coverage

* [Mega-Linter] Apply linters fixes

* Push empty commit

* Update newrelic/api/transaction.py

---------

Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Co-authored-by: Uma Annamalai <uannamalai@newrelic.com>

* Add tests for jinja2. (#842)

* Add tests for jinja2.

* [Mega-Linter] Apply linters fixes

* Update tox.ini

Co-authored-by: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>

---------

Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>

* Add tests for newrelic/config.py (#860)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Fix starlette testing matrix for updated behavior. (#869)

Co-authored-by: Lalleh Rafeei <lrafeei@users.noreply.github.com>
Co-authored-by: Hannah Stepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>

* Correct Serverless Distributed Tracing Logic (#870)

* Fix serverless logic for distributed tracing

* Test stubs

* Collapse testing changes

* Add negative testing to regular DT test suite

* Apply linter fixes

* [Mega-Linter] Apply linters fixes

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>

* Fix Kafka CI (#863)

* Reenable kafka testing

* Add kafka dev lib

* Sync install python with devcontainer

* Fix kafka local host setting

* Drop set -u flag

* Pin CI image dev sha

* Add parallel flag to kafka

* Fix proper exit status

* Build librdkafka from source

* Updated dev image sha

* Remove coverage exclusions

* Add new options to better emulate GHA

* Reconfigure kafka networking

Co-authored-by: Hannah Stepanek <hmstepanek@users.noreply.github.com>

* Fix kafka ports on GHA

* Run kafka tests serially

* Separate kafka consumer groups

* Put CI container makefile back

* Remove confluent kafka Py27 for latest

* Roll back ubuntu version update

* Update dev ci sha

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Hannah Stepanek <hmstepanek@users.noreply.github.com>

* Change image tag to latest (#871)

* Change image tag to latest

* Use built sha

* Fixup

* Replace w/ latest

* Add full version for pypy3.8 to tox (#872)

* Add full version for pypy3.8

* Remove solrpy from tests

* Fix merge conflict

* Fix tests for scikit-learn >= 1.3.0

In 1.3.0 sklearn renamed fit to _fit in BaseDecisionTree.

* Add gfortran to container

* Use ci image sha

* Add pkg-config

* New CI build

---------

Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Co-authored-by: Ahmed Helil <aaeabdo@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
Co-authored-by: Tim Pansino <timpansino@gmail.com>
Co-authored-by: Uma Annamalai <uannamalai@newrelic.com>
Co-authored-by: hmstepanek <hmstepanek@users.noreply.github.com>
Co-authored-by: Timothy Pansino <11214426+TimPansino@users.noreply.github.com>
Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>
Co-authored-by: umaannamalai <umaannamalai@users.noreply.github.com>

* Only send 1 event per prediction & fix tests (#867)

* Only send 1 event per prediction

This changes from sending 1 event per feature/label value to 1 event per prediction.
This change is referred to as a change in "schema".
* Replace feature_name & feature_value and label_name & label_value to
  feature.<name> = <value> and label.<name> = <value>.
* Remove feature_type and label_type.

* Add new_relic_data_schema_version

* Remove pypy3.8-scipy will not compile

* Remove scipy compile deps

* Set ci build back to latest

* Merge redis changes mlops (#914)

* Exclude command line functionality from test coverage (#855)

* FIX: resilient environment settings (#825)

if the application uses generalimport to manage optional depedencies,
it's possible that generalimport.MissingOptionalDependency is raised.
In this case, we should not report the module as it is not actually loaded and
is not a runtime dependency of the application.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>

* Replace drop_transaction logic by using transaction context manager (#832)

* Replace drop_transaction call

* [Mega-Linter] Apply linters fixes

* Empty commit to start tests

* Change logic in BG Wrappers

---------

Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Upgrade to Pypy38 for TypedDict (#861)

* Fix base branch

* Revert tox dependencies

* Replace all pypy37 with pypy38

* Remove action.yml file

* Push Empty Commit

* Fix skip_missing_interpreters behavior

* Fix skip_missing_interpreters behavior

* Pin dev CI image sha

* Remove unsupported Tornado tests

* Add latest tests to Tornado

* Remove pypy38 (for now)

---------

Co-authored-by: Tim Pansino <timpansino@gmail.com>

* Add profile_trace testing (#858)

* Include isort stdlibs for determining stdlib modules

* Use isort & sys to eliminate std & builtin modules

Previously, the logic would fail to identify third party modules installed within the
local user socpe. This fixes that issue by skipping builtin and stdlib modules by name,
instead of attempting to identify third party modules based on file paths.

* Handle importlib_metadata.version being a callable

* Add isort into third party notices

* [Mega-Linter] Apply linters fixes

* Remove Python 2.7 and pypy2 testing (#835)

* Change setup-python to @v2 for py2.7

* Remove py27 and pypy testing

* Fix syntax errors

* Fix comma related syntax errors

* Fix more issues in tox

* Remove gearman test

* Containerized CI Pipeline (#836)

* Revert "Remove Python 2.7 and pypy2 testing (#835)"

This reverts commit abb6405d2bfd629ed83f48e8a17b4a28e3a3c352.

* Containerize CI process

* Publish new docker container for CI images

* Rename github actions job

* Copyright tag scripts

* Drop debug line

* Swap to new CI image

* Move pip install to just main python

* Remove libcurl special case from tox

* Install special case packages into main image

* Remove unused packages

* Remove all other triggers besides manual

* Add make run command

* Cleanup small bugs

* Fix CI Image Tagging (#838)

* Correct templated CI image name

* Pin pypy2.7 in image

* Fix up scripting

* Temporarily Restore Old CI Pipeline (#841)

* Restore old pipelines

* Remove python 2 from setup-python

* Rework CI Pipeline (#839)

Change pypy to pypy27 in tox.

Fix checkout logic

Pin tox requires

* Fix Tests on New CI (#843)

* Remove non-root user

* Test new CI image

* Change pypy to pypy27 in tox.

* Fix checkout logic

* Fetch git tags properly

* Pin tox requires

* Adjust default db settings for github actions

* Rename elasticsearch services

* Reset to new pipelines

* [Mega-Linter] Apply linters fixes

* Fix timezone

* Fix docker networking

* Pin dev image to new sha

* Standardize gearman DB settings

* Fix elasticsearch settings bug

* Fix gearman bug

* Add missing odbc headers

* Add m…
  • Loading branch information
26 people committed Sep 25, 2023
1 parent eff66b5 commit 17cd48d
Show file tree
Hide file tree
Showing 73 changed files with 9,085 additions and 149 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ include newrelic/packages/wrapt/LICENSE
include newrelic/packages/wrapt/README
include newrelic/packages/urllib3/LICENSE.txt
include newrelic/packages/isort/LICENSE
include newrelic/packages/opentelemetry_proto/LICENSE.txt
9 changes: 9 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ Distributed under the following license(s):
* [The MIT License](http://opensource.org/licenses/MIT)


## [opentelemetry-proto](https://pypi.org/project/opentelemetry-proto)

Copyright (c) The OpenTelemetry Authors

Distributed under the following license(s):

* [The Apache License, Version 2.0 License](https://opensource.org/license/apache-2-0/)


## [six](https://pypi.org/project/six)

Copyright (c) 2010-2013 Benjamin Peterson
Expand Down
9 changes: 4 additions & 5 deletions newrelic/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from newrelic.api.transaction import record_custom_metric as __record_custom_metric
from newrelic.api.transaction import record_custom_metrics as __record_custom_metrics
from newrelic.api.transaction import record_log_event as __record_log_event
from newrelic.api.transaction import record_ml_event as __record_ml_event
from newrelic.api.transaction import set_background_task as __set_background_task
from newrelic.api.transaction import set_transaction_name as __set_transaction_name
from newrelic.api.transaction import suppress_apdex_metric as __suppress_apdex_metric
Expand Down Expand Up @@ -152,6 +153,7 @@ def __asgi_application(*args, **kwargs):
from newrelic.api.message_transaction import (
wrap_message_transaction as __wrap_message_transaction,
)
from newrelic.api.ml_model import wrap_mlmodel as __wrap_mlmodel
from newrelic.api.profile_trace import ProfileTraceWrapper as __ProfileTraceWrapper
from newrelic.api.profile_trace import profile_trace as __profile_trace
from newrelic.api.profile_trace import wrap_profile_trace as __wrap_profile_trace
Expand Down Expand Up @@ -206,11 +208,6 @@ def __asgi_application(*args, **kwargs):
# EXPERIMENTAL - Generator traces are currently experimental and may not
# exist in this form in future versions of the agent.


# EXPERIMENTAL - Profile traces are currently experimental and may not
# exist in this form in future versions of the agent.


initialize = __initialize
extra_settings = __wrap_api_call(__extra_settings, "extra_settings")
global_settings = __wrap_api_call(__global_settings, "global_settings")
Expand Down Expand Up @@ -248,6 +245,7 @@ def __asgi_application(*args, **kwargs):
record_custom_metrics = __wrap_api_call(__record_custom_metrics, "record_custom_metrics")
record_custom_event = __wrap_api_call(__record_custom_event, "record_custom_event")
record_log_event = __wrap_api_call(__record_log_event, "record_log_event")
record_ml_event = __wrap_api_call(__record_ml_event, "record_ml_event")
accept_distributed_trace_payload = __wrap_api_call(
__accept_distributed_trace_payload, "accept_distributed_trace_payload"
)
Expand Down Expand Up @@ -341,3 +339,4 @@ def __asgi_application(*args, **kwargs):
wrap_out_function = __wrap_api_call(__wrap_out_function, "wrap_out_function")
insert_html_snippet = __wrap_api_call(__insert_html_snippet, "insert_html_snippet")
verify_body_exists = __wrap_api_call(__verify_body_exists, "verify_body_exists")
wrap_mlmodel = __wrap_api_call(__wrap_mlmodel, "wrap_mlmodel")
12 changes: 12 additions & 0 deletions newrelic/api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,22 @@ def record_custom_metrics(self, metrics):
if self.active and metrics:
self._agent.record_custom_metrics(self._name, metrics)

def record_dimensional_metric(self, name, value, tags=None):
if self.active:
self._agent.record_dimensional_metric(self._name, name, value, tags)

def record_dimensional_metrics(self, metrics):
if self.active and metrics:
self._agent.record_dimensional_metrics(self._name, metrics)

def record_custom_event(self, event_type, params):
if self.active:
self._agent.record_custom_event(self._name, event_type, params)

def record_ml_event(self, event_type, params):
if self.active:
self._agent.record_ml_event(self._name, event_type, params)

def record_transaction(self, data):
if self.active:
self._agent.record_transaction(self._name, data)
Expand Down
35 changes: 35 additions & 0 deletions newrelic/api/ml_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

from newrelic.common.object_names import callable_name
from newrelic.hooks.mlmodel_sklearn import _nr_instrument_model


def wrap_mlmodel(model, name=None, version=None, feature_names=None, label_names=None, metadata=None):
model_callable_name = callable_name(model)
_class = model.__class__.__name__
module = sys.modules[model_callable_name.split(":")[0]]
_nr_instrument_model(module, _class)
if name:
model._nr_wrapped_name = name
if version:
model._nr_wrapped_version = version
if feature_names:
model._nr_wrapped_feature_names = feature_names
if label_names:
model._nr_wrapped_label_names = label_names
if metadata:
model._nr_wrapped_metadata = metadata
102 changes: 100 additions & 2 deletions newrelic/api/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@
DST_NONE,
DST_TRANSACTION_TRACER,
)
from newrelic.core.config import CUSTOM_EVENT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE
from newrelic.core.config import (
CUSTOM_EVENT_RESERVOIR_SIZE,
LOG_EVENT_RESERVOIR_SIZE,
ML_EVENT_RESERVOIR_SIZE,
)
from newrelic.core.custom_event import create_custom_event
from newrelic.core.log_event_node import LogEventNode
from newrelic.core.stack_trace import exception_stack
from newrelic.core.stats_engine import CustomMetrics, SampledDataSet
from newrelic.core.stats_engine import CustomMetrics, DimensionalMetrics, SampledDataSet
from newrelic.core.thread_utilization import utilization_tracker
from newrelic.core.trace_cache import (
TraceCacheActiveTraceError,
Expand Down Expand Up @@ -305,6 +309,7 @@ def __init__(self, application, enabled=None, source=None):
self.synthetics_header = None

self._custom_metrics = CustomMetrics()
self._dimensional_metrics = DimensionalMetrics()

global_settings = application.global_settings

Expand All @@ -328,12 +333,14 @@ def __init__(self, application, enabled=None, source=None):
self._custom_events = SampledDataSet(
capacity=self._settings.event_harvest_config.harvest_limits.custom_event_data
)
self._ml_events = SampledDataSet(capacity=self._settings.event_harvest_config.harvest_limits.ml_event_data)
self._log_events = SampledDataSet(
capacity=self._settings.event_harvest_config.harvest_limits.log_event_data
)
else:
self._custom_events = SampledDataSet(capacity=CUSTOM_EVENT_RESERVOIR_SIZE)
self._log_events = SampledDataSet(capacity=LOG_EVENT_RESERVOIR_SIZE)
self._ml_events = SampledDataSet(capacity=ML_EVENT_RESERVOIR_SIZE)

def __del__(self):
self._dead = True
Expand Down Expand Up @@ -580,10 +587,12 @@ def __exit__(self, exc, value, tb):
errors=tuple(self._errors),
slow_sql=tuple(self._slow_sql),
custom_events=self._custom_events,
ml_events=self._ml_events,
log_events=self._log_events,
apdex_t=self.apdex,
suppress_apdex=self.suppress_apdex,
custom_metrics=self._custom_metrics,
dimensional_metrics=self._dimensional_metrics,
guid=self.guid,
cpu_time=self._cpu_user_time_value,
suppress_transaction_trace=self.suppress_transaction_trace,
Expand Down Expand Up @@ -1607,6 +1616,16 @@ def record_custom_metrics(self, metrics):
for name, value in metrics:
self._custom_metrics.record_custom_metric(name, value)

def record_dimensional_metric(self, name, value, tags=None):
self._dimensional_metrics.record_dimensional_metric(name, value, tags)

def record_dimensional_metrics(self, metrics):
for metric in metrics:
name, value = metric[:2]
tags = metric[2] if len(metric) >= 3 else None

self._dimensional_metrics.record_dimensional_metric(name, value, tags)

def record_custom_event(self, event_type, params):
settings = self._settings

Expand All @@ -1620,6 +1639,19 @@ def record_custom_event(self, event_type, params):
if event:
self._custom_events.add(event, priority=self.priority)

def record_ml_event(self, event_type, params):
settings = self._settings

if not settings:
return

if not settings.ml_insights_events.enabled:
return

event = create_custom_event(event_type, params)
if event:
self._ml_events.add(event, priority=self.priority)

def _intern_string(self, value):
return self._string_cache.setdefault(value, value)

Expand Down Expand Up @@ -1913,6 +1945,44 @@ def record_custom_metrics(metrics, application=None):
application.record_custom_metrics(metrics)


def record_dimensional_metric(name, value, tags=None, application=None):
if application is None:
transaction = current_transaction()
if transaction:
transaction.record_dimensional_metric(name, value, tags)
else:
_logger.debug(
"record_dimensional_metric has been called but no "
"transaction was running. As a result, the following metric "
"has not been recorded. Name: %r Value: %r Tags: %r. To correct this "
"problem, supply an application object as a parameter to this "
"record_dimensional_metrics call.",
name,
value,
tags,
)
elif application.enabled:
application.record_dimensional_metric(name, value, tags)


def record_dimensional_metrics(metrics, application=None):
if application is None:
transaction = current_transaction()
if transaction:
transaction.record_dimensional_metrics(metrics)
else:
_logger.debug(
"record_dimensional_metrics has been called but no "
"transaction was running. As a result, the following metrics "
"have not been recorded: %r. To correct this problem, "
"supply an application object as a parameter to this "
"record_dimensional_metric call.",
list(metrics),
)
elif application.enabled:
application.record_dimensional_metrics(metrics)


def record_custom_event(event_type, params, application=None):
"""Record a custom event.
Expand Down Expand Up @@ -1941,6 +2011,34 @@ def record_custom_event(event_type, params, application=None):
application.record_custom_event(event_type, params)


def record_ml_event(event_type, params, application=None):
"""Record a machine learning custom event.
Args:
event_type (str): The type (name) of the ml event.
params (dict): Attributes to add to the event.
application (newrelic.api.Application): Application instance.
"""

if application is None:
transaction = current_transaction()
if transaction:
transaction.record_ml_event(event_type, params)
else:
_logger.debug(
"record_ml_event has been called but no "
"transaction was running. As a result, the following event "
"has not been recorded. event_type: %r params: %r. To correct "
"this problem, supply an application object as a parameter to "
"this record_ml_event call.",
event_type,
params,
)
elif application.enabled:
application.record_ml_event(event_type, params)


def record_log_event(message, level=None, timestamp=None, application=None, priority=None):
"""Record a log event.
Expand Down
Loading

0 comments on commit 17cd48d

Please sign in to comment.