# See the License for the specific language governing permissions and
# limitations under the License.

import grpc
from opentelemetry import propagate, trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.grpc import client_interceptor
from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

import demo_pb2
import demo_pb2_grpc
from logger import get_json_logger

logger = get_json_logger("emailservice-client")

try:
    trace.set_tracer_provider(TracerProvider())
    trace.get_tracer_provider().add_span_processor(
        SimpleSpanProcessor(CloudTraceSpanExporter()))
    propagate.set_global_textmap(CloudTraceFormatPropagator())
    tracer_interceptor = client_interceptor(trace.get_tracer_provider())
except Exception as e:
    raise Exception("{}".format(e))


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)
Beispiel #2
0
from concurrent import futures
import os
import time

import grpc
from grpc_health.v1.health_pb2 import HealthCheckResponse
from grpc_health.v1.health_pb2_grpc import add_HealthServicer_to_server
import psycopg2

import echo_pb2_grpc
import echo_pb2
from logger import get_json_logger

logger = get_json_logger("echo")
port = "9090"


class EchoService(echo_pb2_grpc.EchoServiceServicer):
    def __init__(self):
        psql_host, psql_port = os.environ['POSTGRES_DB_HOST'].split(':')
        logger.info(f"psql_host: {psql_host}, psql_port: {psql_port}")
        self._conn = psycopg2.connect(
            user=os.environ['POSTGRES_DB_USER'],
            password=os.environ['POSTGRES_DB_PASSWORD'],
            host=psql_host,
            port=psql_port,
        )
        logger.info("Done creating connection")

    def Echo(self, request, context):
        cur = self._conn.cursor()
from grpc_health.v1 import health_pb2, health_pb2_grpc
from opentelemetry import propagate, trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.grpc import (client_interceptor,
                                                server_interceptor)
from opentelemetry.instrumentation.grpc.grpcext import intercept_channel
from opentelemetry.propagators.cloud_trace_propagator import \
    CloudTraceFormatPropagator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

import demo_pb2
import demo_pb2_grpc
from logger import get_json_logger

logger = get_json_logger('recommendationservice-server')

try:
    import googleclouddebugger
    googleclouddebugger.enable(
        module='recommendationservice',
        version='1.0.0'
    )
except ImportError:
    logger.error("could not enable debugger")
    logger.error(traceback.print_exc())
    pass


class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
    def ListRecommendations(self, request, context):
Beispiel #4
0
import grpc
from google.api_core.exceptions import GoogleAPICallError
from grpc_health.v1 import health_pb2, health_pb2_grpc
from jinja2 import Environment, FileSystemLoader, TemplateError, select_autoescape
from opentelemetry import propagate, trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.grpc import server_interceptor
from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

import demo_pb2
import demo_pb2_grpc
from logger import get_json_logger

logger = get_json_logger("emailservice-server")

try:
    import googleclouddebugger

    googleclouddebugger.enable(module="emailserver", version="1.0.0")
except ImportError:
    logger.error("could not enable debugger")
    logger.error(traceback.print_exc())

# Loads confirmation email template from file
env = Environment(loader=FileSystemLoader("templates"),
                  autoescape=select_autoescape(["html", "xml"]))
template = env.get_template("confirmation.html")