Package: newrelic-telemetry-sdk
New Relic Telemetry SDKnewrelic-telemetry-sdk-pythonprovides a Python library for sending data intoNew Relicusing the Pythonurllib3library.See dimensionalmetrics,events,logs, andspans/tracesin New Relic, without having to use an agent!Installing newrelic_telemetry_sdkTo start, thenewrelic-telemetry-sdkpackage must be installed. To install
through pip:$pipinstallnewrelic-telemetry-sdkIf that fails, download the library from its GitHub page and install it using:$pythonsetup.pyinstallReporting your first metricThere are 3 different types of metrics:GaugeMetricCountMetricSummaryMetricMetric descriptionsMetric typeInterval
requiredDescriptionExampleGaugeNoA single value at a single point in time.Room Temperature.CountYesTrack the total number of occurrences of an event.Number of errors that have occurred.SummaryYesTrack count, sum, min, and max values over time.The summarized duration of 100 HTTP requests.ExampleThe example code assumes you’ve set the following environment variables:NEW_RELIC_LICENSE_KEYimportosimporttimefromnewrelic_telemetry_sdkimportGaugeMetric,CountMetric,SummaryMetric,MetricClientmetric_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 secondserrors=CountMetric(name="errors",value=5,interval_ms=2000)# Record a summary of 10 response times over the last 2 secondssummary=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 eventEvents 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_KEYimportosimporttimefromnewrelic_telemetry_sdkimportEvent,EventClient# Record that a rate limit has been applied to an endpoint for an accountevent=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 messageLog 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_KEYimportosfromnewrelic_telemetry_sdkimportLog,LogClientlog=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 spanSpans provide an easy way to time components of your code.
The example code assumes you’ve set the following environment variables:NEW_RELIC_LICENSE_KEYimportosimporttimefromnewrelic_telemetry_sdkimportSpan,SpanClientwithSpan(name="sleep")asspan: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 dataTips on how to find and query your data in New Relic:Find metric dataFind event dataFind log dataFind trace/span dataFor general querying information, see:Query New Relic dataIntro to NRQLLimitationsThe New Relic Telemetry APIs are rate limited. Please reference the documentation forNew Relic Metrics APIandNew Relic Trace API requirements and limitson the specifics of the rate limits.