Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC integration #476

Merged
merged 68 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
1f772fa
Add package boilerplate
c24t Mar 10, 2020
3377e9e
Copy OC examples
c24t Mar 10, 2020
38bb4ef
Move examples, add boilerplate
c24t Mar 10, 2020
7182f3d
Add stub client and server interceptors
c24t Mar 10, 2020
9e4cbca
Add gRPC unary examples
c24t Mar 10, 2020
72a8247
Add stub docs
c24t Mar 11, 2020
d09a0e9
Add unary server interceptor logic
c24t Mar 12, 2020
d11b855
Extend server example
c24t Mar 12, 2020
0c33c80
Add server interceptor tests
c24t Mar 12, 2020
f0b0ba5
TODOs
c24t Mar 12, 2020
483c32f
Missing init
c24t Mar 13, 2020
88e9467
Copy grpc_opentracing
c24t Mar 13, 2020
987d6d4
Cleanup
c24t Mar 13, 2020
3c80b31
Scrub more OpenTracing references, unused code
c24t Mar 24, 2020
19d91ec
Add wait_for_termination
c24t Mar 24, 2020
5a74710
Update interceptors, unary examples
c24t Mar 24, 2020
20c0e9f
Merge branch 'master' into grpc-again
c24t Mar 24, 2020
b597a80
Use get/set_tracer_provider
c24t Mar 24, 2020
f24f826
Add gRPC route guide streaming examples
c24t Mar 24, 2020
6a104cc
Update generated gRPC files
c24t Mar 24, 2020
5846938
Instrument gRPC examples
c24t Mar 24, 2020
82a78de
Handle streaming requests/responses in client
c24t Mar 24, 2020
aa79c70
Handle streaming requests/responses in server
c24t Mar 24, 2020
3845604
Update server tests
c24t Mar 25, 2020
9cf65ab
Set server context explicitly
c24t Mar 25, 2020
835e831
Merge branch 'master' into grpc-again
c24t Mar 25, 2020
55efac2
Remove unused server test classes
c24t Mar 25, 2020
82530ae
Exclude gRPC examples from lint
c24t Mar 25, 2020
8ea858f
Remove OC interceptors
c24t Mar 25, 2020
ac10d52
Update server context managers
c24t Mar 25, 2020
60afdb8
s/OpenTelemetry/OpenTracing/
c24t Mar 25, 2020
fa18357
Move grpc examples, generated code
c24t Mar 25, 2020
bc585d4
Make examples portable
c24t Mar 25, 2020
a3e0c86
Lint, blacken
c24t Mar 25, 2020
401b488
Don't lint generated files
c24t Mar 25, 2020
47e4eed
Remove extra test file
c24t Mar 26, 2020
bb33a9d
Update ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/version.py
c24t Mar 26, 2020
3d49b86
Remove old example dir
c24t Mar 26, 2020
df9f745
Remove copyright year (#523)
mauriciovasquezbernal Mar 25, 2020
656d3a4
Update PyPI classifiers (#525)
mauriciovasquezbernal Mar 25, 2020
8c495e1
Add indicator if SpanContext was propagated from remote parent (#516)
mariojonke Mar 26, 2020
ae08b19
docs: Remove authors from releases (#531)
dgzlopes Mar 26, 2020
8100ab6
Update license boilerplate for #523
c24t Mar 26, 2020
d4b9ca0
Add example app protobuf req, add docs
c24t Mar 26, 2020
e9c0f94
Merge branch 'master' into grpc-again
c24t Mar 26, 2020
b484813
Formatting fix
c24t Mar 26, 2020
f5ae625
Remove grpc example app requirement for now
c24t Mar 27, 2020
2ae99f9
Remove commented code
c24t Mar 30, 2020
720f074
Merge branch 'master' into grpc-again
c24t Mar 30, 2020
9392b67
need a lock when initializing the context
Mar 30, 2020
c10b76f
Merge pull request #4 from codeboten/grpc-again
c24t Mar 30, 2020
a545cdd
Merge branch 'master' into grpc-again
c24t Mar 30, 2020
ac3e617
Don't lint generated files
c24t Mar 30, 2020
88a21ff
Fix now-unused import
c24t Mar 30, 2020
ef080be
Pylint grpcext fixes
c24t Mar 30, 2020
a6eb598
Pylint fixes
c24t Mar 30, 2020
aeb7b5f
Merge branch 'master' into grpc-again
c24t Mar 30, 2020
08e6687
Pylint fixes, ignores
c24t Mar 30, 2020
59858d4
More pylint fixes
c24t Mar 30, 2020
4288861
Merge branch 'master' into grpc-again
c24t Mar 30, 2020
9f5c85a
Misc isort fixes (#535)
c24t Mar 30, 2020
eca618c
Merge branch 'master' into grpc-again
c24t Mar 30, 2020
4e048e0
adding a tox environment for grpc
toumorokoshi Mar 30, 2020
7b950a8
fixing lint
toumorokoshi Mar 30, 2020
06b4c19
Less silly documentation
c24t Mar 30, 2020
8956bfb
Py3.4 threadpools need max_workers
c24t Mar 31, 2020
a8d07cf
Add missing test init
c24t Mar 31, 2020
12db93b
Remove pypy3-test-ext-grpc tox target
c24t Mar 31, 2020
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
7 changes: 7 additions & 0 deletions docs/ext/grpc/grpc.client_interceptor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
grpc.client\_interceptor module
===============================

.. automodule:: opentelemetry.ext.grpc.client_interceptor
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/ext/grpc/grpc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. include:: ../../../ext/opentelemetry-ext-grpc/README.rst

Submodules
----------

.. toctree::

grpc.client_interceptor
grpc.server_interceptor

Module contents
---------------

.. automodule:: opentelemetry.ext.grpc
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/ext/grpc/grpc.server_interceptor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
grpc.server\_interceptor module
===============================

.. automodule:: opentelemetry.ext.grpc.server_interceptor
:members:
:undoc-members:
:show-inheritance:
Empty file.
16 changes: 16 additions & 0 deletions ext/opentelemetry-ext-grpc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
OpenTelemetry gRPC Integration
==============================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-grpc.svg
:target: https://pypi.org/project/opentelemetry-ext-grpc/

gRPC support!

Installation
------------

::

pip install opentelemetry-ext-grpc
26 changes: 26 additions & 0 deletions ext/opentelemetry-ext-grpc/examples/codegen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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 grpc_tools import protoc


def main():
return protoc.main(
["-I.", "--python_out=.", "--grpc_python_out=.", "helloworld.proto"]
)


if __name__ == "__main__":
main()
46 changes: 46 additions & 0 deletions ext/opentelemetry-ext-grpc/examples/hello_world_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

# https://github.com/grpc/grpc/blob/master/examples/python/helloworld/greeter_client.py
# https://github.com/grpc/grpc/blob/v1.16.x/examples/python/interceptors/default_value/greeter_client.py
"""The Python implementation of the GRPC helloworld.Greeter client."""

import logging

import grpc

import helloworld_pb2
import helloworld_pb2_grpc
from opentelemetry.ext.grpc import client_interceptor

interceptor = client_interceptor.OpenTelemetryClientInterceptor()


def run():
# NOTE(gRPC Python Team): .close() is possible on a channel and should be
# used in circumstances in which the with statement does not fit the needs
# of the code.
with grpc.insecure_channel("localhost:50051") as channel:

intercepted_channel = grpc.intercept_channel(channel, interceptor)
stub = helloworld_pb2_grpc.GreeterStub(intercepted_channel)

response = stub.SayHello(helloworld_pb2.HelloRequest(name="YOU"))
print("Greeter client received: " + response.message)


if __name__ == "__main__":
logging.basicConfig()
run()
61 changes: 61 additions & 0 deletions ext/opentelemetry-ext-grpc/examples/hello_world_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

# https://github.com/grpc/grpc/blob/master/examples/python/helloworld/greeter_server.py
"""The Python implementation of the GRPC helloworld.Greeter server."""

import logging
from concurrent import futures

import grpc

import helloworld_pb2
import helloworld_pb2_grpc
from opentelemetry import trace
from opentelemetry.ext.grpc import server_interceptor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleExportSpanProcessor,
)

trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
trace.tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.get_tracer(__name__)


class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message="Hello, %s!" % request.name)


def serve():

interceptor = server_interceptor.OpenTelemetryServerInterceptor(tracer)
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=10), interceptors=(interceptor,)
)

helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port("[::]:50051")
server.start()
server.wait_for_termination()


if __name__ == "__main__":
logging.basicConfig()
serve()
35 changes: 35 additions & 0 deletions ext/opentelemetry-ext-grpc/examples/helloworld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.

// https://github.com/grpc/grpc/blob/master/examples/protos/helloworld.proto

syntax = "proto3";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
132 changes: 132 additions & 0 deletions ext/opentelemetry-ext-grpc/examples/helloworld_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading