Skip to main content

New Relic OpenCensus Exporter

Project description


New Relic OpenCensus exporter

ci coverage docs black

The opencensus-ext-newrelic package provides Python exporters to plug into OpenCensus! Both spans and metrics may be exported using these exporters!


OpenCensus-Python version 0.7.x is required to use the exporters.

Using the trace exporter

The example code assumes you’ve set the following environment variables:

import os
import time
from opencensus.trace.tracer import Tracer
from opencensus.trace import samplers
from opencensus_ext_newrelic import NewRelicTraceExporter

newrelic = NewRelicTraceExporter(
    insert_key=os.environ["NEW_RELIC_INSERT_KEY"], service_name="Example Service"

tracer = Tracer(exporter=newrelic, sampler=samplers.AlwaysOnSampler())

with tracer.span(name="main") as span:

# Send all data and stop the exporter

Using the stats exporter

Metrics are an excellent way to expose aggregated information about your application. The stats exporter allows metrics to be exported from opencensus to New Relic.

The example code assumes you’ve set the following environment variables:

import os
import time
from opencensus.stats import aggregation as aggregation_module
from opencensus.stats import measure as measure_module
from opencensus.stats import stats as stats_module
from opencensus.stats import view as view_module
from opencensus_ext_newrelic import NewRelicStatsExporter

# The stats recorder
stats = stats_module.stats
view_manager = stats.view_manager
stats_recorder = stats.stats_recorder
newrelic = NewRelicStatsExporter(
    os.environ["NEW_RELIC_INSERT_KEY"], service_name="Example Service"

# Create the measures and views
# The latency in milliseconds
m_latency_ms = measure_module.MeasureFloat(
    "task_latency", "The task latency in milliseconds", "ms"

latency_view = view_module.View(
    "The latest task latency",

mmap = stats_recorder.new_measurement_map()

# Record a metric
mmap.measure_float_put(m_latency_ms, 50)

# Send all data and stop the exporter

Find and use data

Tips on how to find and query your data in New Relic:

For general querying information, see:

Project details

Download files

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

Files for opencensus-ext-newrelic, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size opencensus_ext_newrelic-0.2.1-py2.py3-none-any.whl (13.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size opencensus-ext-newrelic-0.2.1.tar.gz (23.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page