newrelic-telemetry-sdk


Namenewrelic-telemetry-sdk JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://newrelic.github.io/newrelic-telemetry-sdk-python
SummaryNew Relic Telemetry SDK
upload_time2024-03-26 16:37:03
maintainerNone
docs_urlNone
authorNew Relic
requires_python!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |header|

.. |header| image:: https://github.com/newrelic/open-source-office/raw/master/examples/categories/images/Community_Project.png
    :target: https://github.com/newrelic/open-source-office/blob/master/examples/categories/index.md#category-community-project

New Relic Telemetry SDK
=======================

|ci| |coverage| |docs| |black|

.. |ci| image:: https://github.com/newrelic/newrelic-telemetry-sdk-python/workflows/Tests/badge.svg
    :target: https://github.com/newrelic/newrelic-telemetry-sdk-python/actions?query=workflow%3ATests

.. |coverage| image:: https://img.shields.io/codecov/c/github/newrelic/newrelic-telemetry-sdk-python/main
    :target: https://codecov.io/gh/newrelic/newrelic-telemetry-sdk-python

.. |docs| image:: https://img.shields.io/badge/docs-available-brightgreen.svg
    :target: https://newrelic.github.io/newrelic-telemetry-sdk-python/

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

`newrelic-telemetry-sdk-python <https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/new-relic-sdks/telemetry-sdks-send-custom-telemetry-data-new-relic>`_ provides a Python library for sending data into `New Relic <https://newrelic.com>`_ using the Python `urllib3 <https://urllib3.readthedocs.io>`_ library.

See dimensional `metrics`_, `events`_, `logs`_, and `spans/traces`_ in New Relic, without having to use an agent!

.. _metrics: https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/metric-api/introduction-metric-api#find-data
.. _events: https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/introduction-event-api#find-data
.. _logs: https://docs.newrelic.com/docs/logs/log-management/ui-data/explore-your-data-log-analytics
.. _spans/traces: https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/introduction-trace-api#view-data


Installing newrelic_telemetry_sdk
---------------------------------

To start, the ``newrelic-telemetry-sdk`` package must be installed. To install
through pip:

.. code-block:: bash

    $ pip install newrelic-telemetry-sdk

If that fails, download the library from its GitHub page and install it using:

.. code-block:: bash

    $ python setup.py install


Reporting your first metric
---------------------------

There are 3 different types of metrics:

* GaugeMetric
* CountMetric
* SummaryMetric

Metric descriptions
^^^^^^^^^^^^^^^^^^^

+-------------+----------+----------------------------------------------------+-----------------------------------------------+
| Metric type | Interval | Description                                        | Example                                       |
|             | required |                                                    |                                               |
+=============+==========+====================================================+===============================================+
| Gauge       | No       | A single value at a single point in time.          | Room Temperature.                             |
+-------------+----------+----------------------------------------------------+-----------------------------------------------+
| Count       | Yes      | Track the total number of occurrences of an event. | Number of errors that have occurred.          |
+-------------+----------+----------------------------------------------------+-----------------------------------------------+
| Summary     | Yes      | Track count, sum, min, and max values over time.   | The summarized duration of 100 HTTP requests. |
+-------------+----------+----------------------------------------------------+-----------------------------------------------+

Example
^^^^^^^
The example code assumes you've set the following environment variables:

* ``NEW_RELIC_LICENSE_KEY``

.. code-block:: python

    import os
    import time
    from newrelic_telemetry_sdk import GaugeMetric, CountMetric, SummaryMetric, MetricClient

    metric_client = MetricClient(os.environ["NEW_RELIC_LICENSE_KEY"])

    temperature = GaugeMetric("temperature", 78.6, {"units": "Farenheit"})

    # Record that there have been 5 errors in the last 2 seconds
    errors = CountMetric(name="errors", value=5, interval_ms=2000)

    # Record a summary of 10 response times over the last 2 seconds
    summary = SummaryMetric(
        "responses", count=10, min=0.2, max=0.5, sum=4.7, interval_ms=2000
    )

    batch = [temperature, errors, summary]
    response = metric_client.send_batch(batch)
    response.raise_for_status()
    print("Sent metrics successfully!")

Reporting your first event
--------------------------

Events represent a record of something that has occurred on a system being monitored.
The example code assumes you've set the following environment variables:

