-
-
Save manuel-delverme/06ff5b2ad5d25ccd6cf89e6b8a7f1295 to your computer and use it in GitHub Desktop.
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 time | |
| import requests | |
| from opentelemetry import trace as trace_api | |
| from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | |
| from opentelemetry.sdk import trace as trace_sdk | |
| from opentelemetry.sdk.trace.export import SimpleSpanProcessor | |
| endpoint = "http://example.mars/" | |
| tracer_provider = trace_sdk.TracerProvider() | |
| tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) | |
| trace_api.set_tracer_provider(tracer_provider) | |
| tracer = trace_api.get_tracer("my_module") | |
| def long_expensive_operation(): | |
| time.sleep(3) | |
| def current_setting(): | |
| with tracer.start_span("takeoff") as span_a: | |
| long_expensive_operation() | |
| def early_failure(): | |
| requests.get(tracer.span_processor._span_processors[0].span_exporter._endpoint) | |
| with tracer.start_span("takeoff") as span_a: | |
| long_expensive_operation() | |
| t0 = time.time() | |
| current_setting() | |
| print("current time to failure", time.time() - t0) | |
| t0 = time.time() | |
| try: | |
| early_failure() | |
| except requests.exceptions.ConnectionError: | |
| print("early failure time to failure", time.time() - t0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment