________ __________ ______ ____________ ___ ______ _____________ _____
________ __________ ____ ______ ___________ ____ ___ ____ __ ___ ______ __________ __ _____ __ ____ __ ________ ________ ______ ____ _______ __ _____ ___ __ ________ __________ ____ ______ ___________ ___ ______ _____________ ______
_____________ ____________ _____________ _____ ___ _____ __ ___ ______ ____________ __ _____________ ______ ______ ____ ______ ________ _____________ ____ ___________ __ ____ _________ _____ ___ ________ ___ ____ __ ___ ______ __________ __ _____ __ ____ __ ________ ________ ______
_____ _______ _____ ____
__ ___ _____ ___ ___ _______________ _______ __ ______ ___ ____________ ___ ___ _______ ______ ___ _________ _____________ __ ______ ___ _________ _______ __ ____ ___________ _____
from splunk_otel.tracing import start_tracing
start_tracing()
# Also accepts optional settings. For example:
#
# start_tracing(
# service_name='<my-python-service>',
# span_exporter_factories=[OTLPSpanExporter]
# access_token='<access_token>',
# max_attr_length=12000,
# trace_response_header_enabled=True,
# resource_attributes={
# 'service.version': '<your_version>',
# 'deployment.environment': '<your_environment>',
# })
_______________ _______ __ ______ ___ __________________ ______ ______
__ ______ ______ ______ _______________ __ ___ __ _____________________ ___ ___ _______ __________ _____ __ ________
-
______ ___ _____________ ____
from opentelemetry import trace -
______ _ ______ ___ ____ ______
tracer = trace.get_tracer("tracer.name") -
______ _ ____ __ _______ _____
def reticulate_splines(): with tracer.start_as_current_span("span-name") as span: print("Reticulating splines...") # When the 'with' block goes out of scope, the 'span' is closed
______________ __ ______ ___ _____ _____________________ ___ ___ _________ _____ ________
-
______ ___ _____________ ____
from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( BatchSpanProcessor, ConsoleSpanExporter, ) -
______ _ ______ ___ ____ ______
provider = TracerProvider() processor = BatchSpanProcessor(ConsoleSpanExporter()) provider.add_span_processor(processor) trace.set_tracer_provider(provider) tracer = trace.get_tracer("tracer.name") -
______ _ ____ __ _______ _____
def reticulate_splines(): with tracer.start_as_current_span("span-name") as span: print("Reticulating splines...") # When the 'with' block goes out of scope, the 'span' is closed
___ ____ _________ ___ ___ _____________ ________ ______________
______ ______ _______
___ ______ ____________ __ _____________ ______ ________ ___ _________ _________________
-
_______ _____________
-
_______ ______________
-
_____ ______________
-
_____________ _____________
-
_____________ ______________
__ ______ ______ ________ ______ ___ _____ _________ __ ___ ____ __ ______ ________________
- ___________ ___________
-
___________ ____________ ____ _________ ___ _______ ______ ____ ________ ______ __ _______ __ ___________ __________ __ _ _______ ___ ___ ______ __ _____ ____ __ _ _______ ____ _______ _______ ____________
-
______ ___ _____________ ____
from opentelemetry import metrics from opentelemetry.sdk.metrics import MeterProvider from opentelemetry.sdk.metrics.export import ( ConsoleMetricExporter, PeriodicExportingMetricReader, ) -
______ _ _____ _________
meter := otel.Meter("ExampleService") -
______ __ __________ __ ____ _____________
metric_reader = PeriodicExportingMetricReader(ConsoleMetricExporter()) provider = MeterProvider(metric_readers=[metric_reader]) metrics.set_meter_provider(provider) meter = metrics.get_meter("my.meter.name") -
_______ ___ _____________
peanut_counter = meter.create_counter( "peanut.counter", unit="1", description="Counts the number of consumed peanuts" ) def do_stuff(work_item): peanut_counter.add(1, {"work.type": work_item.work_type}) print("Collecting peanuts...")
-
- ____________ ___________
-
____________ ____________ ____ ____________ _______ _______ ________ _________ ____ ___ ____ ___ ____ __ ___ ___________ __ _______ __ ____________ __________ __ _ ________ ______ ____ __ ______ _____ ______ ___ ___ _____ ____ _____ _______ _______ ____________
-
______ ___ _____________ ____
from typing import Iterable from opentelemetry.metrics import CallbackOptions, Observation -
_____ _ ________ __ _______ _____
def get_temp_data(options: CallbackOptions) -> Iterable[Temperature]: r = requests.get( "http://weather/data/city", timeout=options.timeout_millis / 10**3 ) for metadata in r.json(): yield Temperature( metadata["temperature"], {"city.name": metadata["temperature"]} ) -
______ __ __________ __ ____ ____________ _____________
meter.create_observable_gauge( "city.temperature", callbacks=[get_temp_data], description="Mean temperature of the city", )
-
___ ____ _________ ___ ___ _____________ ________ ______________
__________ ____ _______ ______ _______________
____ ______ __________ ____ _______ ______ ________________ ___ ________ _____________ ___ __________ ____ _____ ____________