Пример #1
0
 def setUp(self):
     """Create an OpenTelemetry tracer and a shim before every test case."""
     trace.set_tracer_provider(TracerProvider())
     self.shim = opentracingshim.create_tracer(trace.get_tracer_provider())
Пример #2
0
    def setUp(self):
        """Create an OpenTelemetry tracer and a shim before every test case."""

        self.shim = opentracingshim.create_tracer(trace.tracer_source())
Пример #3
0
import time

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.ext.opentracing_shim import create_tracer

# Tell OpenTelemetry which Tracer implementation to use.
trace.set_tracer_provider(TracerProvider())

# Create an OpenTelemetry Tracer.
otel_tracer = trace.get_tracer(__name__)

# Create an OpenTracing shim.
# shim = create_tracer(otel_tracer)
shim = create_tracer(trace.get_tracer_provider())

with shim.start_active_span("ProcessHTTPRequest"):
    print("Processing HTTP request")
    # Sleeping to mock real work.
    time.sleep(0.1)
    with shim.start_active_span("GetDataFromDB"):
        print("Getting data from DB")
        # Sleeping to mock real work.
        time.sleep(0.2)
Пример #4
0
# Configure the tracer using the default implementation
trace.set_tracer_provider(TracerProvider())
tracer_provider = trace.get_tracer_provider()

# Configure the tracer to export traces to Jaeger
jaeger_exporter = JaegerSpanExporter(
    service_name="OpenTracing Shim Example",
    agent_host_name="localhost",
    agent_port=6831,
)
span_processor = SimpleExportSpanProcessor(jaeger_exporter)
tracer_provider.add_span_processor(span_processor)

# Create an OpenTracing shim. This implements the OpenTracing tracer API, but
# forwards calls to the underlying OpenTelemetry tracer.
opentracing_tracer = opentracing_shim.create_tracer(tracer_provider)

# Our example caching library expects an OpenTracing-compliant tracer.
redis_cache = RedisCache(opentracing_tracer)

# Appication code uses an OpenTelemetry Tracer as usual.
tracer = trace.get_tracer(__name__)


@redis_cache
def fib(number):
    """Get the Nth Fibonacci number, cache intermediate results in Redis."""
    if number < 0:
        raise ValueError
    if number in (0, 1):
        return number
Пример #5
0
# Configure the tracer using the default implementation
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer_source = trace.tracer_source()

# Configure the tracer to export traces to Jaeger
jaeger_exporter = JaegerSpanExporter(
    service_name="OpenTracing Shim Example",
    agent_host_name="localhost",
    agent_port=6831,
)
span_processor = SimpleExportSpanProcessor(jaeger_exporter)
tracer_source.add_span_processor(span_processor)

# Create an OpenTracing shim. This implements the OpenTracing tracer API, but
# forwards calls to the underlying OpenTelemetry tracer.
opentracing_tracer = opentracing_shim.create_tracer(tracer_source)

# Our example caching library expects an OpenTracing-compliant tracer.
redis_cache = RedisCache(opentracing_tracer)

# Appication code uses an OpenTelemetry Tracer as usual.
tracer = trace.tracer_source().get_tracer(__name__)


@redis_cache
def fib(number):
    """Get the Nth Fibonacci number, cache intermediate results in Redis."""
    if number < 0:
        raise ValueError
    if number in (0, 1):
        return number