Skip to content

Commit

Permalink
use exporter + interval instead of meter
Browse files Browse the repository at this point in the history
  • Loading branch information
cnnradams committed Jul 21, 2020
1 parent fc38c99 commit 964aff1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from opentelemetry.ext.grpc.version import __version__


def client_interceptor(tracer_provider=None, meter=None):
def client_interceptor(tracer_provider=None, exporter=None, interval=30):
"""Create a gRPC client channel interceptor.
Args:
Expand All @@ -34,7 +34,7 @@ def client_interceptor(tracer_provider=None, meter=None):

tracer = trace.get_tracer(__name__, __version__, tracer_provider)

return _client.OpenTelemetryClientInterceptor(tracer, meter)
return _client.OpenTelemetryClientInterceptor(tracer, exporter, interval)


def server_interceptor(tracer_provider=None):
Expand Down
10 changes: 7 additions & 3 deletions ext/opentelemetry-ext-grpc/src/opentelemetry/ext/grpc/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

import grpc

from opentelemetry import propagators, trace
from opentelemetry import metrics, propagators, trace
from opentelemetry.sdk.metrics.export.controller import PushController
from opentelemetry.trace.status import Status, StatusCanonicalCode

from . import grpcext
Expand Down Expand Up @@ -83,9 +84,12 @@ def callback(response_future):
class OpenTelemetryClientInterceptor(
grpcext.UnaryClientInterceptor, grpcext.StreamClientInterceptor
):
def __init__(self, tracer, meter):
def __init__(self, tracer, exporter, interval):
self._tracer = tracer
self._meter = meter
self._meter = metrics.get_meter(__name__)
self.controller = PushController(
meter=self._meter, exporter=exporter, interval=interval
)
self._metrics_recorder = TimedMetricRecorder(self._meter, "client")

def _start_span(self, method):
Expand Down
18 changes: 7 additions & 11 deletions ext/opentelemetry-ext-grpc/tests/test_client_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
import grpc

import opentelemetry.ext.grpc
from opentelemetry import metrics, trace
from opentelemetry import trace
from opentelemetry.ext.grpc import client_interceptor
from opentelemetry.ext.grpc.grpcext import intercept_channel
from opentelemetry.sdk.metrics.export.aggregate import (
MinMaxSumCountAggregator,
SumAggregator,
)
from opentelemetry.sdk.metrics.export.controller import PushController
from opentelemetry.test.test_base import TestBase
from tests.protobuf import test_server_pb2_grpc

Expand All @@ -40,24 +39,21 @@ def setUp(self):
super().setUp()
self.server = create_test_server(25565)
self.server.start()
meter = metrics.get_meter(__name__)
interceptor = client_interceptor(meter=meter)
self.interceptor = client_interceptor(
exporter=self.memory_metrics_exporter
)
self.channel = intercept_channel(
grpc.insecure_channel("localhost:25565"), interceptor
grpc.insecure_channel("localhost:25565"), self.interceptor
)
self._stub = test_server_pb2_grpc.GRPCTestServerStub(self.channel)

self._controller = PushController(
meter, self.memory_metrics_exporter, 30
)

def tearDown(self):
super().tearDown()
self.memory_metrics_exporter.clear()
self.server.stop(None)

def _verify_success_records(self, num_bytes_out, num_bytes_in, method):
self._controller.tick()
self.interceptor.controller.tick()
records = self.memory_metrics_exporter.get_exported_metrics()
self.assertEqual(len(records), 3)

Expand Down Expand Up @@ -167,7 +163,7 @@ def test_stream_stream(self):
)

def _verify_error_records(self, method):
self._controller.tick()
self.interceptor.controller.tick()
records = self.memory_metrics_exporter.get_exported_metrics()
self.assertEqual(len(records), 3)

Expand Down

0 comments on commit 964aff1

Please sign in to comment.