New Relic OpenCensus Exporter
Project description
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()
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
Built Distribution
Close
Hashes for opencensus-ext-newrelic-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dfa2e9be2969347fb455157b1b25ed013d71e951dcdaf93e2b33a0cf6c5399d |
|
MD5 | 3dfd13bd5e50334ee49271c02c648263 |
|
BLAKE2b-256 | 8337c8e9b9b8f4f25b6154b1c487bd81a766db44ddaa1756fae3ff3bfeac98b5 |
Close
Hashes for opencensus_ext_newrelic-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d747cac44c27a0782449fe4485df852d9a273ca9ecfefc3cba47e67586525790 |
|
MD5 | 93fa08f4f5318e9969cbb14170a042a7 |
|
BLAKE2b-256 | 27f9802d95277400c47fcfef50312935964f9aa5e9498e841fc9435794da1f48 |