Skip to content

Commit

Permalink
feat: enable opentelemetry grpc instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fdupont committed Feb 6, 2024
1 parent 1f8e804 commit f1f18c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"treelite_runtime~=2.2.2",
"scikit-learn~=1.2.0",
"cloudpickle~=2.1.0",
"opentelemetry-instrumentation-grpc~=0.38b0",
"opentelemetry-api>=1.17.0, <2.0",
"opentelemetry-sdk>=1.17.0, <2.0",
"opentelemetry-exporter-otlp>=1.17.0, <2.0",
]
extras_require_test = [
*extras_require_serving,
Expand Down
15 changes: 15 additions & 0 deletions src/pythie_serving/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
from logging.config import dictConfig

from google.protobuf import text_format
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.grpc import GrpcInstrumentorServer
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from pythie_serving import create_grpc_server
from pythie_serving.tensorflow_proto.tensorflow_serving.config import (
model_server_config_pb2,
)


def initialize_tracing():
tracing_collector_host = str(os.environ.get("TRACING_COLLECTOR_HOST"))
if tracing_collector_host is not None:
trace.set_tracer_provider(TracerProvider())
otlp_exporter = OTLPSpanExporter(endpoint=tracing_collector_host, insecure=True)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(otlp_exporter))
GrpcInstrumentorServer().instrument()


def run():
initialize_tracing()
model_choice_set = {"xgboost", "lightgbm", "treelite", "sklearn", "table"}
model_choice_str = ",".join(model_choice_set)

Expand Down

0 comments on commit f1f18c8

Please sign in to comment.