New Relic OpenCensus exporter
The opencensus-ext-newrelic package provides Python exporters to plug into OpenCensus! Both spans and metrics may be exported using these exporters!
Requirements
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:
NEW_RELIC_INSERT_KEY
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:
time.sleep(0.5)
# Send all data and stop the exporter
newrelic.stop()
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:
NEW_RELIC_INSERT_KEY
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"
)
view_manager.register_exporter(newrelic)
# 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(
"task_latency_latest",
"The latest task latency",
[],
m_latency_ms,
aggregation_module.LastValueAggregation(),
)
view_manager.register_view(latency_view)
mmap = stats_recorder.new_measurement_map()
# Record a metric
mmap.measure_float_put(m_latency_ms, 50)
mmap.record()
# Send all data and stop the exporter
newrelic.stop()
Find and use data
Tips on how to find and query your data in New Relic:
For general querying information, see:
Metadata
Release files for opencensus-ext-newrelic 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| opencensus-ext-newrelic-0.2.1.tar.gz | 23.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opencensus_ext_newrelic-0.2.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 36.9 kB
Release files / opencensus-ext-newrelic-0.2.1.tar.gz
| Download URL | opencensus-ext-newrelic-0.2.1.tar.gz |
|---|---|
| Size | 23.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3ca56f330e520f8237a66c5f2f4d21c078353fca76778068d0255ad2792446b
|
|
BLAKE2b-256 checksum How to use checksums |
fb29bb3b0061e52f447c1c08d2c3a0ad40d5db348c262cdda772a6995b584107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Release files / opencensus_ext_newrelic-0.2.1-py2.py3-none-any.whl
| Download URL | opencensus_ext_newrelic-0.2.1-py2.py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d33fc3f1ec426e0ef1701765d2636a1167d1ea382c8ff2a8c3bef7f659cefb30
|
|
BLAKE2b-256 checksum How to use checksums |
0485b2e2397372bf32d3c24fc95bf50e8c7abebb76a23b902d58f3d35dc30de5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|