Skip to main content

New Relic Telemetry SDK

Project description

ci coverage docs black

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

The current SDK supports sending dimensional metrics to the New Relic Metric API and spans to the New Relic Trace API.

Why is this cool?

Dimensional Metrics and traces in New Relic! No agent required.

The telemetry SDK tries to be helpful, so your job of sending telemetry data to New Relic can be done in the right way, easily. We’ve covered all of the basics for you so you can focus on writing feature code directly related to your business need or interest.

Why would you want to use the telemetry SDK?

We imagine you (or your customers) are interested in seeing the telemetry data, generated by your tool, framework, or code, in New Relic. You can write an exporter to do so! Read below to get started

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 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!')

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!")

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newrelic-telemetry-sdk-0.2.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

newrelic_telemetry_sdk-0.2.0-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file newrelic-telemetry-sdk-0.2.0.tar.gz.

File metadata

  • Download URL: newrelic-telemetry-sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for newrelic-telemetry-sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fc765d93adf70abdf96bd5cdaf920c5b7155bfa4404c2f9417b4aa53cfe36bdb
MD5 4e881cef101ea96002b75f64845cadaf
BLAKE2b-256 dd0a20a98571c6650b640c5a2e18371b50f5149f8acc719738f0f9743249951d

See more details on using hashes here.

File details

Details for the file newrelic_telemetry_sdk-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: newrelic_telemetry_sdk-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for newrelic_telemetry_sdk-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9cf74652d01176888ee5a853e55ad06ac14ab603e7b9b644f33e9057804889e1
MD5 f1eb8ca8db53a2ea55e755bead31b2e3
BLAKE2b-256 b6c9416f01fd41766df097057d21280e65c2c11a53108971db128d6f5fd50623

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page