def init_tracing(service_name): if Config.TRACE_EXPORTER is None: return elif Config.TRACE_EXPORTER == 'jaeger': exporter = JaegerSpanExporter( service_name=service_name, agent_host_name=Config.JAEGER_HOST, agent_port=6831, ) elif Config.TRACE_EXPORTER == 'honeycomb': exporter = HoneycombSpanExporter( service_name=service_name, writekey=Config.HONEYCOMB_API_KEY, dataset=Config.HONEYCOMB_DATASET, ) else: raise ValueError( f"TRACE_EXPORTER {Config.TRACE_EXPORTER} is not valid") trace.set_tracer_provider(TracerProvider()) span_processor = BatchExportSpanProcessor(exporter) trace.get_tracer_provider().add_span_processor(span_processor) # This isn't great but oh well global tracer tracer = trace.get_tracer(service_name)
def init_tracer(): from opentelemetry.ext.jaeger import JaegerSpanExporter exporter = JaegerSpanExporter( service_name="basic", agent_host_name="localhost", agent_port=6831 ) trace.set_tracer_provider(TracerProvider()) span_processor = BatchExportSpanProcessor(exporter) trace.get_tracer_provider().add_span_processor(span_processor)
def _grpc(): """Start discount gRPC server.""" logging.basicConfig(level=logging.INFO) engine = create_engine(settings.DATABASE_URL) Session = sessionmaker(bind=engine) connection = engine.connect() session = Session(bind=connection) exporter = ConsoleSpanExporter() if settings.TRACER_ENDPOINT_HOST and settings.TRACER_ENDPOINT_PORT: exporter = JaegerSpanExporter( service_name="promotion-grpc", agent_host_name=settings.TRACER_ENDPOINT_HOST, agent_port=settings.TRACER_ENDPOINT_PORT, ) trace.set_preferred_tracer_source_implementation(lambda T: TracerSource()) tracer = trace.get_tracer(__name__) ## span_processor = BatchExportSpanProcessor(exporter) span_processor = SimpleExportSpanProcessor(exporter) trace.tracer_source().add_span_processor(span_processor) tracer = trace.get_tracer(__name__) user_store = UserDataStore(session, tracer) user_case = UserUseCase(user_store, tracer) order_store = OrderDataStore(session, tracer) order_case = OrderUseCase(order_store, tracer) balance_client = BalanceClient(settings.BALANCE_TOKEN) balance_case = BalanceUseCase(order_case, balance_client, tracer) holiday_store = HolidayDataStore(settings.BLACK_FRIDAY_DATE, tracer) holiday_case = HolidayUseCase(holiday_store, tracer) authentication_case = AuthenticationUseCase(user_case, tracer) case = PromotionUseCase(discounts=[holiday_case, user_case], tracer=tracer) servicer = PromotionServicer(case, user_case, order_case, balance_case, authentication_case, tracer) server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) service.add_PromotionAPIServicer_to_server(servicer, server) logger.info("Listenning on port 50051.") server.add_insecure_port("[::]:50051") server.start() server.wait_for_termination()
async def __aenter__(self): exporter = JaegerSpanExporter( service_name=self._config.service_name, agent_host_name=self._config.address.host, agent_port=self._config.address.port, ) span_processor = BatchExportSpanProcessor(exporter) source: TracerProvider = get_tracer_provider() source.add_span_processor(span_processor) _log.info( "%s started: service_name=%s; addr=%s:%d", self.__class__.__name__, self._config.service_name, self._config.address.host, self._config.address.port, )
import os from opentelemetry import trace from opentelemetry.context import Context from opentelemetry.sdk.trace import TracerSource from opentelemetry.sdk.trace.export import ( BatchExportSpanProcessor, ConsoleSpanExporter, ) if os.getenv("EXPORTER") == "jaeger": from opentelemetry.ext.jaeger import JaegerSpanExporter exporter = JaegerSpanExporter( service_name="basic-service", agent_host_name="localhost", agent_port=6831, ) else: exporter = ConsoleSpanExporter() # The preferred tracer implementation must be set, as the opentelemetry-api # defines the interface with a no-op implementation. trace.set_preferred_tracer_source_implementation(lambda T: TracerSource()) # We tell OpenTelemetry who it is that is creating spans. In this case, we have # no real name (no setup.py), so we make one up. If we had a version, we would # also specify it here. tracer = trace.tracer_source().get_tracer(__name__) # SpanExporter receives the spans and send them to the target location.
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from oteltrace import patch_all patch_all() from oteltrace import tracer # noqa: E402 from oteltrace.api_otel_exporter import APIOtel # noqa: E402 from opentelemetry.ext.jaeger import JaegerSpanExporter # noqa: E402 from oteltrace.propagation.w3c import W3CHTTPPropagator # noqa: E402 # create Jaeger Exporter jaeger_exporter = JaegerSpanExporter(service_name='example2', ) # configure tracer with Jaeger exporter and w3c as http propagator tracer.configure( api=APIOtel(exporter=jaeger_exporter), http_propagator=W3CHTTPPropagator, ) # same code of example1 from flask import Flask # noqa: E402 import requests # noqa: E402 app = Flask(__name__) @app.route('/')
import requests from opentelemetry import trace from opentelemetry.ext import http_requests from opentelemetry.sdk.trace import TracerSource from opentelemetry.sdk.trace.export import ( BatchExportSpanProcessor, ConsoleSpanExporter, ) if os.getenv("EXPORTER") == "jaeger": from opentelemetry.ext.jaeger import JaegerSpanExporter exporter = JaegerSpanExporter( service_name="http-client", agent_host_name="localhost", agent_port=6831, ) else: exporter = ConsoleSpanExporter() # The preferred tracer implementation must be set, as the opentelemetry-api # defines the interface with a no-op implementation. trace.set_preferred_tracer_source_implementation(lambda T: TracerSource()) tracer_source = trace.tracer_source() # SpanExporter receives the spans and send them to the target location. span_processor = BatchExportSpanProcessor(exporter) tracer_source.add_span_processor(span_processor) # Integrations are the glue that binds the OpenTelemetry API and the
import os from opentelemetry import trace from opentelemetry.ext.jaeger import JaegerSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer(__name__) exporter = JaegerSpanExporter( service_name="my-helloworld-service", # configure agent agent_host_name="localhost", agent_port=6831, # optional: configure also collector # collector_host_name="localhost", # collector_port=14268, # collector_endpoint="/api/traces?format=jaeger.thrift", # username=xxxx, # optional # password=xxxx, # optional ) span_processor = BatchExportSpanProcessor(exporter) trace.get_tracer_provider().add_span_processor(span_processor) with tracer.start_as_current_span("foo"): with tracer.start_as_current_span("bar"): with tracer.start_as_current_span("baz"): print("Hello world from OpenTelemetry Python!")
from opentelemetry import trace from opentelemetry.ext import opentracing_shim from opentelemetry.ext.jaeger import JaegerSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor from rediscache import RedisCache # 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__)