Last active
November 14, 2022 15:15
-
-
Save ashok-an/02b6aa8413f719c0aba1cdc472569510 to your computer and use it in GitHub Desktop.
opentelemetry kubernetes demo
This file contains hidden or 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 datetime | |
| from flask import Flask, jsonify | |
| then = datetime.datetime.now() | |
| app = Flask(__name__) | |
| @app.route('/', methods=['GET']) | |
| def root(): | |
| return jsonify({"message": "Hello world"}) | |
| @app.route('/healthz', methods=['GET']) | |
| def healthz(): | |
| now = datetime.datetime.now() | |
| delta = now - then | |
| return jsonify({"message": f"Up for {delta} seconds"}) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', debug=True) |
This file contains hidden or 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
| apiVersion: opentelemetry.io/v1alpha1 | |
| kind: OpenTelemetryCollector | |
| metadata: | |
| name: sidecar-collector | |
| spec: | |
| mode: sidecar | |
| config: | | |
| receivers: | |
| otlp: | |
| protocols: | |
| grpc: | |
| http: | |
| processors: | |
| exporters: | |
| logging: | |
| service: | |
| pipelines: | |
| traces: | |
| receivers: [otlp] | |
| processors: [] | |
| exporters: [otlp] |
This file contains hidden or 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
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| labels: | |
| app: flask-example | |
| name: flask-example | |
| spec: | |
| replicas: 1 | |
| selector: | |
| matchLabels: | |
| app: flask-example | |
| strategy: {} | |
| template: | |
| metadata: | |
| annotations: | |
| sidecar.opentelemtry.io/inject: "true" | |
| instrumentation.opentelemetry.io/inject-python: "true" | |
| labels: | |
| app: flask-example | |
| spec: | |
| containers: | |
| - image: ashoka007/flask-example:0.1 | |
| name: flask-example | |
| ports: | |
| - containerPort: 5000 | |
| resources: {} | |
| status: {} |
This file contains hidden or 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
| FROM python:3.10 | |
| WORKDIR /src | |
| COPY app.py . | |
| EXPOSE 5000 | |
| RUN pip install flask | |
| CMD ["python", "app.py"] | |
| # Build | |
| # docker build -t ashoka007/flask-example:0.1 |
This file contains hidden or 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
| apiVersion: opentelemetry.io/v1alpha1 | |
| kind: Instrumentation | |
| metadata: | |
| name: python-instrumentation | |
| spec: | |
| env: | |
| - name: OTEL_EXPORTER_OTLP_TIMEOUT | |
| value: "20" | |
| - name: OTEL_TRACES_SAMPLER | |
| value: parentbased_traceidratio | |
| - name: OTEL_TRACES_SAMPLER_ARG | |
| value: "0.85" | |
| exporter: | |
| endpoint: http://localhost:4317 | |
| propagators: | |
| - tracecontext | |
| - baggage | |
| sampler: | |
| type: parentbased_traceidratio | |
| argument: "0.25" | |
| python: | |
| env: | |
| - name: OTEL_LOG_LEVEL | |
| value: "debug" | |
| - name: OTEL_TRACES_EXPORTER | |
| value: otlp_proto_http | |
| - name: OTEL_EXPORTER_OTLP_ENDPOINT | |
| value: http://localhost:4317 |
This file contains hidden or 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
| flask |
This file contains hidden or 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
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| labels: | |
| app: flask-example | |
| name: flask-example | |
| namespace: default | |
| spec: | |
| ports: | |
| - port: 5000 | |
| selector: | |
| app: flask-example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment