Created
July 5, 2021 09:18
-
-
Save RobertRosca/c7a282ce7746c0d06a659e0c235c371d to your computer and use it in GitHub Desktop.
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
import flask | |
import requests | |
from opentelemetry import trace | |
from opentelemetry.instrumentation.flask import FlaskInstrumentor | |
from opentelemetry.exporter.jaeger.thrift import JaegerExporter | |
from opentelemetry.instrumentation.requests import RequestsInstrumentor | |
from opentelemetry.sdk.trace.export import BatchSpanProcessor | |
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | |
from opentelemetry.sdk.trace import TracerProvider | |
from opentelemetry.sdk.trace.export import ( | |
ConsoleSpanExporter, | |
SimpleSpanProcessor, | |
) | |
trace.set_tracer_provider( | |
TracerProvider( | |
resource=Resource.create({SERVICE_NAME: "flask-example"}) | |
) | |
) | |
jaeger_exporter = JaegerExporter( | |
agent_host_name="localhost", | |
agent_port=6831, | |
) | |
trace.get_tracer_provider().add_span_processor( | |
BatchSpanProcessor(jaeger_exporter) | |
) | |
app = flask.Flask(__name__) | |
FlaskInstrumentor().instrument_app(app) | |
RequestsInstrumentor().instrument() | |
@app.route("/") | |
def hello(): | |
tracer = trace.get_tracer(__name__) | |
with tracer.start_as_current_span("example-request"): | |
requests.get("http://www.example.com") | |
return "hello" | |
app.run(debug=True, port=5000) |
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "4de1cf4f-febb-4c66-8a7f-896e8c604eaf", | |
"metadata": {}, | |
"source": [ | |
"# Future Plans?\n", | |
"\n", | |
"Basic instrumentation is pretty simple, so adding in telemetry for:\n", | |
"\n", | |
"- Module loaded\n", | |
"- Kernel loaded\n", | |
"- Environment activated\n", | |
"\n", | |
"Would be possible and give us information on how often our environments get used on Maxwell\n", | |
"\n", | |
"Any other ideas?" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment