Skip to main content

header

New Relic OpenTelemetry Python Exporter

An OpenTelemetry exporter for sending spans to New Relic using the New Relic Python Telemetry SDK. Currently, spans as of OpenTelemetry v0.15b0 are supported. For details on how OpenTelemetry data is mapped to New Relic data, see documentation in our exporter specifications documentation.

Installation

To start, the opentelemetry-ext-newrelic package must be installed. To install through pip:

$ pip install opentelemetry-ext-newrelic

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

$ python setup.py install

Getting Started

In order to use the exporter, you will need to set the NEW_RELIC_INSERT_KEY environment variable with your Insights Insert API Key.

Using the span exporter

The following code sample assumes you have set the NEW_RELIC_INSERT_KEY environment variable and installed the following packages:

  • opentelemetry-ext-newrelic

import os
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry_ext_newrelic import NewRelicSpanExporter
from opentelemetry.sdk.trace import TracerProvider

trace.set_tracer_provider(
    TracerProvider(resource=Resource.create({"service.name": "otel-python"}))
)

trace.get_tracer_provider().add_span_processor(
    BatchExportSpanProcessor(
        NewRelicSpanExporter(
            os.environ["NEW_RELIC_INSERT_KEY"],
        ),
        schedule_delay_millis=500,
    )
)

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("foo"):
    with tracer.start_as_current_span("bar"):
        print("Hello World from OpenTelemetry Python!")

Using the span exporter with auto-instrumentation

The following code sample assumes you have set the NEW_RELIC_INSERT_KEY environment variable and installed the following packages:

  • opentelemetry-ext-newrelic

  • opentelemetry-instrumentation-flask

  • flask

import os
from opentelemetry import trace
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry_ext_newrelic import NewRelicSpanExporter
from flask import Flask
app = Flask(__name__)
FlaskInstrumentor().instrument_app(app)
trace.set_tracer_provider(
    TracerProvider(resource=Resource.create({"service.name": "otel-python-flask"}))
)

trace.get_tracer_provider().add_span_processor(
    BatchExportSpanProcessor(
        NewRelicSpanExporter(os.environ["NEW_RELIC_INSERT_KEY"]),
        schedule_delay_millis=500,
    )
)

@app.route("/")
def hello_world():
    return "Hello World!"

@app.route("/error")
def raise_500():
    raise RuntimeError("Something happened!")

if __name__ == "__main__":
    app.run(port=8080)

Find and use your data

For tips on how to find and query your data in New Relic, see Find trace/span data.

For general querying information, see: - Query New Relic data - Intro to NRQL

Support

New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there’s a related Community topic in the New Relic Explorers Hub. You can find this project’s topic/threads here:

Support Channels

Contributing

We encourage your contributions to improve opentelemetry-exporter-python! Keep in mind when you submit your pull request, you’ll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic’s products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.

License

opentelemetry-exporter-python is licensed under the Apache 2.0 License.

Limitations

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

Metadata

Release files for opentelemetry-ext-newrelic 0.1.1

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

Source distribution (sdist)

Source distribution for opentelemetry-ext-newrelic 0.1.1
File Size Uploaded
opentelemetry-ext-newrelic-0.1.1.tar.gz 20.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opentelemetry-ext-newrelic 0.1.1
File Interpreter ABI Platform
opentelemetry_ext_newrelic-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / opentelemetry-ext-newrelic-0.1.1.tar.gz

Download URL opentelemetry-ext-newrelic-0.1.1.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2610dfd5c69d63c87a124009f7fd188293737be241dff66972e88f3816b2d19b
BLAKE2b-256 checksum
How to use checksums
fc35bb15eabf1aa1794f6a39fc024e6e0b672df8a3844c8de0a863926c51422f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

Release files / opentelemetry_ext_newrelic-0.1.1-py3-none-any.whl

Download URL opentelemetry_ext_newrelic-0.1.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
386718c0ed28d0f45ff65bcd28f869048f92f454dcc612492c8f31bcb7d5529c
BLAKE2b-256 checksum
How to use checksums
cae3edac1c4259e0cf61294cb99c92d5e21fad718154f0f53b62cecfc5115265
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

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