-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from DMS-SMS/develop
기본적인 Opentracing 작성
- Loading branch information
Showing
9 changed files
with
125 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from functools import wraps | ||
from infrastructure.extension import open_tracing | ||
from infrastructure.open_tracing import openTracing | ||
|
||
|
||
|
||
def jagger_enable(fn): | ||
@wraps(fn) | ||
def wrapper(*args, **kwargs): | ||
flag = 0 | ||
context = args[2] | ||
parents_span = str() | ||
x_request_id = str() | ||
for k, v in context.invocation_metadata(): | ||
if flag == 2: break | ||
if k == "x-request-id": | ||
x_request_id = v | ||
flag += 1 | ||
if k == "span-context": | ||
parents_span = v | ||
flag += 1 | ||
else: raise Exception | ||
|
||
open_tracing_service = openTracing(open_tracing.tracer, parents_span, x_request_id) | ||
return open_tracing_service.start_active_span(fn, *args, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from functools import wraps | ||
from jaeger_client import Config | ||
from jaeger_client.span_context import SpanContext | ||
|
||
|
||
class reigsterOpenTracing: | ||
def __init__(self): | ||
self._config = Config( | ||
config={ # usually read from some yaml config | ||
'logging': True, | ||
}, | ||
service_name='outing-service', | ||
validate=True, | ||
) | ||
self._tracer = self._config.initialize_tracer() | ||
|
||
@property | ||
def tracer(self): | ||
return self._tracer | ||
|
||
|
||
class openTracing: | ||
def __init__(self, tracer, span_context, x_request_id): | ||
self._split_span_context = span_context.split(":") | ||
self._trace_id = int(self._split_span_context[0], 16) | ||
self._span_id =int(self._split_span_context[1], 16) | ||
self._span_parent_id = int(self._split_span_context[2], 16) | ||
self._span_flag = int(self._split_span_context[3], 16) | ||
self._span_context = SpanContext( | ||
self._trace_id, | ||
self._span_id, | ||
self._span_parent_id, | ||
self._span_flag | ||
) | ||
self._tracer = tracer | ||
self._x_request_id = x_request_id | ||
|
||
|
||
def start_active_span(self, fn, *args, **kwargs): | ||
with self._tracer.start_active_span("OutingService", child_of=self._span_context) as span: | ||
self._tracer.active_span.set_tag("X-Request-Id", self._x_request_id) | ||
return_value = fn(args[0], args[1], args[2]) | ||
span.close() | ||
return return_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
from application import create_app | ||
from infrastructure.extension import consul | ||
|
||
|
||
def serve(app): | ||
try: | ||
app.start() | ||
print("* Presentation is served") | ||
consul.register_consul() | ||
app.wait_for_termination() | ||
except: | ||
consul.deregister_consul() | ||
from application import gRPCApplication | ||
|
||
from infrastructure.config.grpc_config import gRPCAppConfig | ||
from infrastructure.extension import consul | ||
|
||
if __name__ == "__main__": | ||
app = create_app() | ||
serve(app) | ||
app = gRPCApplication(gRPCAppConfig(), consul) | ||
app.serve() |