Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions instana/instrumentation/grpcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,6 @@ def call_behavior_with_instana(wrapped, instance, argv, kwargs):
else:
return rv

logger.debug("Instrumenting grpcio")
except ImportError:
pass
54 changes: 54 additions & 0 deletions tests/apps/grpc_server/stan_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import absolute_import

import time
import random

import grpc
import stan_pb2
import stan_pb2_grpc

from instana.singletons import tracer

testenv = dict()
testenv["grpc_port"] = 10814
testenv["grpc_host"] = "127.0.0.1"
testenv["grpc_server"] = testenv["grpc_host"] + ":" + str(testenv["grpc_port"])


def generate_questions():
""" Used in the streaming grpc tests """
questions = [
stan_pb2.QuestionRequest(question="Are you there?"),
stan_pb2.QuestionRequest(question="What time is it?"),
stan_pb2.QuestionRequest(question="Where in the world is Waldo?"),
stan_pb2.QuestionRequest(question="What did one campfire say to the other?"),
stan_pb2.QuestionRequest(question="Is cereal soup?"),
stan_pb2.QuestionRequest(question="What is always coming, but never arrives?")
]
for q in questions:
yield q
time.sleep(random.uniform(0.2, 0.5))


channel = grpc.insecure_channel(testenv["grpc_server"])
server_stub = stan_pb2_grpc.StanStub(channel)
# The grpc client apparently needs a second to connect and initialize
time.sleep(1)

with tracer.start_active_span('http-server') as scope:
scope.span.set_tag('http.url', 'https://localhost:8080/grpc-client')
scope.span.set_tag('http.method', 'GET')
scope.span.set_tag('span.kind', 'entry')
response = server_stub.OneQuestionOneResponse(stan_pb2.QuestionRequest(question="Are you there?"))

with tracer.start_active_span('http-server') as scope:
scope.span.set_tag('http.url', 'https://localhost:8080/grpc-server-streaming')
scope.span.set_tag('http.method', 'GET')
scope.span.set_tag('span.kind', 'entry')
responses = server_stub.OneQuestionManyResponses(stan_pb2.QuestionRequest(question="Are you there?"))

with tracer.start_active_span('http-server') as scope:
scope.span.set_tag('http.url', 'https://localhost:8080/grpc-client-streaming')
scope.span.set_tag('http.method', 'GET')
scope.span.set_tag('span.kind', 'entry')
response = server_stub.ManyQuestionsOneResponse(generate_questions())
17 changes: 16 additions & 1 deletion tests/apps/grpc_server/stan_server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import os
import sys
import grpc
import time
import tests.apps.grpc_server.stan_pb2 as stan_pb2
import tests.apps.grpc_server.stan_pb2_grpc as stan_pb2_grpc
from concurrent import futures

from ...helpers import testenv
try:
from ...helpers import testenv
except ValueError:
# We must be running from the command line...
testenv = {}

testenv["grpc_port"] = 10814
testenv["grpc_host"] = "127.0.0.1"
Expand Down Expand Up @@ -80,3 +86,12 @@ def start_server(self):
rpc_server.stop(0)
print('Stan as a Service RPC Server Stopped ...')


if __name__ == "__main__":
print ("Booting foreground GRPC application...")
# os.environ["INSTANA_TEST"] = "true"

if sys.version_info >= (3, 5, 3):
StanServicer().start_server()
else:
print("Python v3.5.3 or higher only")