Skip to main content

New Relic Telemetry SDK

Project description

header

New Relic Telemetry SDK

ci coverage 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, logs, 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 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_INSERT_KEY

import os

from newrelic_telemetry_sdk import Log, LogClient

log = Log("Hello World!")

log_client = LogClient(os.environ["NEW_RELIC_INSERT_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_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.

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.4.2.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

newrelic_telemetry_sdk-0.4.2-py2.py3-none-any.whl (23.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: newrelic-telemetry-sdk-0.4.2.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for newrelic-telemetry-sdk-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6b20f05098bce07711d48c337b724e36b823e0c97ef3a39d55d0cdee0959f76a
MD5 ef0679baef390ea96c306d334a161015
BLAKE2b-256 40eb93b560e38911e02e06833a5512012d0fbdd6fa1b1e2b301783d25d3d16ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: newrelic_telemetry_sdk-0.4.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for newrelic_telemetry_sdk-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3d4918630db76c633ce06ef0a90fc30de779f0a61beef72a98b7cd1901394fe3
MD5 c638c57ed651660c6c50a4d5f6e2f156
BLAKE2b-256 24ea0c67491d856d4a8de51cabceafdd8dc550085c50eca2f0dfb1ed6cb6ede1

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