-
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.
- Loading branch information
1 parent
12102cb
commit dee2bb9
Showing
5 changed files
with
106 additions
and
7 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
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,79 @@ | ||
__author__ = "Jay Modi" | ||
|
||
import os | ||
import requests | ||
|
||
from flask import Flask | ||
from flask_restful import Resource as REST_Resource, Api | ||
from dotenv import load_dotenv | ||
|
||
# opentelemetry | ||
from opentelemetry import trace | ||
from opentelemetry.trace.status import StatusCode | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
|
||
# flask and requests instrumentation | ||
from opentelemetry.instrumentation.flask import FlaskInstrumentor | ||
from opentelemetry.instrumentation.requests import RequestsInstrumentor | ||
|
||
# exporters | ||
from opentelemetry.sdk.trace.export import ( | ||
ConsoleSpanExporter, | ||
SimpleSpanProcessor, | ||
BatchSpanProcessor | ||
) | ||
from opentelemetry.exporter.jaeger.thrift import JaegerExporter | ||
|
||
# propagator | ||
from opentelemetry.propagate import set_global_textmap | ||
from opentelemetry.propagators.b3 import B3Format | ||
|
||
load_dotenv() # take environment variables from .env | ||
|
||
# Set global propagator | ||
set_global_textmap(B3Format()) | ||
|
||
# set trace provider as default one | ||
trace.set_tracer_provider( | ||
TracerProvider( | ||
resource=Resource.create({SERVICE_NAME: "my-other-service"}) | ||
) | ||
) | ||
|
||
# jaeger exporter | ||
jaeger_exporter = JaegerExporter( | ||
agent_host_name="localhost", | ||
agent_port=6831, | ||
) | ||
|
||
# add exporter to trace | ||
trace.get_tracer_provider().add_span_processor( | ||
BatchSpanProcessor(jaeger_exporter) | ||
# SimpleSpanProcessor(ConsoleSpanExporter) | ||
) | ||
|
||
app = Flask(__name__) | ||
api = Api(app) | ||
|
||
FlaskInstrumentor().instrument_app(app) | ||
RequestsInstrumentor().instrument() | ||
|
||
|
||
class GetHelloWorld(REST_Resource): | ||
def get(self): | ||
tracer = trace.get_tracer(__name__) | ||
world = None | ||
with tracer.start_as_current_span("get-hello-request"): | ||
world = "World!" | ||
return {'hello': world} | ||
|
||
|
||
api.add_resource(GetHelloWorld, '/get-hello') | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run( | ||
debug=os.getenv("DEBUG"), | ||
port=3000 | ||
) |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.