Skip to content
This repository has been archived by the owner on Sep 18, 2018. It is now read-only.

Commit

Permalink
Utilize baseplate request tracing in activity gateway/service
Browse files Browse the repository at this point in the history
Add tracing
  • Loading branch information
ckwang8128 committed Dec 1, 2016
1 parent d69711c commit c5438cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions example.ini
Expand Up @@ -20,6 +20,9 @@ activity.window = 15 minutes
; the minimum number of visitors in a context before fuzzing goes away
activity.fuzz_threshold = 100

; request tracing
tracing.service_name = activity
tracing.endpoint =

; an HTTP service which accepts pixel-like requests from browsers and records
; the users' activity with the thrift service.
Expand All @@ -30,6 +33,10 @@ factory = reddit_service_activitygateway:make_wsgi_app
metrics.namespace = activity_gateway
metrics.endpoint =

; request tracing
tracing.service_name = activity_gateway
tracing.endpoint =

; where to find the thrift activity service
activity.endpoint = localhost:9090

Expand Down
9 changes: 8 additions & 1 deletion reddit_service_activity/__init__.py
Expand Up @@ -109,7 +109,10 @@ def make_processor(app_config): # pragma: nocover
"window": config.Timespan,
"fuzz_threshold": config.Integer,
},

"tracing": {
"endpoint": config.Optional(config.Endpoint),
"service_name": config.String,
},
"redis": {
"url": config.String,
"max_connections": config.Optional(config.Integer, default=100),
Expand All @@ -126,6 +129,10 @@ def make_processor(app_config): # pragma: nocover
baseplate = Baseplate()
baseplate.configure_logging()
baseplate.configure_metrics(metrics_client)
baseplate.configure_tracing(
cfg.tracing.service_name,
cfg.tracing.endpoint,
)
baseplate.add_to_context("redis", RedisContextFactory(redis_pool))

counter = ActivityCounter(cfg.activity.window.total_seconds())
Expand Down
11 changes: 10 additions & 1 deletion reddit_service_activitygateway/__init__.py
Expand Up @@ -47,6 +47,10 @@ def make_wsgi_app(app_config):
"activity": {
"endpoint": config.Endpoint,
},
"tracing": {
"endpoint": config.Optional(config.Endpoint),
"service_name": config.String,
},
})

metrics_client = make_metrics_client(app_config)
Expand All @@ -56,8 +60,13 @@ def make_wsgi_app(app_config):
baseplate = Baseplate()
baseplate.configure_logging()
baseplate.configure_metrics(metrics_client)
baseplate.configure_tracing(
cfg.tracing.service_name,
cfg.tracing.endpoint,
)

baseplate.add_to_context("activity",
ThriftContextFactory(pool, ActivityService.Client))
ThriftContextFactory(pool, ActivityService.Client))

configurator = Configurator(settings=app_config)

Expand Down
2 changes: 2 additions & 0 deletions tests/gateway_tests.py
Expand Up @@ -45,6 +45,8 @@ def setUp(self, metrics_client, ThriftConnectionPool):
"activity.endpoint": "/socket",
"metrics.endpoint": "/socket",
"metrics.namespace": "namespace",
"tracing.endpoint": None,
"tracing.service_name": "activity_gateway",
})

self.test_app = webtest.TestApp(app)
Expand Down

0 comments on commit c5438cc

Please sign in to comment.