Skip to main content

ci docs black

newrelic-telemetry-sdk-python provides a Python library for sending data into New Relic using the Python urllib3 library.

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

Installing newrelic_telemetry_sdk

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

$ pip install newrelic-telemetry-sdk

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

$ python setup.py install

Reporting your first metric

There are 3 different types of metrics:

  • GaugeMetric

  • CountMetric

  • SummaryMetric

Metric descriptions

Metric type

Interval required

Description

Example

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_INSERT_KEY

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

metric_client = MetricClient(os.environ['NEW_RELIC_INSERT_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
)

response = metric_client.send_batch((temperature, errors, summary))
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_INSERT_KEY

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_INSERT_KEY"])
response = event_client.send(event)
response.raise_for_status()
print("Event 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_INSERT_KEY

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_INSERT_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:

For general querying information, see:

Limitations

The New Relic Telemetry APIs are rate limited. Please reference the documentation for New Relic Metrics API and New Relic Trace API requirements and limits on the specifics of the rate limits.

Release files for newrelic-telemetry-sdk 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for newrelic-telemetry-sdk 0.2.5
File Size Uploaded
newrelic-telemetry-sdk-0.2.5.tar.gz 32.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for newrelic-telemetry-sdk 0.2.5
File Interpreter ABI Platform
newrelic_telemetry_sdk-0.2.5-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size:53.9 kB

Release files / newrelic-telemetry-sdk-0.2.5.tar.gz

Download URL newrelic-telemetry-sdk-0.2.5.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
07b0de7bb30660b9eaf77d208e541cbcd1681290606f103c622864097bf6e42f
BLAKE2b-256 checksum
How to use checksums
365831dad0d1cd3a977154abf65a3e421fedd5d939601fb36d0afb6ab5cb9c38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / newrelic_telemetry_sdk-0.2.5-py2.py3-none-any.whl

Download URL newrelic_telemetry_sdk-0.2.5-py2.py3-none-any.whl
Size 21.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d2f4f8a90cef564e76eff6e1896d943a67d435e21dfc9034933ebc4f7e8431ca
BLAKE2b-256 checksum
How to use checksums
efa95b4895a49540b829ccb286b9991f65f8d047463f14a0e6196418accd6fb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

1 release file

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

This release

0.2.5 This release

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page