* ``NEW_RELIC_LICENSE_KEY``

.. code-block:: python

    import os
    import time
    from newrelic_telemetry_sdk import Event, EventClient

    # Record that a rate limit has been applied to an endpoint for an account
    event = Event(
        "RateLimit", {"path": "/v1/endpoint", "accountId": 1000, "rejectRatio": 0.1}
    )

    event_client = EventClient(os.environ["NEW_RELIC_LICENSE_KEY"])
    response = event_client.send(event)
    response.raise_for_status()
    print("Event sent successfully!")

Reporting your first log message
--------------------------------

Log messages are generated by applications, usually via the Python logging
module. These messages are used to audit and diagnose issues with an operating
application. The example code assumes you've set the following environment variables:

* ``NEW_RELIC_LICENSE_KEY``

.. code-block:: python

    import os

    from newrelic_telemetry_sdk import Log, LogClient

    log = Log("Hello World!")

    log_client = LogClient(os.environ["NEW_RELIC_LICENSE_KEY"])
    response = log_client.send(log)
    response.raise_for_status()
    print("Log sent successfully!")


Reporting your first span
-------------------------

Spans provide an easy way to time components of your code.
The example code assumes you've set the following environment variables:

* ``NEW_RELIC_LICENSE_KEY``

.. code-block:: python

    import os
    import time
    from newrelic_telemetry_sdk import Span, SpanClient

    with Span(name="sleep") as span:
        time.sleep(0.5)

    span_client = SpanClient(os.environ["NEW_RELIC_LICENSE_KEY"])
    response = span_client.send(span)
    response.raise_for_status()
    print("Span sleep sent successfully!")

Find and use data
-----------------

Tips on how to find and query your data in New Relic:

* `Find metric data <https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/metric-api/introduction-metric-api#find-data>`_
* `Find event data <https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/introduction-event-api#find-data>`_
* `Find log data <https://docs.newrelic.com/docs/logs/log-management/ui-data/explore-your-data-log-analytics>`_
* `Find trace/span data <https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/introduction-trace-api#view-data>`_

For general querying information, see:

* `Query New Relic data <https://docs.newrelic.com/docs/using-new-relic/data/understand-data/query-new-relic-data>`_
* `Intro to NRQL <https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql>`_

Limitations
-----------
The New Relic Telemetry APIs are rate limited. Please reference the documentation for `New Relic Metrics API <https://docs.newrelic.com/docs/introduction-new-relic-metric-api>`_ and `New Relic Trace API requirements and limits <https://docs.newrelic.com/docs/apm/distributed-tracing/trace-api/trace-api-general-requirements-limits>`_ on the specifics of the rate limits.


            

