Esempio n. 1
0
def trace_exporter(hosts, insert_key):
    exporter = NewRelicTraceExporter(
        insert_key=insert_key,
        transport=Transport,
        host=hosts["trace"],
        service_name="Python Application",
    )
    return exporter
Esempio n. 2
0
def test_override_exporter_values(insert_key):
    host = "non-default-host"
    port = 8080
    exporter = NewRelicTraceExporter(
        insert_key,
        service_name="Python Application",
        transport=CustomTransport,
        host=host,
        port=port,
    )

    assert isinstance(exporter._transport, CustomTransport)
    assert exporter.client._pool.host == host
    assert exporter.client._pool.port == port
import grpc

import demo_pb2
import demo_pb2_grpc

from logger import getJSONLogger
logger = getJSONLogger('emailservice-client')

from opencensus_ext_newrelic import NewRelicTraceExporter
from opencensus.ext.grpc import client_interceptor
from opencensus.trace import samplers

try:
    sampler = samplers.AlwaysOnSampler()
    exporter = NewRelicTraceExporter(
        insert_key=os.environ["NEW_RELIC_API_KEY"],
        host=urlparse(os.environ["NEW_RELIC_TRACE_URL"]).hostname,
        service_name="emailservice")
    tracer = Tracer(exporter=exporter)
    tracer_interceptor = client_interceptor.OpenCensusClientInterceptor(
        tracer, host_port='0.0.0.0:8080')
except:
    tracer_interceptor = client_interceptor.OpenCensusClientInterceptor()


def send_confirmation_email(email, order):
    channel = grpc.insecure_channel('0.0.0.0:8080')
    channel = grpc.intercept_channel(channel, tracer_interceptor)
    stub = demo_pb2_grpc.EmailServiceStub(channel)
    try:
        response = stub.SendOrderConfirmation(
            demo_pb2.SendOrderConfirmationRequest(email=email, order=order))
Esempio n. 4
0
def test_default_exporter_values(insert_key):
    exporter = NewRelicTraceExporter(insert_key, service_name="Python Application")

    assert isinstance(exporter._transport, DefaultTransport)
    assert exporter.client._pool.host == SpanClient.HOST
    assert exporter.client._pool.port == 443