Raw data

            {
    "_id": null,
    "home_page": "https://newrelic.github.io/newrelic-telemetry-sdk-python",
    "name": "newrelic-telemetry-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "New Relic",
    "author_email": "open-source@newrelic.com",
    "download_url": "https://files.pythonhosted.org/packages/20/7b/a1dee942c74f76f5eefdabbdb75f8d1d77c0de5c2584f5f72d3216d4e98f/newrelic-telemetry-sdk-0.5.1.tar.gz",
    "platform": "any",
    "description": "|header|\n\n.. |header| image:: https://github.com/newrelic/open-source-office/raw/master/examples/categories/images/Community_Project.png\n    :target: https://github.com/newrelic/open-source-office/blob/master/examples/categories/index.md#category-community-project\n\nNew Relic Telemetry SDK\n=======================\n\n|ci| |coverage| |docs| |black|\n\n.. |ci| image:: https://github.com/newrelic/newrelic-telemetry-sdk-python/workflows/Tests/badge.svg\n    :target: https://github.com/newrelic/newrelic-telemetry-sdk-python/actions?query=workflow%3ATests\n\n.. |coverage| image:: https://img.shields.io/codecov/c/github/newrelic/newrelic-telemetry-sdk-python/main\n    :target: https://codecov.io/gh/newrelic/newrelic-telemetry-sdk-python\n\n.. |docs| image:: https://img.shields.io/badge/docs-available-brightgreen.svg\n    :target: https://newrelic.github.io/newrelic-telemetry-sdk-python/\n\n.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n`newrelic-telemetry-sdk-python <https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/new-relic-sdks/telemetry-sdks-send-custom-telemetry-data-new-relic>`_ provides a Python library for sending data into `New Relic <https://newrelic.com>`_ using the Python `urllib3 <https://urllib3.readthedocs.io>`_ library.\n\nSee dimensional `metrics`_, `events`_, `logs`_, and `spans/traces`_ in New Relic, without having to use an agent!\n\n.. _metrics: https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/metric-api/introduction-metric-api#find-data\n.. _events: https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/introduction-event-api#find-data\n.. _logs: https://docs.newrelic.com/docs/logs/log-management/ui-data/explore-your-data-log-analytics\n.. _spans/traces: https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/introduction-trace-api#view-data\n\n\nInstalling newrelic_telemetry_sdk\n---------------------------------\n\nTo start, the ``newrelic-telemetry-sdk`` package must be installed. To install\nthrough pip:\n\n.. code-block:: bash\n\n    $ pip install newrelic-telemetry-sdk\n\nIf that fails, download the library from its GitHub page and install it using:\n\n.. code-block:: bash\n\n    $ python setup.py install\n\n\nReporting your first metric\n---------------------------\n\nThere are 3 different types of metrics:\n\n* GaugeMetric\n* CountMetric\n* SummaryMetric\n\nMetric descriptions\n^^^^^^^^^^^^^^^^^^^\n\n+-------------+----------+----------------------------------------------------+-----------------------------------------------+\n| Metric type | Interval | Description                                        | Example                                       |\n|             | required |                                                    |                                               |\n+=============+==========+====================================================+===============================================+\n| Gauge       | No       | A single value at a single point in time.          | Room Temperature.                             |\n+-------------+----------+----------------------------------------------------+-----------------------------------------------+\n| Count       | Yes      | Track the total number of occurrences of an event. | Number of errors that have occurred.          |\n+-------------+----------+----------------------------------------------------+-----------------------------------------------+\n| Summary     | Yes      | Track count, sum, min, and max values over time.   | The summarized duration of 100 HTTP requests. |\n+-------------+----------+----------------------------------------------------+-----------------------------------------------+\n\nExample\n^^^^^^^\nThe example code assumes you've set the following environment variables:\n\n* ``NEW_RELIC_LICENSE_KEY``\n\n.. code-block:: python\n\n    import os\n    import time\n    from newrelic_telemetry_sdk import GaugeMetric, CountMetric, SummaryMetric, MetricClient\n\n    metric_client = MetricClient(os.environ[\"NEW_RELIC_LICENSE_KEY\"])\n\n    temperature = GaugeMetric(\"temperature\", 78.6, {\"units\": \"Farenheit\"})\n\n    # Record that there have been 5 errors in the last 2 seconds\n    errors = CountMetric(name=\"errors\", value=5, interval_ms=2000)\n\n    # Record a summary of 10 response times over the last 2 seconds\n    summary = SummaryMetric(\n        \"responses\", count=10, min=0.2, max=0.5, sum=4.7, interval_ms=2000\n    )\n\n    batch = [temperature, errors, summary]\n    response = metric_client.send_batch(batch)\n    response.raise_for_status()\n    print(\"Sent metrics successfully!\")\n\nReporting your first event\n--------------------------\n\nEvents represent a record of something that has occurred on a system being monitored.\nThe example code assumes you've set the following environment variables:\n\n* ``NEW_RELIC_LICENSE_KEY``\n\n.. code-block:: python\n\n    import os\n    import time\n    from newrelic_telemetry_sdk import Event, EventClient\n\n    # Record that a rate limit has been applied to an endpoint for an account\n    event = Event(\n        \"RateLimit\", {\"path\": \"/v1/endpoint\", \"accountId\": 1000, \"rejectRatio\": 0.1}\n    )\n\n    event_client = EventClient(os.environ[\"NEW_RELIC_LICENSE_KEY\"])\n    response = event_client.send(event)\n    response.raise_for_status()\n    print(\"Event sent successfully!\")\n\nReporting your first log message\n--------------------------------\n\nLog messages are generated by applications, usually via the Python logging\nmodule. These messages are used to audit and diagnose issues with an operating\napplication. The example code assumes you've set the following environment variables:\n\n* ``NEW_RELIC_LICENSE_KEY``\n\n.. code-block:: python\n\n    import os\n\n    from newrelic_telemetry_sdk import Log, LogClient\n\n    log = Log(\"Hello World!\")\n\n    log_client = LogClient(os.environ[\"NEW_RELIC_LICENSE_KEY\"])\n    response = log_client.send(log)\n    response.raise_for_status()\n    print(\"Log sent successfully!\")\n\n\nReporting your first span\n-------------------------\n\nSpans provide an easy way to time components of your code.\nThe example code assumes you've set the following environment variables:\n\n* ``NEW_RELIC_LICENSE_KEY``\n\n.. code-block:: python\n\n    import os\n    import time\n    from newrelic_telemetry_sdk import Span, SpanClient\n\n    with Span(name=\"sleep\") as span:\n        time.sleep(0.5)\n\n    span_client = SpanClient(os.environ[\"NEW_RELIC_LICENSE_KEY\"])\n    response = span_client.send(span)\n    response.raise_for_status()\n    print(\"Span sleep sent successfully!\")\n\nFind and use data\n-----------------\n\nTips on how to find and query your data in New Relic:\n\n* `Find metric data <https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/metric-api/introduction-metric-api#find-data>`_\n* `Find event data <https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/introduction-event-api#find-data>`_\n* `Find log data <https://docs.newrelic.com/docs/logs/log-management/ui-data/explore-your-data-log-analytics>`_\n* `Find trace/span data <https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/introduction-trace-api#view-data>`_\n\nFor general querying information, see:\n\n* `Query New Relic data <https://docs.newrelic.com/docs/using-new-relic/data/understand-data/query-new-relic-data>`_\n* `Intro to NRQL <https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql>`_\n\nLimitations\n-----------\nThe New Relic Telemetry APIs are rate limited. Please reference the documentation for `New Relic Metrics API <https://docs.newrelic.com/docs/introduction-new-relic-metric-api>`_ and `New Relic Trace API requirements and limits <https://docs.newrelic.com/docs/apm/distributed-tracing/trace-api/trace-api-general-requirements-limits>`_ on the specifics of the rate limits.\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "New Relic Telemetry SDK",
    "version": "0.5.1",
    "project_urls": {
        "Homepage": "https://newrelic.github.io/newrelic-telemetry-sdk-python",
        "Source": "https://github.com/newrelic/newrelic-telemetry-sdk-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86736a0deda4a1b4a7f7ca09a5e284ffad029d1d63f78827ff77b037efad6a97",
                "md5": "c373bf2bf96f00975877a03019da862e",
                "sha256": "5cf27cfcb793b0fd1b6b4eb6834f6eab556fcb9fdf7459785d1b0e2fa3eb9c0d"
            },
            "downloads": -1,
            "filename": "newrelic_telemetry_sdk-0.5.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c373bf2bf96f00975877a03019da862e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7",
            "size": 23916,
            "upload_time": "2024-03-26T16:37:01",
            "upload_time_iso_8601": "2024-03-26T16:37:01.794115Z",
            "url": "https://files.pythonhosted.org/packages/86/73/6a0deda4a1b4a7f7ca09a5e284ffad029d1d63f78827ff77b037efad6a97/newrelic_telemetry_sdk-0.5.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "207ba1dee942c74f76f5eefdabbdb75f8d1d77c0de5c2584f5f72d3216d4e98f",
                "md5": "f934f7193af40d9e680548245ce88a6d",
                "sha256": "f21b1f27ec4420dc3de6570e520af65ee67ed995c58d6a2fb404f9410283f300"
            },
            "downloads": -1,
            "filename": "newrelic-telemetry-sdk-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f934f7193af40d9e680548245ce88a6d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7",
            "size": 38438,
            "upload_time": "2024-03-26T16:37:03",
            "upload_time_iso_8601": "2024-03-26T16:37:03.624222Z",
            "url": "https://files.pythonhosted.org/packages/20/7b/a1dee942c74f76f5eefdabbdb75f8d1d77c0de5c2584f5f72d3216d4e98f/newrelic-telemetry-sdk-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 16:37:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "newrelic",
    "github_project": "newrelic-telemetry-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "newrelic-telemetry-sdk"
}
        
Elapsed time: 0.20833s